From bc9080fcfbea92e28757baaa5757f8c65cbb5023 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 14 Oct 2021 11:58:54 +0700 Subject: Improve handling of signatures for duplicated user-id/attributes --- crypto/src/openpgp/PgpPublicKey.cs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'crypto') 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 /// Allows enumeration of any signatures associated with the passed in id. /// The ID to be matched. /// An IEnumerable of PgpSignature objects. - 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; } /// Allows enumeration of signatures associated with the passed in user attributes. /// The vector of user attributes to be matched. /// An IEnumerable of PgpSignature objects. - 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; } /// Allows enumeration of signatures of the passed in type that are on this key. -- cgit 1.4.1