Add span variant for Collect
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
}
}
|