diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-11 18:58:02 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-11 18:58:02 +0700 |
commit | 7b744590df675b09e7773e2b2af3d2b1f8c528d5 (patch) | |
tree | 2884492600e4f286ffe22d11014aefd6904aecff /crypto/src/pkcs | |
parent | Fix static method references (diff) | |
download | BouncyCastle.NET-ed25519-7b744590df675b09e7773e2b2af3d2b1f8c528d5.tar.xz |
X509: Refactor stream calculator usage
Diffstat (limited to 'crypto/src/pkcs')
-rw-r--r-- | crypto/src/pkcs/Pkcs10CertificationRequest.cs | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/crypto/src/pkcs/Pkcs10CertificationRequest.cs b/crypto/src/pkcs/Pkcs10CertificationRequest.cs index dbaaa34f6..c3e21f8ed 100644 --- a/crypto/src/pkcs/Pkcs10CertificationRequest.cs +++ b/crypto/src/pkcs/Pkcs10CertificationRequest.cs @@ -269,10 +269,7 @@ namespace Org.BouncyCastle.Pkcs Init(signatureFactory, subject, publicKey, attributes); } - private void Init( - ISignatureFactory signatureFactory, - X509Name subject, - AsymmetricKeyParameter publicKey, + private void Init(ISignatureFactory signatureFactory, X509Name subject, AsymmetricKeyParameter publicKey, Asn1Set attributes) { this.sigAlgId = (AlgorithmIdentifier)signatureFactory.AlgorithmDetails; @@ -281,14 +278,7 @@ namespace Org.BouncyCastle.Pkcs this.reqInfo = new CertificationRequestInfo(subject, pubInfo, attributes); - IStreamCalculator<IBlockResult> streamCalculator = signatureFactory.CreateCalculator(); - using (Stream sigStream = streamCalculator.Stream) - { - reqInfo.EncodeTo(sigStream, Der); - } - - // Generate Signature. - sigBits = new DerBitString(streamCalculator.GetResult().Collect()); + sigBits = X509.X509Utilities.GenerateSignature(signatureFactory, reqInfo); } // internal Pkcs10CertificationRequest( @@ -337,18 +327,11 @@ namespace Org.BouncyCastle.Pkcs return Verify(verifierProvider.CreateVerifierFactory(sigAlgId)); } - public bool Verify( - IVerifierFactory verifier) + public bool Verify(IVerifierFactory verifier) { try { - IStreamCalculator<IVerifier> streamCalculator = verifier.CreateCalculator(); - using (var stream = streamCalculator.Stream) - { - reqInfo.EncodeTo(stream, Asn1Encodable.Der); - } - - return streamCalculator.GetResult().IsVerified(sigBits.GetOctets()); + return X509.X509Utilities.VerifySignature(verifier, reqInfo, sigBits); } catch (Exception e) { |