diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-08-30 14:29:05 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-08-30 14:29:05 +0700 |
commit | d8df5908be185bcf0ee3e32636b2ef0319626966 (patch) | |
tree | 5707363662a812dbaf45505dc926787eae79a074 /crypto/src | |
parent | Span-based variant for IStreamCipher.ProcessBytes (diff) | |
download | BouncyCastle.NET-ed25519-d8df5908be185bcf0ee3e32636b2ef0319626966.tar.xz |
Add span concatenation methods
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/util/Arrays.cs | 32 |
1 files changed, 32 insertions, 0 deletions
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<byte> a, ReadOnlySpan<byte> 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<byte> a, ReadOnlySpan<byte> b, ReadOnlySpan<byte> 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<byte> a, ReadOnlySpan<byte> b, ReadOnlySpan<byte> c, + ReadOnlySpan<byte> 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 } } |