Skip to content

Commit

Permalink
Allow importing of known keys (needed when re-importing keys after si…
Browse files Browse the repository at this point in the history
…gning them)

Partial fix for issue #315
  • Loading branch information
jstedfast committed Jul 19, 2017
1 parent eac4b21 commit a126065
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions MimeKit/Cryptography/OpenPgpContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
}
Expand All @@ -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)
Expand Down Expand Up @@ -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 ();
}
Expand All @@ -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)
Expand Down

0 comments on commit a126065

Please sign in to comment.