diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-29 20:55:57 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-29 20:55:57 +0700 |
commit | e049cab36e9e68adff298acc24acdaa2551f72ef (patch) | |
tree | e772d623791461cba50b1eba3bbd4f833f893ae9 /crypto/src/crmf | |
parent | Add Objects class (diff) | |
download | BouncyCastle.NET-ed25519-e049cab36e9e68adff298acc24acdaa2551f72ef.tar.xz |
Refactoring around Stream signers
Diffstat (limited to 'crypto/src/crmf')
-rw-r--r-- | crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs b/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs index b7a3ae01a..50c2ea65c 100644 --- a/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs +++ b/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.Crmf; @@ -58,32 +59,30 @@ namespace Org.BouncyCastle.Crmf } PopoSigningKeyInput popo; - byte[] b; - IStreamCalculator calc = signer.CreateCalculator(); - if (_certRequest != null) - { - popo = null; - b = _certRequest.GetDerEncoded(); - calc.Stream.Write(b, 0, b.Length); - } - else if (_name != null) - { - popo = new PopoSigningKeyInput(_name, _pubKeyInfo); - b = popo.GetDerEncoded(); - calc.Stream.Write(b, 0, b.Length); - } - else + IStreamCalculator calc = signer.CreateCalculator(); + using (Stream sigStream = calc.Stream) { - popo = new PopoSigningKeyInput(_publicKeyMAC, _pubKeyInfo); - b = popo.GetDerEncoded(); - calc.Stream.Write(b, 0, b.Length); + 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); + } } - calc.Stream.Flush(); - Platform.Dispose(calc.Stream); - DefaultSignatureResult res = (DefaultSignatureResult)calc.GetResult(); - return new PopoSigningKey(popo, (AlgorithmIdentifier)signer.AlgorithmDetails, new DerBitString(res.Collect())); + var signature = ((IBlockResult)calc.GetResult()).Collect(); + + return new PopoSigningKey(popo, (AlgorithmIdentifier)signer.AlgorithmDetails, new DerBitString(signature)); } } } |