本文整理汇总了Golang中golang.org/x/crypto/openpgp/packet.OpaquePacket类的典型用法代码示例。如果您正苦于以下问题:Golang OpaquePacket类的具体用法?Golang OpaquePacket怎么用?Golang OpaquePacket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OpaquePacket类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ParsePrimaryKey
func ParsePrimaryKey(op *packet.OpaquePacket) (*PrimaryKey, error) {
var buf bytes.Buffer
var err error
if err = op.Serialize(&buf); err != nil {
return nil, errgo.Mask(err)
}
pubkey := &PrimaryKey{
PublicKey: PublicKey{
Packet: Packet{
Tag: op.Tag,
Packet: buf.Bytes(),
},
},
}
// Attempt to parse the opaque packet into a public key type.
parseErr := pubkey.parse(op, false)
if parseErr != nil {
err = pubkey.setUnsupported(op)
if err != nil {
return nil, errgo.Mask(err)
}
} else {
pubkey.Parsed = true
}
return pubkey, nil
}
示例2: ParseUserID
func ParseUserID(op *packet.OpaquePacket, parentID string) (*UserID, error) {
var buf bytes.Buffer
if err := op.Serialize(&buf); err != nil {
return nil, errgo.Mask(err)
}
uid := &UserID{
Packet: Packet{
UUID: scopedDigest([]string{parentID}, uidTag, buf.Bytes()),
Tag: op.Tag,
Packet: buf.Bytes(),
},
}
p, err := op.Parse()
if err != nil {
return nil, errgo.Mask(err)
}
u, ok := p.(*packet.UserId)
if !ok {
return nil, ErrInvalidPacketType
}
err = uid.setUserID(u)
if err != nil {
return nil, errgo.Mask(err)
}
uid.Parsed = true
return uid, nil
}
示例3: ParseSubKey
func ParseSubKey(op *packet.OpaquePacket) (*SubKey, error) {
var buf bytes.Buffer
var err error
if err = op.Serialize(&buf); err != nil {
return nil, errgo.Mask(err)
panic("unable to write internal buffer")
}
subkey := &SubKey{
PublicKey: PublicKey{
Packet: Packet{
Tag: op.Tag,
Packet: buf.Bytes(),
},
},
}
// Attempt to parse the opaque packet into a public key type.
parseErr := subkey.parse(op, true)
if parseErr != nil {
subkey.setUnsupported(op)
} else {
subkey.Parsed = true
}
return subkey, nil
}
示例4: parse
func (sig *Signature) parse(op *packet.OpaquePacket) error {
p, err := op.Parse()
if err != nil {
return errgo.Mask(err)
}
switch s := p.(type) {
case *packet.Signature:
return sig.setSignature(s)
case *packet.SignatureV3:
return sig.setSignatureV3(s)
}
return errgo.Mask(ErrInvalidPacketType, errgo.Any)
}
示例5: ParseOther
func ParseOther(op *packet.OpaquePacket, parentID string) (*Packet, error) {
var buf bytes.Buffer
err := op.Serialize(&buf)
if err != nil {
return nil, errgo.Mask(err)
}
return &Packet{
UUID: scopedDigest([]string{parentID}, packetTag, buf.Bytes()),
Tag: op.Tag,
Packet: buf.Bytes(),
Parsed: false,
}, nil
}
示例6: parse
func (pkp *PublicKey) parse(op *packet.OpaquePacket, subkey bool) error {
p, err := op.Parse()
if err != nil {
return errgo.Mask(err)
}
switch pk := p.(type) {
case *packet.PublicKey:
if pk.IsSubkey != subkey {
return ErrInvalidPacketType
}
return pkp.setPublicKey(pk)
case *packet.PublicKeyV3:
if pk.IsSubkey != subkey {
return ErrInvalidPacketType
}
return pkp.setPublicKeyV3(pk)
default:
}
return errgo.Mask(ErrInvalidPacketType)
}
示例7: ParseUserAttribute
func ParseUserAttribute(op *packet.OpaquePacket, parentID string) (*UserAttribute, error) {
var buf bytes.Buffer
if err := op.Serialize(&buf); err != nil {
return nil, errgo.Mask(err)
}
uat := &UserAttribute{
Packet: Packet{
UUID: scopedDigest([]string{parentID}, uatTag, buf.Bytes()),
Tag: op.Tag,
Packet: buf.Bytes(),
},
}
u, err := uat.userAttributePacket()
if err != nil {
return nil, errgo.WithCausef(err, ErrInvalidPacketType, "")
}
uat.Images = u.ImageData()
uat.Parsed = true
return uat, nil
}
示例8: ParseSignature
func ParseSignature(op *packet.OpaquePacket, pubkeyUUID, scopedUUID string) (*Signature, error) {
var buf bytes.Buffer
var err error
if err = op.Serialize(&buf); err != nil {
return nil, errgo.Mask(err)
}
sig := &Signature{
Packet: Packet{
UUID: scopedDigest([]string{pubkeyUUID, scopedUUID}, sigTag, buf.Bytes()),
Tag: op.Tag,
Packet: buf.Bytes(),
},
}
// Attempt to parse the opaque packet into a public key type.
err = sig.parse(op)
if err != nil {
return nil, errgo.Mask(err)
}
sig.Parsed = true
return sig, nil
}