signature/mechanism_openpgp.go
func (m *openpgpSigningMechanism) importKeysFromBytes(blob []byte) ([]string, error) {
	keyring, err := openpgp.ReadKeyRing(bytes.NewReader(blob))
	if err != nil {
		k, e2 := openpgp.ReadArmoredKeyRing(bytes.NewReader(blob))
		if e2 != nil {
			return nil, err // The original error  -- FIXME: is this better?
		}
		keyring = k
	}

	keyIdentities := []string{}
	for _, entity := range keyring {
		if entity.PrimaryKey == nil {
			// Coverage: This should never happen, openpgp.ReadEntity fails with a
			// openpgp.errors.StructuralError instead of returning an entity with this
			// field set to nil.
			continue
		}
		// Uppercase the fingerprint to be compatible with gpgme
		keyIdentities = append(keyIdentities, strings.ToUpper(fmt.Sprintf("%x", entity.PrimaryKey.Fingerprint)))
		m.keyring = append(m.keyring, entity)
	}
	return keyIdentities, nil
}
func (m *openpgpSigningMechanism) importKeysFromBytes(blob []byte) ([]string, error) {
	keyring, err := openpgp.ReadKeyRing(bytes.NewReader(blob))
	if err != nil {
		k, e2 := openpgp.ReadArmoredKeyRing(bytes.NewReader(blob))
		if e2 != nil {
			return nil, err // The original error  -- FIXME: is this better?
		}
		keyring = k
	}

	keyIdentities := []string{}
	for _, entity := range keyring {
		if entity.PrimaryKey == nil {
			// Coverage: This should never happen, openpgp.ReadEntity fails with a
			// openpgp.errors.StructuralError instead of returning an entity with this
			// field set to nil.
			continue
		}
		// Uppercase the fingerprint to be compatible with gpgme
		keyIdentities = append(keyIdentities, strings.ToUpper(fmt.Sprintf("%x", entity.PrimaryKey.Fingerprint)))
		m.keyring = append(m.keyring, entity)
	}
	return keyIdentities, nil
}
func ( m * openpgpSigningMechanism ) importKeysFromBytes ( blob [ ] byte ) ( [ ] string , error ) { keyring , err := openpgp . ReadKeyRing ( bytes . NewReader ( blob ) ) if err != nil { k , e2 := openpgp . ReadArmoredKeyRing ( bytes . NewReader ( blob ) ) if e2 != nil { return nil , err // The original error  -- FIXME: is this better? } keyring = k } keyIdentities := [ ] string { } for _ , entity := range keyring { if entity . PrimaryKey == nil { // Coverage: This should never happen, openpgp.ReadEntity fails with a // openpgp.errors.StructuralError instead of returning an entity with this // field set to nil. continue } // Uppercase the fingerprint to be compatible with gpgme keyIdentities = append ( keyIdentities , strings . ToUpper ( fmt . Sprintf ( " " , entity . PrimaryKey . Fingerprint ) ) ) m . keyring = append ( m . keyring , entity ) } return keyIdentities , nil }
// importKeysFromBytes imports public keys from the supplied blob and returns their identities.
// The blob is assumed to have an appropriate format (the caller is expected to know which one).
importKeysFromBytes imports public keys from the supplied blob and returns their identities . The blob is assumed to have an appropriate format ( the caller is expected to know which one ) .