Throw error EncryptSessionKey (#60)

* throw error EncryptSessionKey

throw error if one of the keys in keyring does not have valid encryption
key

* add key id to error description
This commit is contained in:
Ilya Chesnokov 2020-07-15 16:17:49 +07:00 committed by GitHub
parent b38f993c25
commit 88da5d44b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,7 @@ package crypto
import (
"bytes"
"fmt"
"strconv"
"github.com/pkg/errors"
@ -53,11 +54,13 @@ func (keyRing *KeyRing) EncryptSessionKey(sk *SessionKey) ([]byte, error) {
return nil, errors.Wrap(err, "gopenpgp: unable to encrypt session key")
}
var pubKeys []*packet.PublicKey
pubKeys := make([]*packet.PublicKey, 0, len(keyRing.entities))
for _, e := range keyRing.entities {
if encryptionKey, ok := e.EncryptionKey(getNow()); ok {
pubKeys = append(pubKeys, encryptionKey.PublicKey)
encryptionKey, ok := e.EncryptionKey(getNow())
if !ok {
return nil, errors.New("gopenpgp: encryption key is unavailable for key id " + strconv.FormatUint(e.PrimaryKey.KeyId, 16))
}
pubKeys = append(pubKeys, encryptionKey.PublicKey)
}
if len(pubKeys) == 0 {
return nil, errors.New("cannot set key: no public key available")