(reader io.ReadCloser)
| 55 | } |
| 56 | |
| 57 | func 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(). |
no test coverage detected