From ffd9f8fde126859cd9441baef7899e5645047dae Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Tue, 2 Aug 2022 15:02:15 +0700 Subject: Add span variant for Collect --- crypto/src/crmf/PKMacBuilder.cs | 9 +++++++++ crypto/src/crypto/IBlockResult.cs | 12 +++++++++++- crypto/src/crypto/SimpleBlockResult.cs | 9 +++++++++ crypto/src/crypto/operators/DefaultSignatureResult.cs | 9 +++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) (limited to 'crypto') diff --git a/crypto/src/crmf/PKMacBuilder.cs b/crypto/src/crmf/PKMacBuilder.cs index 156936eac..8093eab44 100644 --- a/crypto/src/crmf/PKMacBuilder.cs +++ b/crypto/src/crmf/PKMacBuilder.cs @@ -83,6 +83,15 @@ namespace Org.BouncyCastle.Crmf signature.CopyTo(sig, sigOff); return signature.Length; } + +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public int Collect(Span destination) + { + byte[] result = Collect(); + result.AsSpan().CopyTo(destination); + return result.Length; + } +#endif } public class PKMacBuilder diff --git a/crypto/src/crypto/IBlockResult.cs b/crypto/src/crypto/IBlockResult.cs index 0f054fedc..3ed96a7c1 100644 --- a/crypto/src/crypto/IBlockResult.cs +++ b/crypto/src/crypto/IBlockResult.cs @@ -1,4 +1,5 @@ - +using System; + namespace Org.BouncyCastle.Crypto { /// @@ -20,5 +21,14 @@ namespace Org.BouncyCastle.Crypto /// The byte array to copy the result into. /// The offset into destination to start copying the result at. int Collect(byte[] destination, int offset); + +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + /// + /// Store the final result of the operation by copying it into the destination span. + /// + /// The number of bytes copied into destination. + /// The span to copy the result into. + int Collect(Span destination); +#endif } } diff --git a/crypto/src/crypto/SimpleBlockResult.cs b/crypto/src/crypto/SimpleBlockResult.cs index 6cacda63f..a653b0a91 100644 --- a/crypto/src/crypto/SimpleBlockResult.cs +++ b/crypto/src/crypto/SimpleBlockResult.cs @@ -49,5 +49,14 @@ namespace Org.BouncyCastle.Crypto return result.Length; } + +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public int Collect(Span destination) + { + result.AsSpan().CopyTo(destination); + + return result.Length; + } +#endif } } diff --git a/crypto/src/crypto/operators/DefaultSignatureResult.cs b/crypto/src/crypto/operators/DefaultSignatureResult.cs index 615f67dcb..fe47d792b 100644 --- a/crypto/src/crypto/operators/DefaultSignatureResult.cs +++ b/crypto/src/crypto/operators/DefaultSignatureResult.cs @@ -23,5 +23,14 @@ namespace Org.BouncyCastle.Crypto.Operators signature.CopyTo(sig, sigOff); return signature.Length; } + +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public int Collect(Span destination) + { + byte[] result = Collect(); + result.AsSpan().CopyTo(destination); + return result.Length; + } +#endif } } -- cgit 1.4.1