summary refs log tree commit diff
path: root/crypto/src/cmp/CertificateConfirmationContentBuilder.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-07-25 18:15:43 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-07-25 18:15:43 +0700
commit27f48072133d8ae91291907fab83130853c840c2 (patch)
tree5db594369bfe8611a3fa01040756ff6161b9c3e4 /crypto/src/cmp/CertificateConfirmationContentBuilder.cs
parentRestore deleted members as Obsolete (diff)
downloadBouncyCastle.NET-ed25519-27f48072133d8ae91291907fab83130853c840c2.tar.xz
Refactoring around algorithm finders
Diffstat (limited to 'crypto/src/cmp/CertificateConfirmationContentBuilder.cs')
-rw-r--r--crypto/src/cmp/CertificateConfirmationContentBuilder.cs23
1 files changed, 9 insertions, 14 deletions
diff --git a/crypto/src/cmp/CertificateConfirmationContentBuilder.cs b/crypto/src/cmp/CertificateConfirmationContentBuilder.cs
index 09ae71bbf..4178264b4 100644
--- a/crypto/src/cmp/CertificateConfirmationContentBuilder.cs
+++ b/crypto/src/cmp/CertificateConfirmationContentBuilder.cs
@@ -12,21 +12,18 @@ namespace Org.BouncyCastle.Cmp
 {
     public sealed class CertificateConfirmationContentBuilder
     {
-        private static readonly DefaultSignatureAlgorithmIdentifierFinder SigAlgFinder =
-            new DefaultSignatureAlgorithmIdentifierFinder();
-
         private readonly DefaultDigestAlgorithmIdentifierFinder m_digestAlgFinder;
-        private readonly IList<X509Certificate> m_acceptedCerts = new List<X509Certificate>();
-        private readonly IList<BigInteger> m_acceptedReqIDs = new List<BigInteger>();
+        private readonly List<X509Certificate> m_acceptedCerts = new List<X509Certificate>();
+        private readonly List<BigInteger> m_acceptedReqIDs = new List<BigInteger>();
 
         public CertificateConfirmationContentBuilder()
-            : this(new DefaultDigestAlgorithmIdentifierFinder())
+            : this(DefaultDigestAlgorithmIdentifierFinder.Instance)
         {
         }
 
         public CertificateConfirmationContentBuilder(DefaultDigestAlgorithmIdentifierFinder digestAlgFinder)
         {
-            this.m_digestAlgFinder = digestAlgFinder;
+            m_digestAlgFinder = digestAlgFinder;
         }
 
         public CertificateConfirmationContentBuilder AddAcceptedCertificate(X509Certificate certHolder,
@@ -45,15 +42,13 @@ namespace Org.BouncyCastle.Cmp
                 X509Certificate cert = m_acceptedCerts[i];
                 BigInteger reqID = m_acceptedReqIDs[i];
 
-                AlgorithmIdentifier algorithmIdentifier = SigAlgFinder.Find(cert.SigAlgName);
-                if (null == algorithmIdentifier)
-                    throw new CmpException("cannot find algorithm identifier for signature name");
+                var sigAlgID = DefaultSignatureAlgorithmIdentifierFinder.Instance.Find(cert.SigAlgName)
+                    ?? throw new CmpException("cannot find algorithm identifier for signature name");
 
-                AlgorithmIdentifier digAlg = m_digestAlgFinder.Find(algorithmIdentifier);
-                if (null == digAlg)
-                    throw new CmpException("cannot find algorithm for digest from signature");
+                AlgorithmIdentifier digAlgID = m_digestAlgFinder.Find(sigAlgID)
+                    ?? throw new CmpException("cannot find algorithm for digest from signature");
 
-                byte[] digest = DigestUtilities.CalculateDigest(digAlg.Algorithm, cert.GetEncoded());
+                byte[] digest = DigestUtilities.CalculateDigest(digAlgID.Algorithm, cert.GetEncoded());
 
                 v.Add(new CertStatus(digest, reqID));
             }