diff options
Diffstat (limited to 'crypto/src/cmp')
-rw-r--r-- | crypto/src/cmp/ProtectedPkiMessage.cs | 8 | ||||
-rw-r--r-- | crypto/src/cmp/ProtectedPkiMessageBuilder.cs | 18 |
2 files changed, 4 insertions, 22 deletions
diff --git a/crypto/src/cmp/ProtectedPkiMessage.cs b/crypto/src/cmp/ProtectedPkiMessage.cs index fdcdeb90d..79394094d 100644 --- a/crypto/src/cmp/ProtectedPkiMessage.cs +++ b/crypto/src/cmp/ProtectedPkiMessage.cs @@ -139,12 +139,8 @@ namespace Org.BouncyCastle.Cmp private TResult Process<TResult>(IStreamCalculator<TResult> streamCalculator) { - using (var s = streamCalculator.Stream) - { - new DerSequence(m_pkiMessage.Header, m_pkiMessage.Body).EncodeTo(s, Asn1Encodable.Der); - } - - return streamCalculator.GetResult(); + var asn1Encodable = new DerSequence(m_pkiMessage.Header, m_pkiMessage.Body); + return X509Utilities.CalculateResult(streamCalculator, asn1Encodable); } } } 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(); - } } } |