@@ -19,32 +19,34 @@ func ReadPubRing(path string, keyIds []string) (*openpgp.EntityList, error) {
19
19
return nil , err
20
20
}
21
21
22
+ // For each provided key ids, check if it exists
23
+ // through the gnupg pub ring
22
24
for _ , keyId := range keyIds {
23
- for _ , entity := range * pubKeys {
25
+ var matched bool = false
24
26
27
+ for _ , entity := range * pubKeys {
25
28
if isEntityKey (keyId , entity ) {
26
29
pi := primaryIdentity (entity )
27
30
ss := pi .SelfSignature
28
31
29
32
hprefs = intersectPreferences (hprefs , ss .PreferredHash )
30
33
sprefs = intersectPreferences (sprefs , ss .PreferredSymmetric )
31
34
matchedKeys = append (matchedKeys , entity )
32
- } else {
33
- unmatchedKeyIds = append (unmatchedKeyIds , keyId )
34
-
35
+ matched = true
35
36
}
36
37
}
38
+
39
+ if matched == false {
40
+ unmatchedKeyIds = append (unmatchedKeyIds , keyId )
41
+ }
42
+
37
43
}
38
44
39
45
if len (unmatchedKeyIds ) != 0 {
40
46
errMsg := fmt .Sprintf ("The following keys could not be found " +
41
47
"in the public keyring: %s" , strings .Join (unmatchedKeyIds , ", " ))
42
48
return nil , NewPgpError (ERR_DECRYPTION_KEYS , errMsg )
43
49
}
44
-
45
- if len (matchedKeys ) != len (keyIds ) {
46
- return nil , NewPgpError (ERR_DECRYPTION_KEYS , "Couldn't find all keys" )
47
- }
48
50
if len (hprefs ) == 0 {
49
51
return nil , NewPgpError (ERR_DECRYPTION_HASHES , "No common hashes for encryption keys" )
50
52
}
0 commit comments