summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crypto/src/x509/X509Certificate.cs6
-rw-r--r--crypto/src/x509/X509Crl.cs3
2 files changed, 3 insertions, 6 deletions
diff --git a/crypto/src/x509/X509Certificate.cs b/crypto/src/x509/X509Certificate.cs
index aec793731..f58477439 100644
--- a/crypto/src/x509/X509Certificate.cs
+++ b/crypto/src/x509/X509Certificate.cs
@@ -477,8 +477,7 @@ namespace Org.BouncyCastle.X509
 
             AsymmetricKeyParameter temp = PublicKeyFactory.CreateKey(c.SubjectPublicKeyInfo);
 
-            Interlocked.CompareExchange(ref publicKeyValue, temp, null);
-            return publicKeyValue;
+            return Interlocked.CompareExchange(ref publicKeyValue, temp, null) ?? temp;
         }
 
         /// <summary>
@@ -699,8 +698,7 @@ namespace Org.BouncyCastle.X509
 
             CachedEncoding temp = new CachedEncoding(encoding, exception);
 
-            Interlocked.CompareExchange(ref cachedEncoding, temp, null);
-            return cachedEncoding;
+           return Interlocked.CompareExchange(ref cachedEncoding, temp, null) ?? temp;
         }
 
         private static bool IsAlgIDEqual(AlgorithmIdentifier id1, AlgorithmIdentifier id2)
diff --git a/crypto/src/x509/X509Crl.cs b/crypto/src/x509/X509Crl.cs
index e47addd7a..b4af1b374 100644
--- a/crypto/src/x509/X509Crl.cs
+++ b/crypto/src/x509/X509Crl.cs
@@ -466,8 +466,7 @@ namespace Org.BouncyCastle.X509
 
             CachedEncoding temp = new CachedEncoding(encoding, exception);
 
-			Interlocked.CompareExchange(ref cachedEncoding, temp, null);
-            return cachedEncoding;
+			return Interlocked.CompareExchange(ref cachedEncoding, temp, null) ?? temp;
         }
     }
 }