diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-11-01 14:39:54 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-11-01 14:39:54 +0700 |
commit | 716a491e3ed312da6c80a74e327d62dd4388b11e (patch) | |
tree | 0adabea28431857f372256233ddd4b2e0982190b /crypto/src/asn1/DefiniteLengthInputStream.cs | |
parent | Package with LICENSE.md file (diff) | |
download | BouncyCastle.NET-ed25519-716a491e3ed312da6c80a74e327d62dd4388b11e.tar.xz |
More Span-based Stream methods
Diffstat (limited to 'crypto/src/asn1/DefiniteLengthInputStream.cs')
-rw-r--r-- | crypto/src/asn1/DefiniteLengthInputStream.cs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/crypto/src/asn1/DefiniteLengthInputStream.cs b/crypto/src/asn1/DefiniteLengthInputStream.cs index ed5bd2446..89f0d5a62 100644 --- a/crypto/src/asn1/DefiniteLengthInputStream.cs +++ b/crypto/src/asn1/DefiniteLengthInputStream.cs @@ -79,6 +79,27 @@ namespace Org.BouncyCastle.Asn1 return numRead; } +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public override int Read(Span<byte> buffer) + { + if (_remaining == 0) + return 0; + + int toRead = System.Math.Min(buffer.Length, _remaining); + int numRead = _in.Read(buffer[..toRead]); + + if (numRead < 1) + throw new EndOfStreamException("DEF length " + _originalLength + " object truncated by " + _remaining); + + if ((_remaining -= numRead) == 0) + { + SetParentEofDetect(); + } + + return numRead; + } +#endif + internal void ReadAllIntoByteArray(byte[] buf) { if (_remaining != buf.Length) |