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/crmf/ProofOfPossessionSigningKeyBuilder.cs | |
parent | Fix static method references (diff) | |
download | BouncyCastle.NET-ed25519-7b744590df675b09e7773e2b2af3d2b1f8c528d5.tar.xz |
X509: Refactor stream calculator usage
Diffstat (limited to 'crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs')
-rw-r--r-- | crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs b/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs index 8d2ea0bac..02af74924 100644 --- a/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs +++ b/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs @@ -1,12 +1,11 @@ using System; using System.IO; +using System.Net.Security; using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.Crmf; using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Crypto; -using Org.BouncyCastle.Crypto.Operators; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Crmf { @@ -55,43 +54,33 @@ namespace Org.BouncyCastle.Crmf throw new InvalidOperationException("name and publicKeyMAC cannot both be set."); PopoSigningKeyInput popo; + Asn1Encodable asn1Encodable; - IStreamCalculator<IBlockResult> calc = signer.CreateCalculator(); - using (Stream sigStream = calc.Stream) + if (_certRequest != null) { - if (_certRequest != null) - { - popo = null; - _certRequest.EncodeTo(sigStream, Asn1Encodable.Der); - } - else if (_name != null) - { - popo = new PopoSigningKeyInput(_name, _pubKeyInfo); - popo.EncodeTo(sigStream, Asn1Encodable.Der); - } - else - { - popo = new PopoSigningKeyInput(_publicKeyMAC, _pubKeyInfo); - popo.EncodeTo(sigStream, Asn1Encodable.Der); - } + popo = null; + asn1Encodable = _certRequest; + } + else if (_name != null) + { + popo = new PopoSigningKeyInput(_name, _pubKeyInfo); + asn1Encodable = popo; + } + else + { + popo = new PopoSigningKeyInput(_publicKeyMAC, _pubKeyInfo); + asn1Encodable = popo; } - var signature = calc.GetResult().Collect(); + var signature = X509.X509Utilities.GenerateSignature(signer, asn1Encodable); - return new PopoSigningKey(popo, (AlgorithmIdentifier)signer.AlgorithmDetails, new DerBitString(signature)); + return new PopoSigningKey(popo, (AlgorithmIdentifier)signer.AlgorithmDetails, signature); } - private ProofOfPossessionSigningKeyBuilder ImplSetPublicKeyMac(IMacFactory fact) + private ProofOfPossessionSigningKeyBuilder ImplSetPublicKeyMac(IMacFactory macFactory) { - IStreamCalculator<IBlockResult> calc = fact.CreateCalculator(); - using (var stream = calc.Stream) - { - _pubKeyInfo.EncodeTo(stream, Asn1Encodable.Der); - } - - var mac = calc.GetResult().Collect(); - - this._publicKeyMAC = new PKMacValue((AlgorithmIdentifier)fact.AlgorithmDetails, new DerBitString(mac)); + var macValue = X509.X509Utilities.GenerateMac(macFactory, _pubKeyInfo); + this._publicKeyMAC = new PKMacValue((AlgorithmIdentifier)macFactory.AlgorithmDetails, macValue); return this; } } |