summary refs log tree commit diff
path: root/crypto/src/cmp/ProtectedPkiMessageBuilder.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-04-11 18:58:02 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-04-11 18:58:02 +0700
commit7b744590df675b09e7773e2b2af3d2b1f8c528d5 (patch)
tree2884492600e4f286ffe22d11014aefd6904aecff /crypto/src/cmp/ProtectedPkiMessageBuilder.cs
parentFix static method references (diff)
downloadBouncyCastle.NET-ed25519-7b744590df675b09e7773e2b2af3d2b1f8c528d5.tar.xz
X509: Refactor stream calculator usage
Diffstat (limited to 'crypto/src/cmp/ProtectedPkiMessageBuilder.cs')
-rw-r--r--crypto/src/cmp/ProtectedPkiMessageBuilder.cs18
1 files changed, 2 insertions, 16 deletions
diff --git a/crypto/src/cmp/ProtectedPkiMessageBuilder.cs b/crypto/src/cmp/ProtectedPkiMessageBuilder.cs
index 508b00ff5..a3070ee56 100644
--- a/crypto/src/cmp/ProtectedPkiMessageBuilder.cs
+++ b/crypto/src/cmp/ProtectedPkiMessageBuilder.cs
@@ -97,14 +97,12 @@ namespace Org.BouncyCastle.Cmp
             if (null == body)
                 throw new InvalidOperationException("body must be set before building");
 
-            var calculator = signatureFactory.CreateCalculator();
-
             if (!(signatureFactory.AlgorithmDetails is AlgorithmIdentifier algorithmDetails))
                 throw new ArgumentException("AlgorithmDetails is not AlgorithmIdentifier");
 
             FinalizeHeader(algorithmDetails);
             PkiHeader header = m_hdrBuilder.Build();
-            DerBitString protection = new DerBitString(CalculateSignature(calculator, header, body));
+            DerBitString protection = X509Utilities.GenerateSignature(signatureFactory, new DerSequence(header, body));
             return FinalizeMessage(header, protection);
         }
 
@@ -113,14 +111,12 @@ namespace Org.BouncyCastle.Cmp
             if (null == body)
                 throw new InvalidOperationException("body must be set before building");
 
-            var calculator = macFactory.CreateCalculator();
-
             if (!(macFactory.AlgorithmDetails is AlgorithmIdentifier algorithmDetails))
                 throw new ArgumentException("AlgorithmDetails is not AlgorithmIdentifier");
 
             FinalizeHeader(algorithmDetails);
             PkiHeader header = m_hdrBuilder.Build();
-            DerBitString protection = new DerBitString(CalculateSignature(calculator, header, body));
+            DerBitString protection = X509Utilities.GenerateMac(macFactory, new DerSequence(header, body));
             return FinalizeMessage(header, protection);
         }
 
@@ -146,15 +142,5 @@ namespace Org.BouncyCastle.Cmp
 
             return new ProtectedPkiMessage(new PkiMessage(header, body, protection, cmpCertificates));
         }
-
-        private byte[] CalculateSignature(IStreamCalculator<IBlockResult> signer, PkiHeader header, PkiBody body)
-        {
-            using (var s = signer.Stream)
-            {
-                new DerSequence(header, body).EncodeTo(s);
-            }
-
-            return signer.GetResult().Collect();
-        }
     }
 }