diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-11 18:55:01 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-11 18:55:01 +0700 |
commit | 767f1c498d07d59c1f98940c0e45db9206a33c30 (patch) | |
tree | 1bbf95c542d4f12e8b648dd3e770236dd44de94d /crypto/src/asn1/DerBitString.cs | |
parent | Reduce allocations in hex encoding (diff) | |
download | BouncyCastle.NET-ed25519-767f1c498d07d59c1f98940c0e45db9206a33c30.tar.xz |
Support BitString construction from ReadOnlySpan
Diffstat (limited to 'crypto/src/asn1/DerBitString.cs')
-rw-r--r-- | crypto/src/asn1/DerBitString.cs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/crypto/src/asn1/DerBitString.cs b/crypto/src/asn1/DerBitString.cs index b929de357..bc3de7fe4 100644 --- a/crypto/src/asn1/DerBitString.cs +++ b/crypto/src/asn1/DerBitString.cs @@ -118,6 +118,23 @@ namespace Org.BouncyCastle.Asn1 this.contents = Arrays.Prepend(data, (byte)padBits); } +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public DerBitString(ReadOnlySpan<byte> data) + : this(data, 0) + { + } + + public DerBitString(ReadOnlySpan<byte> data, int padBits) + { + if (padBits < 0 || padBits > 7) + throw new ArgumentException("must be in the range 0 to 7", "padBits"); + if (data.IsEmpty && padBits != 0) + throw new ArgumentException("if 'data' is empty, 'padBits' must be 0"); + + this.contents = Arrays.Prepend(data, (byte)padBits); + } +#endif + public DerBitString(int namedBits) { if (namedBits == 0) |