init commit

This commit is contained in:
2025-10-09 09:57:24 +09:00
commit 4d551bd74f
6636 changed files with 1218703 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
using System.IO;
namespace Org.BouncyCastle.Asn1;
internal class IndefiniteLengthInputStream : LimitedInputStream
{
private int _lookAhead;
private bool _eofOn00 = true;
internal IndefiniteLengthInputStream(Stream inStream, int limit)
: base(inStream, limit)
{
_lookAhead = RequireByte();
CheckForEof();
}
internal void SetEofOn00(bool eofOn00)
{
_eofOn00 = eofOn00;
if (_eofOn00)
{
CheckForEof();
}
}
private bool CheckForEof()
{
if (_lookAhead == 0)
{
if (RequireByte() != 0)
{
throw new IOException("malformed end-of-contents marker");
}
_lookAhead = -1;
SetParentEofDetect(on: true);
return true;
}
return _lookAhead < 0;
}
public override int Read(byte[] buffer, int offset, int count)
{
if (_eofOn00 || count <= 1)
{
return base.Read(buffer, offset, count);
}
if (_lookAhead < 0)
{
return 0;
}
int num = _in.Read(buffer, offset + 1, count - 1);
if (num <= 0)
{
throw new EndOfStreamException();
}
buffer[offset] = (byte)_lookAhead;
_lookAhead = RequireByte();
return num + 1;
}
public override int ReadByte()
{
if (_eofOn00 && CheckForEof())
{
return -1;
}
int lookAhead = _lookAhead;
_lookAhead = RequireByte();
return lookAhead;
}
private int RequireByte()
{
int num = _in.ReadByte();
if (num < 0)
{
throw new EndOfStreamException();
}
return num;
}
}