diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-08-02 15:02:15 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-08-02 15:02:15 +0700 |
commit | ffd9f8fde126859cd9441baef7899e5645047dae (patch) | |
tree | 08a125229bae874c58ae7b2a1348423eb144ad41 /crypto | |
parent | Use intrinsics in custom binary curves (diff) | |
download | BouncyCastle.NET-ed25519-ffd9f8fde126859cd9441baef7899e5645047dae.tar.xz |
Add span variant for Collect
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/src/crmf/PKMacBuilder.cs | 9 | ||||
-rw-r--r-- | crypto/src/crypto/IBlockResult.cs | 12 | ||||
-rw-r--r-- | crypto/src/crypto/SimpleBlockResult.cs | 9 | ||||
-rw-r--r-- | crypto/src/crypto/operators/DefaultSignatureResult.cs | 9 |
4 files changed, 38 insertions, 1 deletions
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<byte> 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 { /// <summary> @@ -20,5 +21,14 @@ namespace Org.BouncyCastle.Crypto /// <param name="destination">The byte array to copy the result into.</param> /// <param name="offset">The offset into destination to start copying the result at.</param> int Collect(byte[] destination, int offset); + +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + /// <summary> + /// Store the final result of the operation by copying it into the destination span. + /// </summary> + /// <returns>The number of bytes copied into destination.</returns> + /// <param name="destination">The span to copy the result into.</param> + int Collect(Span<byte> 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<byte> 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<byte> destination) + { + byte[] result = Collect(); + result.AsSpan().CopyTo(destination); + return result.Length; + } +#endif } } |