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:
parent
b38f993c25
commit
88da5d44b1
1 changed files with 6 additions and 3 deletions
|
|
@ -3,6 +3,7 @@ package crypto
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"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")
|
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 {
|
for _, e := range keyRing.entities {
|
||||||
if encryptionKey, ok := e.EncryptionKey(getNow()); ok {
|
encryptionKey, ok := e.EncryptionKey(getNow())
|
||||||
pubKeys = append(pubKeys, encryptionKey.PublicKey)
|
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 {
|
if len(pubKeys) == 0 {
|
||||||
return nil, errors.New("cannot set key: no public key available")
|
return nil, errors.New("cannot set key: no public key available")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue