summary refs log tree commit diff
path: root/crypto/src/openpgp/PgpSecretKeyRing.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/openpgp/PgpSecretKeyRing.cs')
-rw-r--r--crypto/src/openpgp/PgpSecretKeyRing.cs48
1 files changed, 46 insertions, 2 deletions
diff --git a/crypto/src/openpgp/PgpSecretKeyRing.cs b/crypto/src/openpgp/PgpSecretKeyRing.cs
index a070aa132..ff644545f 100644
--- a/crypto/src/openpgp/PgpSecretKeyRing.cs
+++ b/crypto/src/openpgp/PgpSecretKeyRing.cs
@@ -3,7 +3,6 @@ using System.Collections.Generic;
 using System.IO;
 
 using Org.BouncyCastle.Security;
-using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.Collections;
 
 namespace Org.BouncyCastle.Bcpg.OpenPgp
@@ -115,6 +114,38 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
             return keys[0].PublicKey;
         }
 
+        /// <summary>Return the public key referred to by the passed in keyID if it is present.</summary>
+        public PgpPublicKey GetPublicKey(long keyID)
+        {
+            PgpSecretKey key = GetSecretKey(keyID);
+            if (key != null)
+                return key.PublicKey;
+
+            foreach (PgpPublicKey k in extraPubKeys)
+            {
+                if (keyID == k.KeyId)
+                    return k;
+            }
+
+            return null;
+        }
+
+        /// <summary>Return the public key with the passed in fingerprint if it is present.</summary>
+        public PgpPublicKey GetPublicKey(byte[] fingerprint)
+        {
+            PgpSecretKey key = GetSecretKey(fingerprint);
+            if (key != null)
+                return key.PublicKey;
+
+            foreach (PgpPublicKey k in extraPubKeys)
+            {
+                if (k.HasFingerprint(fingerprint))
+                    return k;
+            }
+
+            return null;
+        }
+
         /**
          * Return any keys carrying a signature issued by the key represented by keyID.
          *
@@ -165,6 +196,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
             return CollectionUtilities.Proxy(keys);
         }
 
+        /// <summary>Return the secret key referred to by the passed in keyID if it is present.</summary>
         public PgpSecretKey GetSecretKey(long keyId)
         {
             foreach (PgpSecretKey k in keys)
@@ -176,6 +208,18 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
             return null;
         }
 
+        /// <summary>Return the secret key associated with the passed in fingerprint if it is present.</summary>
+        public PgpSecretKey GetSecretKey(byte[] fingerprint)
+        {
+            foreach (PgpSecretKey k in keys)
+            {
+                if (k.PublicKey.HasFingerprint(fingerprint))
+                    return k;
+            }
+
+            return null;
+        }
+
         /// <summary>
         /// Return an iterator of the public keys in the secret key ring that
         /// have no matching private key. At the moment only personal certificate data
@@ -247,7 +291,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
         {
             var newKeys = new List<PgpSecretKey>(ring.keys.Count);
 
-            foreach (PgpSecretKey secretKey in ring.GetSecretKeys())
+            foreach (PgpSecretKey secretKey in ring.keys)
             {
                 if (secretKey.IsPrivateKeyEmpty)
                 {