summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-10-14 11:58:54 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-10-14 11:58:54 +0700
commitbc9080fcfbea92e28757baaa5757f8c65cbb5023 (patch)
tree60c257e9bef2b378563c8260f43c8953081c28d9
parentIgnore PGP signatures with invalid version (diff)
downloadBouncyCastle.NET-ed25519-bc9080fcfbea92e28757baaa5757f8c65cbb5023.tar.xz
Improve handling of signatures for duplicated user-id/attributes
-rw-r--r--crypto/src/openpgp/PgpPublicKey.cs25
1 files changed, 17 insertions, 8 deletions
diff --git a/crypto/src/openpgp/PgpPublicKey.cs b/crypto/src/openpgp/PgpPublicKey.cs
index 92422c413..9b8a956f2 100644
--- a/crypto/src/openpgp/PgpPublicKey.cs
+++ b/crypto/src/openpgp/PgpPublicKey.cs
@@ -559,38 +559,47 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
         /// <summary>Allows enumeration of any signatures associated with the passed in id.</summary>
         /// <param name="id">The ID to be matched.</param>
         /// <returns>An <c>IEnumerable</c> of <c>PgpSignature</c> objects.</returns>
-        public IEnumerable GetSignaturesForId(
-            string id)
+        public IEnumerable GetSignaturesForId(string id)
         {
             if (id == null)
                 throw new ArgumentNullException("id");
 
+            IList signatures = Platform.CreateArrayList();
+            bool userIdFound = false;
+
             for (int i = 0; i != ids.Count; i++)
             {
                 if (id.Equals(ids[i]))
                 {
-                    return new EnumerableProxy((IList)idSigs[i]);
+                    userIdFound = true;
+                    CollectionUtilities.AddRange(signatures, (IList)idSigs[i]);
                 }
             }
 
-            return null;
+            return userIdFound ? signatures : null;
         }
 
         /// <summary>Allows enumeration of signatures associated with the passed in user attributes.</summary>
         /// <param name="userAttributes">The vector of user attributes to be matched.</param>
         /// <returns>An <c>IEnumerable</c> of <c>PgpSignature</c> objects.</returns>
-        public IEnumerable GetSignaturesForUserAttribute(
-            PgpUserAttributeSubpacketVector userAttributes)
+        public IEnumerable GetSignaturesForUserAttribute(PgpUserAttributeSubpacketVector userAttributes)
         {
+            if (userAttributes == null)
+                throw new ArgumentNullException("userAttributes");
+
+            IList signatures = Platform.CreateArrayList();
+            bool attributeFound = false;
+
             for (int i = 0; i != ids.Count; i++)
             {
                 if (userAttributes.Equals(ids[i]))
                 {
-                    return new EnumerableProxy((IList) idSigs[i]);
+                    attributeFound = true;
+                    CollectionUtilities.AddRange(signatures, (IList)idSigs[i]);
                 }
             }
 
-            return null;
+            return attributeFound ? signatures : null;
         }
 
         /// <summary>Allows enumeration of signatures of the passed in type that are on this key.</summary>