From a126065b76f98687664917a5f31f640819cbc0ae Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Wed, 19 Jul 2017 11:29:15 -0400 Subject: [PATCH] Allow importing of known keys (needed when re-importing keys after signing them) Partial fix for issue #315 --- MimeKit/Cryptography/OpenPgpContext.cs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/MimeKit/Cryptography/OpenPgpContext.cs b/MimeKit/Cryptography/OpenPgpContext.cs index 77c510708c..24a0d50aa7 100644 --- a/MimeKit/Cryptography/OpenPgpContext.cs +++ b/MimeKit/Cryptography/OpenPgpContext.cs @@ -1940,9 +1940,6 @@ public void Import (PgpPublicKeyRing keyring) if (keyring == null) throw new ArgumentNullException (nameof (keyring)); - if (PublicKeyRingBundle.Contains (keyring.GetPublicKey ().KeyId)) - return; - PublicKeyRingBundle = PgpPublicKeyRingBundle.AddPublicKeyRing (PublicKeyRingBundle, keyring); SavePublicKeyRingBundle (); } @@ -1965,10 +1962,8 @@ public void Import (PgpPublicKeyRingBundle bundle) int publicKeysAdded = 0; foreach (PgpPublicKeyRing pubring in bundle.GetKeyRings ()) { - if (!PublicKeyRingBundle.Contains (pubring.GetPublicKey ().KeyId)) { - PublicKeyRingBundle = PgpPublicKeyRingBundle.AddPublicKeyRing (PublicKeyRingBundle, pubring); - publicKeysAdded++; - } + PublicKeyRingBundle = PgpPublicKeyRingBundle.AddPublicKeyRing (PublicKeyRingBundle, pubring); + publicKeysAdded++; } if (publicKeysAdded > 0) @@ -2014,9 +2009,6 @@ public void Import (PgpSecretKeyRing keyring) if (keyring == null) throw new ArgumentNullException (nameof (keyring)); - if (SecretKeyRingBundle.Contains (keyring.GetSecretKey ().KeyId)) - return; - SecretKeyRingBundle = PgpSecretKeyRingBundle.AddSecretKeyRing (SecretKeyRingBundle, keyring); SaveSecretKeyRingBundle (); } @@ -2039,10 +2031,8 @@ public void Import (PgpSecretKeyRingBundle bundle) int secretKeysAdded = 0; foreach (PgpSecretKeyRing secring in bundle.GetKeyRings ()) { - if (!SecretKeyRingBundle.Contains (secring.GetSecretKey ().KeyId)) { - SecretKeyRingBundle = PgpSecretKeyRingBundle.AddSecretKeyRing (SecretKeyRingBundle, secring); - secretKeysAdded++; - } + SecretKeyRingBundle = PgpSecretKeyRingBundle.AddSecretKeyRing (SecretKeyRingBundle, secring); + secretKeysAdded++; } if (secretKeysAdded > 0)