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 }
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 }
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 }
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) }
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 }
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) }
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 }
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 }