summary refs log tree commit diff
path: root/crypto/src/openpgp/PgpPublicKeyRing.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-04-10 17:02:37 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-04-10 17:02:37 +0700
commit67f26538ce499d3d201fe217709542ba8360ebff (patch)
tree27845cdbc49b88405170c32a766711cbd83178b6 /crypto/src/openpgp/PgpPublicKeyRing.cs
parentFix CCM input length check (diff)
downloadBouncyCastle.NET-ed25519-67f26538ce499d3d201fe217709542ba8360ebff.tar.xz
Add various fingerprint-related methods in OpenPgp
Diffstat (limited to 'crypto/src/openpgp/PgpPublicKeyRing.cs')
-rw-r--r--crypto/src/openpgp/PgpPublicKeyRing.cs19
1 files changed, 15 insertions, 4 deletions
diff --git a/crypto/src/openpgp/PgpPublicKeyRing.cs b/crypto/src/openpgp/PgpPublicKeyRing.cs
index 46eecd726..f50dd915c 100644
--- a/crypto/src/openpgp/PgpPublicKeyRing.cs
+++ b/crypto/src/openpgp/PgpPublicKeyRing.cs
@@ -2,7 +2,6 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 
-using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.Collections;
 
 namespace Org.BouncyCastle.Bcpg.OpenPgp
@@ -80,6 +79,18 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
             return null;
         }
 
+        /// <summary>Return the public key with the passed in fingerprint if it is present.</summary>
+        public virtual PgpPublicKey GetPublicKey(byte[] fingerprint)
+        {
+            foreach (PgpPublicKey k in keys)
+            {
+                if (k.HasFingerprint(fingerprint))
+                    return k;
+            }
+
+            return null;
+        }
+
         /// <summary>Allows enumeration of all the public keys.</summary>
         /// <returns>An <c>IEnumerable</c> of <c>PgpPublicKey</c> objects.</returns>
         public virtual IEnumerable<PgpPublicKey> GetPublicKeys()
@@ -239,17 +250,17 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
         public static PgpPublicKeyRing Join(PgpPublicKeyRing first, PgpPublicKeyRing second, bool joinTrustPackets,
             bool allowSubkeySigsOnNonSubkey)
         {
-            if (!Arrays.AreEqual(first.GetPublicKey().GetFingerprint(), second.GetPublicKey().GetFingerprint()))
+            if (!second.GetPublicKey().HasFingerprint(first.GetPublicKey().GetFingerprint()))
                 throw new ArgumentException("Cannot merge certificates with differing primary keys.");
 
             var secondKeys = new HashSet<long>();
-            foreach (var key in second.GetPublicKeys())
+            foreach (var key in second.keys)
             {
                 secondKeys.Add(key.KeyId);
             }
 
             var merged = new List<PgpPublicKey>();
-            foreach (var key in first.GetPublicKeys())
+            foreach (var key in first.keys)
             {
                 var copy = second.GetPublicKey(key.KeyId);
                 if (copy != null)