From 525dad93ce6d9444bab33f68fa5a43d8d9b9f94b Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 4 May 2023 13:08:25 +0700 Subject: Refactoring in CMS cert selectors --- crypto/src/x509/store/X509CertStoreSelector.cs | 34 ++++++++++++-------------- 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'crypto/src/x509/store/X509CertStoreSelector.cs') diff --git a/crypto/src/x509/store/X509CertStoreSelector.cs b/crypto/src/x509/store/X509CertStoreSelector.cs index 357b5e76d..30cd44a8e 100644 --- a/crypto/src/x509/store/X509CertStoreSelector.cs +++ b/crypto/src/x509/store/X509CertStoreSelector.cs @@ -110,8 +110,8 @@ namespace Org.BouncyCastle.X509.Store public bool[] KeyUsage { - get { return CopyBoolArray(keyUsage); } - set { keyUsage = CopyBoolArray(value); } + get { return Arrays.Clone(keyUsage); } + set { keyUsage = Arrays.Clone(value); } } /// @@ -286,17 +286,19 @@ namespace Org.BouncyCastle.X509.Store return true; } - internal static bool IssuersMatch( - X509Name a, - X509Name b) - { - return a == null ? b == null : a.Equivalent(b, true); - } + protected internal int GetHashCodeOfSubjectKeyIdentifier() => Arrays.GetHashCode(subjectKeyIdentifier); + + protected internal bool MatchesIssuer(X509CertStoreSelector other) => IssuersMatch(issuer, other.issuer); - private static bool[] CopyBoolArray( - bool[] b) + protected internal bool MatchesSerialNumber(X509CertStoreSelector other) => + Objects.Equals(serialNumber, other.SerialNumber); + + protected internal bool MatchesSubjectKeyIdentifier(X509CertStoreSelector other) => + Arrays.AreEqual(subjectKeyIdentifier, other.subjectKeyIdentifier); + + private static bool IssuersMatch(X509Name a, X509Name b) { - return b == null ? null : (bool[]) b.Clone(); + return a == null ? b == null : a.Equivalent(b, true); } private static ISet CopySet(ISet s) @@ -304,16 +306,12 @@ namespace Org.BouncyCastle.X509.Store return s == null ? null : new HashSet(s); } - private static SubjectPublicKeyInfo GetSubjectPublicKey( - X509Certificate c) + private static SubjectPublicKeyInfo GetSubjectPublicKey(X509Certificate c) { - return SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(c.GetPublicKey()); + return c.CertificateStructure.SubjectPublicKeyInfo; } - private static bool MatchExtension( - byte[] b, - X509Certificate c, - DerObjectIdentifier oid) + private static bool MatchExtension(byte[] b, X509Certificate c, DerObjectIdentifier oid) { if (b == null) return true; -- cgit 1.4.1