This commit is contained in:
niko
2026-06-04 11:42:34 +02:00
parent f39ba70a9f
commit e720b98cd1
7488 changed files with 2493818 additions and 0 deletions
+389
View File
@@ -0,0 +1,389 @@
using System;
using System.Collections;
using System.IO;
using System.Text;
namespace Mono.Security
{
// Token: 0x020000DA RID: 218
internal class ASN1
{
// Token: 0x06000ADA RID: 2778 RVA: 0x0002FF08 File Offset: 0x0002E108
public ASN1()
: this(0, null)
{
}
// Token: 0x06000ADB RID: 2779 RVA: 0x0002FF14 File Offset: 0x0002E114
public ASN1(byte tag)
: this(tag, null)
{
}
// Token: 0x06000ADC RID: 2780 RVA: 0x0002FF20 File Offset: 0x0002E120
public ASN1(byte tag, byte[] data)
{
this.m_nTag = tag;
this.m_aValue = data;
}
// Token: 0x06000ADD RID: 2781 RVA: 0x0002FF38 File Offset: 0x0002E138
public ASN1(byte[] data)
{
this.m_nTag = data[0];
int num = 0;
int num2 = (int)data[1];
if (num2 > 128)
{
num = num2 - 128;
num2 = 0;
for (int i = 0; i < num; i++)
{
num2 *= 256;
num2 += (int)data[i + 2];
}
}
else if (num2 == 128)
{
throw new NotSupportedException("Undefined length encoding.");
}
this.m_aValue = new byte[num2];
Buffer.BlockCopy(data, 2 + num, this.m_aValue, 0, num2);
if ((this.m_nTag & 32) == 32)
{
int num3 = 2 + num;
this.Decode(data, ref num3, data.Length);
}
}
// Token: 0x1700016E RID: 366
// (get) Token: 0x06000ADE RID: 2782 RVA: 0x0002FFEC File Offset: 0x0002E1EC
public int Count
{
get
{
if (this.elist == null)
{
return 0;
}
return this.elist.Count;
}
}
// Token: 0x1700016F RID: 367
// (get) Token: 0x06000ADF RID: 2783 RVA: 0x00030008 File Offset: 0x0002E208
public byte Tag
{
get
{
return this.m_nTag;
}
}
// Token: 0x17000170 RID: 368
// (get) Token: 0x06000AE0 RID: 2784 RVA: 0x00030010 File Offset: 0x0002E210
public int Length
{
get
{
if (this.m_aValue != null)
{
return this.m_aValue.Length;
}
return 0;
}
}
// Token: 0x17000171 RID: 369
// (get) Token: 0x06000AE1 RID: 2785 RVA: 0x00030028 File Offset: 0x0002E228
// (set) Token: 0x06000AE2 RID: 2786 RVA: 0x00030058 File Offset: 0x0002E258
public byte[] Value
{
get
{
if (this.m_aValue == null)
{
this.GetBytes();
}
return (byte[])this.m_aValue.Clone();
}
set
{
if (value != null)
{
this.m_aValue = (byte[])value.Clone();
}
}
}
// Token: 0x06000AE3 RID: 2787 RVA: 0x00030074 File Offset: 0x0002E274
private bool CompareArray(byte[] array1, byte[] array2)
{
bool flag = array1.Length == array2.Length;
if (flag)
{
for (int i = 0; i < array1.Length; i++)
{
if (array1[i] != array2[i])
{
return false;
}
}
}
return flag;
}
// Token: 0x06000AE4 RID: 2788 RVA: 0x000300B4 File Offset: 0x0002E2B4
public bool Equals(byte[] asn1)
{
return this.CompareArray(this.GetBytes(), asn1);
}
// Token: 0x06000AE5 RID: 2789 RVA: 0x000300C4 File Offset: 0x0002E2C4
public bool CompareValue(byte[] value)
{
return this.CompareArray(this.m_aValue, value);
}
// Token: 0x06000AE6 RID: 2790 RVA: 0x000300D4 File Offset: 0x0002E2D4
public ASN1 Add(ASN1 asn1)
{
if (asn1 != null)
{
if (this.elist == null)
{
this.elist = new ArrayList();
}
this.elist.Add(asn1);
}
return asn1;
}
// Token: 0x06000AE7 RID: 2791 RVA: 0x0003010C File Offset: 0x0002E30C
public virtual byte[] GetBytes()
{
byte[] array = null;
if (this.Count > 0)
{
int num = 0;
ArrayList arrayList = new ArrayList();
foreach (object obj in this.elist)
{
ASN1 asn = (ASN1)obj;
byte[] bytes = asn.GetBytes();
arrayList.Add(bytes);
num += bytes.Length;
}
array = new byte[num];
int num2 = 0;
for (int i = 0; i < this.elist.Count; i++)
{
byte[] array2 = (byte[])arrayList[i];
Buffer.BlockCopy(array2, 0, array, num2, array2.Length);
num2 += array2.Length;
}
}
else if (this.m_aValue != null)
{
array = this.m_aValue;
}
int num3 = 0;
byte[] array3;
if (array != null)
{
int num4 = array.Length;
if (num4 > 127)
{
if (num4 <= 255)
{
array3 = new byte[3 + num4];
Buffer.BlockCopy(array, 0, array3, 3, num4);
num3 = 129;
array3[2] = (byte)num4;
}
else if (num4 <= 65535)
{
array3 = new byte[4 + num4];
Buffer.BlockCopy(array, 0, array3, 4, num4);
num3 = 130;
array3[2] = (byte)(num4 >> 8);
array3[3] = (byte)num4;
}
else if (num4 <= 16777215)
{
array3 = new byte[5 + num4];
Buffer.BlockCopy(array, 0, array3, 5, num4);
num3 = 131;
array3[2] = (byte)(num4 >> 16);
array3[3] = (byte)(num4 >> 8);
array3[4] = (byte)num4;
}
else
{
array3 = new byte[6 + num4];
Buffer.BlockCopy(array, 0, array3, 6, num4);
num3 = 132;
array3[2] = (byte)(num4 >> 24);
array3[3] = (byte)(num4 >> 16);
array3[4] = (byte)(num4 >> 8);
array3[5] = (byte)num4;
}
}
else
{
array3 = new byte[2 + num4];
Buffer.BlockCopy(array, 0, array3, 2, num4);
num3 = num4;
}
if (this.m_aValue == null)
{
this.m_aValue = array;
}
}
else
{
array3 = new byte[2];
}
array3[0] = this.m_nTag;
array3[1] = (byte)num3;
return array3;
}
// Token: 0x06000AE8 RID: 2792 RVA: 0x0003037C File Offset: 0x0002E57C
protected void Decode(byte[] asn1, ref int anPos, int anLength)
{
while (anPos < anLength - 1)
{
byte b;
int num;
byte[] array;
this.DecodeTLV(asn1, ref anPos, out b, out num, out array);
if (b != 0)
{
ASN1 asn2 = this.Add(new ASN1(b, array));
if ((b & 32) == 32)
{
int num2 = anPos;
asn2.Decode(asn1, ref num2, num2 + num);
}
anPos += num;
}
}
}
// Token: 0x06000AE9 RID: 2793 RVA: 0x000303E4 File Offset: 0x0002E5E4
protected void DecodeTLV(byte[] asn1, ref int pos, out byte tag, out int length, out byte[] content)
{
tag = asn1[pos++];
length = (int)asn1[pos++];
if ((length & 128) == 128)
{
int num = length & 127;
length = 0;
for (int i = 0; i < num; i++)
{
length = length * 256 + (int)asn1[pos++];
}
}
content = new byte[length];
Buffer.BlockCopy(asn1, pos, content, 0, length);
}
// Token: 0x17000172 RID: 370
public ASN1 this[int index]
{
get
{
ASN1 asn;
try
{
if (this.elist == null || index >= this.elist.Count)
{
asn = null;
}
else
{
asn = (ASN1)this.elist[index];
}
}
catch (ArgumentOutOfRangeException)
{
asn = null;
}
return asn;
}
}
// Token: 0x06000AEB RID: 2795 RVA: 0x000304E8 File Offset: 0x0002E6E8
public ASN1 Element(int index, byte anTag)
{
ASN1 asn;
try
{
if (this.elist == null || index >= this.elist.Count)
{
asn = null;
}
else
{
ASN1 asn2 = (ASN1)this.elist[index];
if (asn2.Tag == anTag)
{
asn = asn2;
}
else
{
asn = null;
}
}
}
catch (ArgumentOutOfRangeException)
{
asn = null;
}
return asn;
}
// Token: 0x06000AEC RID: 2796 RVA: 0x00030574 File Offset: 0x0002E774
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendFormat("Tag: {0} {1}", this.m_nTag.ToString("X2"), Environment.NewLine);
stringBuilder.AppendFormat("Length: {0} {1}", this.Value.Length, Environment.NewLine);
stringBuilder.Append("Value: ");
stringBuilder.Append(Environment.NewLine);
for (int i = 0; i < this.Value.Length; i++)
{
stringBuilder.AppendFormat("{0} ", this.Value[i].ToString("X2"));
if ((i + 1) % 16 == 0)
{
stringBuilder.AppendFormat(Environment.NewLine, new object[0]);
}
}
return stringBuilder.ToString();
}
// Token: 0x06000AED RID: 2797 RVA: 0x0003063C File Offset: 0x0002E83C
public void SaveToFile(string filename)
{
if (filename == null)
{
throw new ArgumentNullException("filename");
}
using (FileStream fileStream = File.Create(filename))
{
byte[] bytes = this.GetBytes();
fileStream.Write(bytes, 0, bytes.Length);
}
}
// Token: 0x040002D4 RID: 724
private byte m_nTag;
// Token: 0x040002D5 RID: 725
private byte[] m_aValue;
// Token: 0x040002D6 RID: 726
private ArrayList elist;
}
}