From 27f48072133d8ae91291907fab83130853c840c2 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Tue, 25 Jul 2023 18:15:43 +0700 Subject: Refactoring around algorithm finders --- crypto/src/cmp/CertificateStatus.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'crypto/src/cmp/CertificateStatus.cs') diff --git a/crypto/src/cmp/CertificateStatus.cs b/crypto/src/cmp/CertificateStatus.cs index 53227d062..8ccf89562 100644 --- a/crypto/src/cmp/CertificateStatus.cs +++ b/crypto/src/cmp/CertificateStatus.cs @@ -1,9 +1,6 @@ -using System; - -using Org.BouncyCastle.Asn1.Cmp; +using Org.BouncyCastle.Asn1.Cmp; using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Cms; -using Org.BouncyCastle.Crypto.IO; using Org.BouncyCastle.Math; using Org.BouncyCastle.Security; using Org.BouncyCastle.Utilities; @@ -13,8 +10,6 @@ namespace Org.BouncyCastle.Cmp { public class CertificateStatus { - private static readonly DefaultSignatureAlgorithmIdentifierFinder sigAlgFinder = new DefaultSignatureAlgorithmIdentifierFinder(); - private readonly DefaultDigestAlgorithmIdentifierFinder digestAlgFinder; private readonly CertStatus certStatus; @@ -30,11 +25,13 @@ namespace Org.BouncyCastle.Cmp public virtual bool IsVerified(X509Certificate cert) { - AlgorithmIdentifier digAlg = digestAlgFinder.Find(sigAlgFinder.Find(cert.SigAlgName)); - if (null == digAlg) - throw new CmpException("cannot find algorithm for digest from signature " + cert.SigAlgName); + var sigAlgID = DefaultSignatureAlgorithmIdentifierFinder.Instance.Find(cert.SigAlgName) + ?? throw new CmpException("cannot find algorithm identifier for signature name"); + + var digAlgID = digestAlgFinder.Find(sigAlgID) + ?? throw new CmpException("cannot find algorithm for digest from signature " + cert.SigAlgName); - byte[] digest = DigestUtilities.CalculateDigest(digAlg.Algorithm, cert.GetEncoded()); + byte[] digest = DigestUtilities.CalculateDigest(digAlgID.Algorithm, cert.GetEncoded()); return Arrays.FixedTimeEquals(certStatus.CertHash.GetOctets(), digest); } -- cgit 1.4.1