From d8df5908be185bcf0ee3e32636b2ef0319626966 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Tue, 30 Aug 2022 14:29:05 +0700 Subject: Add span concatenation methods --- crypto/src/util/Arrays.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'crypto/src') diff --git a/crypto/src/util/Arrays.cs b/crypto/src/util/Arrays.cs index 247f3ab77..7a1e80115 100644 --- a/crypto/src/util/Arrays.cs +++ b/crypto/src/util/Arrays.cs @@ -944,5 +944,37 @@ namespace Org.BouncyCastle.Utilities { return null == array || array.Length < 1; } + +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + + public static byte[] Concatenate(ReadOnlySpan a, ReadOnlySpan b) + { + byte[] rv = new byte[a.Length + b.Length]; + a.CopyTo(rv); + b.CopyTo(rv.AsSpan(a.Length)); + return rv; + } + + public static byte[] Concatenate(ReadOnlySpan a, ReadOnlySpan b, ReadOnlySpan c) + { + byte[] rv = new byte[a.Length + b.Length + c.Length]; + a.CopyTo(rv); + b.CopyTo(rv.AsSpan(a.Length)); + c.CopyTo(rv.AsSpan(a.Length + b.Length)); + return rv; + } + + public static byte[] Concatenate(ReadOnlySpan a, ReadOnlySpan b, ReadOnlySpan c, + ReadOnlySpan d) + { + byte[] rv = new byte[a.Length + b.Length + c.Length + d.Length]; + a.CopyTo(rv); + b.CopyTo(rv.AsSpan(a.Length)); + c.CopyTo(rv.AsSpan(a.Length + b.Length)); + d.CopyTo(rv.AsSpan(a.Length + b.Length + c.Length)); + return rv; + } + +#endif } } -- cgit 1.4.1