summary refs log tree commit diff
path: root/crypto/src/cmp/CertificateConfirmationContentBuilder.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/cmp/CertificateConfirmationContentBuilder.cs')
-rw-r--r--crypto/src/cmp/CertificateConfirmationContentBuilder.cs38
1 files changed, 27 insertions, 11 deletions
diff --git a/crypto/src/cmp/CertificateConfirmationContentBuilder.cs b/crypto/src/cmp/CertificateConfirmationContentBuilder.cs
index 32fef908b..b46c1ab0e 100644
--- a/crypto/src/cmp/CertificateConfirmationContentBuilder.cs
+++ b/crypto/src/cmp/CertificateConfirmationContentBuilder.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cmp;
+using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Operators.Utilities;
 using Org.BouncyCastle.Security;
@@ -13,8 +14,9 @@ namespace Org.BouncyCastle.Cmp
     public sealed class CertificateConfirmationContentBuilder
     {
         private readonly IDigestAlgorithmFinder m_digestAlgorithmFinder;
-        private readonly List<X509Certificate> m_acceptedCerts = new List<X509Certificate>();
-        private readonly List<BigInteger> m_acceptedReqIDs = new List<BigInteger>();
+        private readonly List<CmpCertificate> m_acceptedCerts = new List<CmpCertificate>();
+        private readonly List<AlgorithmIdentifier> m_acceptedSignatureAlgorithms = new List<AlgorithmIdentifier>();
+        private readonly List<DerInteger> m_acceptedReqIDs = new List<DerInteger>();
 
         public CertificateConfirmationContentBuilder()
             : this(DefaultDigestAlgorithmFinder.Instance)
@@ -32,11 +34,26 @@ namespace Org.BouncyCastle.Cmp
             m_digestAlgorithmFinder = digestAlgorithmFinder;
         }
 
+        // TODO[api] Rename parameters to 'cert', 'certReqID'
         public CertificateConfirmationContentBuilder AddAcceptedCertificate(X509Certificate certHolder,
             BigInteger certReqId)
         {
-            m_acceptedCerts.Add(certHolder);
-            m_acceptedReqIDs.Add(certReqId);
+            return AddAcceptedCertificate(certHolder, new DerInteger(certReqId));
+        }
+
+        public CertificateConfirmationContentBuilder AddAcceptedCertificate(X509Certificate cert, DerInteger certReqID)
+        {
+            return AddAcceptedCertificate(
+                new CmpCertificate(cert.CertificateStructure), cert.SignatureAlgorithm, certReqID);
+        }
+
+        public CertificateConfirmationContentBuilder AddAcceptedCertificate(CmpCertificate cmpCertificate,
+            AlgorithmIdentifier signatureAlgorithm, DerInteger certReqID)
+        {
+            m_acceptedCerts.Add(cmpCertificate);
+            m_acceptedSignatureAlgorithms.Add(signatureAlgorithm);
+            m_acceptedReqIDs.Add(certReqID);
+
             return this;
         }
 
@@ -45,16 +62,15 @@ namespace Org.BouncyCastle.Cmp
             Asn1EncodableVector v = new Asn1EncodableVector(m_acceptedCerts.Count);
             for (int i = 0; i != m_acceptedCerts.Count; i++)
             {
-                X509Certificate cert = m_acceptedCerts[i];
-                BigInteger reqID = m_acceptedReqIDs[i];
-
-                var sigAlgID = DefaultSignatureAlgorithmFinder.Instance.Find(cert.SigAlgName)
-                    ?? throw new CmpException("cannot find algorithm identifier for signature name");
+                CmpCertificate cmpCertificate = m_acceptedCerts[i];
+                AlgorithmIdentifier signatureAlgorithm = m_acceptedSignatureAlgorithms[i];
+                DerInteger reqID = m_acceptedReqIDs[i];
 
-                var digAlgID = m_digestAlgorithmFinder.Find(sigAlgID)
+                var digestAlgorithm = m_digestAlgorithmFinder.Find(signatureAlgorithm)
                     ?? throw new CmpException("cannot find algorithm for digest from signature");
 
-                byte[] digest = DigestUtilities.CalculateDigest(digAlgID.Algorithm, cert.GetEncoded());
+                byte[] digest = DigestUtilities.CalculateDigest(digestAlgorithm.Algorithm,
+                    cmpCertificate.GetEncoded(Asn1Encodable.Der));
 
                 v.Add(new CertStatus(digest, reqID));
             }