Skip to content

Commit bd9e0fa

Browse files
author
Oleiade
committed
Fix 77 invalid check of unmatched key ids length
1 parent 64fdcd4 commit bd9e0fa

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

crypto/openpgp/keyring.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,34 @@ func ReadPubRing(path string, keyIds []string) (*openpgp.EntityList, error) {
1919
return nil, err
2020
}
2121

22+
// For each provided key ids, check if it exists
23+
// through the gnupg pub ring
2224
for _, keyId := range keyIds {
23-
for _, entity := range *pubKeys {
25+
var matched bool = false
2426

27+
for _, entity := range *pubKeys {
2528
if isEntityKey(keyId, entity) {
2629
pi := primaryIdentity(entity)
2730
ss := pi.SelfSignature
2831

2932
hprefs = intersectPreferences(hprefs, ss.PreferredHash)
3033
sprefs = intersectPreferences(sprefs, ss.PreferredSymmetric)
3134
matchedKeys = append(matchedKeys, entity)
32-
} else {
33-
unmatchedKeyIds = append(unmatchedKeyIds, keyId)
34-
35+
matched = true
3536
}
3637
}
38+
39+
if matched == false {
40+
unmatchedKeyIds = append(unmatchedKeyIds, keyId)
41+
}
42+
3743
}
3844

3945
if len(unmatchedKeyIds) != 0 {
4046
errMsg := fmt.Sprintf("The following keys could not be found "+
4147
"in the public keyring: %s", strings.Join(unmatchedKeyIds, ", "))
4248
return nil, NewPgpError(ERR_DECRYPTION_KEYS, errMsg)
4349
}
44-
45-
if len(matchedKeys) != len(keyIds) {
46-
return nil, NewPgpError(ERR_DECRYPTION_KEYS, "Couldn't find all keys")
47-
}
4850
if len(hprefs) == 0 {
4951
return nil, NewPgpError(ERR_DECRYPTION_HASHES, "No common hashes for encryption keys")
5052
}

0 commit comments

Comments
 (0)