diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2019-08-02 15:34:54 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2019-08-02 15:34:54 +0700 |
commit | fe33e6090225fd173df691e307b034dd712f4e07 (patch) | |
tree | e6152f508adb3bb89cfabe6af826f76e6a6950e9 /crypto/src/x509/X509Crl.cs | |
parent | SHA-256 performance tweak (diff) | |
download | BouncyCastle.NET-ed25519-fe33e6090225fd173df691e307b034dd712f4e07.tar.xz |
Refactor Equals/GetHashCode in X509 objects
- cache public key in X509Certificate
Diffstat (limited to 'crypto/src/x509/X509Crl.cs')
-rw-r--r-- | crypto/src/x509/X509Crl.cs | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/crypto/src/x509/X509Crl.cs b/crypto/src/x509/X509Crl.cs index ecfb14132..8903e69d0 100644 --- a/crypto/src/x509/X509Crl.cs +++ b/crypto/src/x509/X509Crl.cs @@ -6,6 +6,7 @@ using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.Utilities; using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Crypto; +using Org.BouncyCastle.Crypto.Operators; using Org.BouncyCastle.Math; using Org.BouncyCastle.Security; using Org.BouncyCastle.Security.Certificates; @@ -14,7 +15,6 @@ using Org.BouncyCastle.Utilities.Collections; using Org.BouncyCastle.Utilities.Date; using Org.BouncyCastle.Utilities.Encoders; using Org.BouncyCastle.X509.Extension; -using Org.BouncyCastle.Crypto.Operators; namespace Org.BouncyCastle.X509 { @@ -36,6 +36,9 @@ namespace Org.BouncyCastle.X509 private readonly byte[] sigAlgParams; private readonly bool isIndirect; + private volatile bool hashValueSet; + private volatile int hashValue; + public X509Crl( CertificateList c) { @@ -229,27 +232,41 @@ namespace Org.BouncyCastle.X509 return Arrays.Clone(sigAlgParams); } - public override bool Equals( - object obj) + public override bool Equals(object other) { - if (obj == this) - return true; + if (this == other) + return true; - X509Crl other = obj as X509Crl; + X509Crl that = other as X509Crl; + if (null == that) + return false; - if (other == null) - return false; + if (this.hashValueSet && that.hashValueSet) + { + if (this.hashValue != that.hashValue) + return false; + } + else if (!this.c.Signature.Equals(that.c.Signature)) + { + return false; + } - return c.Equals(other.c); + return this.c.Equals(that.c); - // NB: May prefer this implementation of Equals if more than one certificate implementation in play - //return Arrays.AreEqual(this.GetEncoded(), other.GetEncoded()); + // NB: May prefer this implementation of Equals if more than one CRL implementation in play + //return Arrays.AreEqual(this.GetEncoded(), that.GetEncoded()); } - public override int GetHashCode() - { - return c.GetHashCode(); - } + public override int GetHashCode() + { + if (!hashValueSet) + { + hashValue = this.c.GetHashCode(); + hashValueSet = true; + } + + return hashValue; + } /** * Returns a string representation of this CRL. |