MCPcopy
hub / github.com/perkeep/perkeep / openArmoredPublicKeyFile

Function openArmoredPublicKeyFile

pkg/jsonsign/keys.go:57–78  ·  view source on GitHub ↗
(reader io.ReadCloser)

Source from the content-addressed store, hash-verified

55}
56
57func openArmoredPublicKeyFile(reader io.ReadCloser) (*packet.PublicKey, error) {
58 defer reader.Close()
59
60 var lr = io.LimitReader(reader, publicKeyMaxSize)
61 block, _ := armor.Decode(lr)
62 if block == nil {
63 return nil, errors.New("Couldn't find PGP block in public key file")
64 }
65 if block.Type != "PGP PUBLIC KEY BLOCK" {
66 return nil, errors.New("invalid public key blob")
67 }
68 p, err := packet.Read(block.Body)
69 if err != nil {
70 return nil, fmt.Errorf("Invalid public key blob: %v", err)
71 }
72
73 pk, ok := p.(*packet.PublicKey)
74 if !ok {
75 return nil, fmt.Errorf("Invalid public key blob; not a public key packet")
76 }
77 return pk, nil
78}
79
80// EntityFromSecring returns the openpgp Entity from keyFile that matches keyID.
81// If empty, keyFile defaults to osutil.SecretRingFile().

Callers 3

SignMethod · 0.85
ParseArmoredPublicKeyFunction · 0.85

Calls 2

CloseMethod · 0.65
ReadMethod · 0.45

Tested by

no test coverage detected