コード例 #1
0
ファイル: storage.go プロジェクト: cmars/pghkp
func (st *storage) Notify(change hkpstorage.KeyChange) error {
	st.mu.Lock()
	defer st.mu.Unlock()
	log.Debugf("%v", change)
	for _, f := range st.listeners {
		// TODO: log error notifying listener?
		f(change)
	}
	return nil
}
コード例 #2
0
ファイル: io.go プロジェクト: squeed/openpgp
func (ok *OpaqueKeyring) Parse() (*PrimaryKey, error) {
	var err error
	var pubkey *PrimaryKey
	var signablePacket signable
	for _, opkt := range ok.Packets {
		var badPacket *packet.OpaquePacket
		if opkt.Tag == 6 { //packet.PacketTypePublicKey:
			if pubkey != nil {
				return nil, errgo.Newf("multiple public keys in keyring")
			}
			pubkey, err = ParsePrimaryKey(opkt)
			if err != nil {
				return nil, errgo.Notef(err, "invalid public key packet type")
			}
			signablePacket = pubkey
		} else if pubkey != nil {
			switch opkt.Tag {
			case 14: //packet.PacketTypePublicSubKey:
				signablePacket = nil
				subkey, err := ParseSubKey(opkt)
				if err != nil {
					log.Debugf("unreadable subkey packet: %v", err)
					badPacket = opkt
				} else {
					pubkey.SubKeys = append(pubkey.SubKeys, subkey)
					signablePacket = subkey
				}
			case 13: //packet.PacketTypeUserId:
				signablePacket = nil
				uid, err := ParseUserID(opkt, pubkey.UUID)
				if err != nil {
					log.Debugf("unreadable user id packet: %v", err)
					badPacket = opkt
				} else {
					pubkey.UserIDs = append(pubkey.UserIDs, uid)
					signablePacket = uid
				}
			case 17: //packet.PacketTypeUserAttribute:
				signablePacket = nil
				uat, err := ParseUserAttribute(opkt, pubkey.UUID)
				if err != nil {
					log.Debugf("unreadable user attribute packet: %v", err)
					badPacket = opkt
				} else {
					pubkey.UserAttributes = append(pubkey.UserAttributes, uat)
					signablePacket = uat
				}
			case 2: //packet.PacketTypeSignature:
				if signablePacket == nil {
					log.Debugf("signature out of context")
					badPacket = opkt
				} else {
					sig, err := ParseSignature(opkt, pubkey.UUID, signablePacket.uuid())
					if err != nil {
						log.Debugf("unreadable signature packet: %v", err)
						badPacket = opkt
					} else {
						signablePacket.appendSignature(sig)
					}
				}
			default:
				badPacket = opkt
			}

			if badPacket != nil {
				var badParent string
				if signablePacket != nil {
					badParent = signablePacket.uuid()
				} else {
					badParent = pubkey.uuid()
				}
				other, err := ParseOther(badPacket, badParent)
				if err != nil {
					return nil, errgo.Mask(err)
				}
				pubkey.Others = append(pubkey.Others, other)
			}
		}
	}
	if pubkey == nil {
		return nil, errgo.New("primary public key not found")
	}
	pubkey.MD5, err = SksDigest(pubkey, md5.New())
	if err != nil {
		return nil, err
	}
	return pubkey, nil
}