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,88 @@
using System.IO;
using Org.BouncyCastle.Utilities.IO;
namespace Org.BouncyCastle.Asn1;
public class BerGenerator : Asn1Generator
{
private bool _tagged = false;
private bool _isExplicit;
private int _tagNo;
protected BerGenerator(Stream outStream)
: base(outStream)
{
}
public BerGenerator(Stream outStream, int tagNo, bool isExplicit)
: base(outStream)
{
_tagged = true;
_isExplicit = isExplicit;
_tagNo = tagNo;
}
public override void AddObject(Asn1Encodable obj)
{
new BerOutputStream(base.Out).WriteObject(obj);
}
public override Stream GetRawOutputStream()
{
return base.Out;
}
public override void Close()
{
WriteBerEnd();
}
private void WriteHdr(int tag)
{
base.Out.WriteByte((byte)tag);
base.Out.WriteByte(128);
}
protected void WriteBerHeader(int tag)
{
if (_tagged)
{
int num = _tagNo | 0x80;
if (_isExplicit)
{
WriteHdr(num | 0x20);
WriteHdr(tag);
}
else if ((tag & 0x20) != 0)
{
WriteHdr(num | 0x20);
}
else
{
WriteHdr(num);
}
}
else
{
WriteHdr(tag);
}
}
protected void WriteBerBody(Stream contentStream)
{
Streams.PipeAll(contentStream, base.Out);
}
protected void WriteBerEnd()
{
base.Out.WriteByte(0);
base.Out.WriteByte(0);
if (_tagged && _isExplicit)
{
base.Out.WriteByte(0);
base.Out.WriteByte(0);
}
}
}