本文整理汇总了Golang中golang.org/x/crypto/openpgp/packet.OpaquePacket.Serialize方法的典型用法代码示例。如果您正苦于以下问题:Golang OpaquePacket.Serialize方法的具体用法?Golang OpaquePacket.Serialize怎么用?Golang OpaquePacket.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/crypto/openpgp/packet.OpaquePacket
的用法示例。
在下文中一共展示了OpaquePacket.Serialize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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
}
示例5: 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
}
示例6: 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
}