Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TbsCertificateAsn.cs
Go to the documentation of this file.
4
6
7internal struct TbsCertificateAsn
8{
9 internal int Version;
10
12
14
16
18
20
22
24
26
28
29 private static ReadOnlySpan<byte> DefaultVersion => new byte[3] { 2, 1, 0 };
30
31 internal void Encode(AsnWriter writer)
32 {
34 }
35
36 internal void Encode(AsnWriter writer, Asn1Tag tag)
37 {
38 writer.PushSequence(tag);
40 asnWriter.WriteInteger(Version);
41 if (!asnWriter.EncodedValueEquals(DefaultVersion))
42 {
43 writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
45 writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
46 }
47 writer.WriteInteger(SerialNumber.Span);
49 if (!Asn1Tag.TryDecode(Issuer.Span, out var tag2, out var bytesConsumed) || !tag2.HasSameClassAndValue(new Asn1Tag(UniversalTagNumber.Sequence)))
50 {
51 throw new CryptographicException();
52 }
53 try
54 {
55 writer.WriteEncodedValue(Issuer.Span);
56 }
57 catch (ArgumentException inner)
58 {
60 }
62 if (!Asn1Tag.TryDecode(Subject.Span, out var tag3, out bytesConsumed) || !tag3.HasSameClassAndValue(new Asn1Tag(UniversalTagNumber.Sequence)))
63 {
64 throw new CryptographicException();
65 }
66 try
67 {
68 writer.WriteEncodedValue(Subject.Span);
69 }
71 {
73 }
75 if (IssuerUniqueId.HasValue)
76 {
77 writer.WriteBitString(IssuerUniqueId.Value.Span, 0, new Asn1Tag(TagClass.ContextSpecific, 1));
78 }
79 if (SubjectUniqueId.HasValue)
80 {
81 writer.WriteBitString(SubjectUniqueId.Value.Span, 0, new Asn1Tag(TagClass.ContextSpecific, 2));
82 }
83 if (Extensions != null)
84 {
85 writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
86 writer.PushSequence();
87 for (int i = 0; i < Extensions.Length; i++)
88 {
89 Extensions[i].Encode(writer);
90 }
91 writer.PopSequence();
92 writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
93 }
94 writer.PopSequence(tag);
95 }
96
101
103 {
104 try
105 {
107 }
108 catch (AsnContentException inner)
109 {
111 }
112 }
113
115 {
116 decoded = default(TbsCertificateAsn);
120 if (reader2.HasData && reader2.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0)))
121 {
122 asnValueReader = reader2.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
123 if (!asnValueReader.TryReadInt32(out decoded.Version))
124 {
125 asnValueReader.ThrowIfNotEmpty();
126 }
127 asnValueReader.ThrowIfNotEmpty();
128 }
129 else
130 {
132 if (!asnValueReader2.TryReadInt32(out decoded.Version))
133 {
134 asnValueReader2.ThrowIfNotEmpty();
135 }
136 }
137 ReadOnlySpan<byte> value = reader2.ReadIntegerBytes();
138 decoded.SerialNumber = (span.Overlaps(value, out var elementOffset) ? rebind.Slice(elementOffset, value.Length) : ((ReadOnlyMemory<byte>)value.ToArray()));
140 if (!reader2.PeekTag().HasSameClassAndValue(new Asn1Tag(UniversalTagNumber.Sequence)))
141 {
142 throw new CryptographicException();
143 }
144 value = reader2.ReadEncodedValue();
145 decoded.Issuer = (span.Overlaps(value, out elementOffset) ? rebind.Slice(elementOffset, value.Length) : ((ReadOnlyMemory<byte>)value.ToArray()));
147 if (!reader2.PeekTag().HasSameClassAndValue(new Asn1Tag(UniversalTagNumber.Sequence)))
148 {
149 throw new CryptographicException();
150 }
151 value = reader2.ReadEncodedValue();
152 decoded.Subject = (span.Overlaps(value, out elementOffset) ? rebind.Slice(elementOffset, value.Length) : ((ReadOnlyMemory<byte>)value.ToArray()));
154 int unusedBitCount;
155 if (reader2.HasData && reader2.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1)))
156 {
157 if (reader2.TryReadPrimitiveBitString(out unusedBitCount, out value, new Asn1Tag(TagClass.ContextSpecific, 1)))
158 {
159 decoded.IssuerUniqueId = (span.Overlaps(value, out elementOffset) ? rebind.Slice(elementOffset, value.Length) : ((ReadOnlyMemory<byte>)value.ToArray()));
160 }
161 else
162 {
163 decoded.IssuerUniqueId = reader2.ReadBitString(out unusedBitCount, new Asn1Tag(TagClass.ContextSpecific, 1));
164 }
165 }
166 if (reader2.HasData && reader2.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 2)))
167 {
168 if (reader2.TryReadPrimitiveBitString(out unusedBitCount, out value, new Asn1Tag(TagClass.ContextSpecific, 2)))
169 {
170 decoded.SubjectUniqueId = (span.Overlaps(value, out elementOffset) ? rebind.Slice(elementOffset, value.Length) : ((ReadOnlyMemory<byte>)value.ToArray()));
171 }
172 else
173 {
174 decoded.SubjectUniqueId = reader2.ReadBitString(out unusedBitCount, new Asn1Tag(TagClass.ContextSpecific, 2));
175 }
176 }
177 if (reader2.HasData && reader2.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 3)))
178 {
179 asnValueReader = reader2.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
182 while (reader3.HasData)
183 {
185 list.Add(decoded2);
186 }
187 decoded.Extensions = list.ToArray();
188 asnValueReader.ThrowIfNotEmpty();
189 }
190 reader2.ThrowIfNotEmpty();
191 }
192}
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
static string Cryptography_Der_Invalid_Encoding
Definition SR.cs:50
Definition SR.cs:7
static readonly Asn1Tag Sequence
Definition Asn1Tag.cs:29
static bool TryDecode(ReadOnlySpan< byte > source, out Asn1Tag tag, out int bytesConsumed)
Definition Asn1Tag.cs:87
unsafe ReadOnlySpan< T > Span
static void Decode(ref AsnValueReader reader, ReadOnlyMemory< byte > rebind, out AlgorithmIdentifierAsn decoded)
static void Decode(ref AsnValueReader reader, ReadOnlyMemory< byte > rebind, out SubjectPublicKeyInfoAsn decoded)
static void Decode(ref System.Formats.Asn1.AsnValueReader reader, ReadOnlyMemory< byte > rebind, out X509ExtensionAsn decoded)
System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn SignatureAlgorithm
static void DecodeCore(ref System.Formats.Asn1.AsnValueReader reader, Asn1Tag expectedTag, ReadOnlyMemory< byte > rebind, out TbsCertificateAsn decoded)
static void Decode(ref System.Formats.Asn1.AsnValueReader reader, Asn1Tag expectedTag, ReadOnlyMemory< byte > rebind, out TbsCertificateAsn decoded)
System.Security.Cryptography.Asn1.SubjectPublicKeyInfoAsn SubjectPublicKeyInfo
static void Decode(ref System.Formats.Asn1.AsnValueReader reader, ReadOnlyMemory< byte > rebind, out TbsCertificateAsn decoded)
static void Decode(ref System.Formats.Asn1.AsnValueReader reader, ReadOnlyMemory< byte > rebind, out ValidityAsn decoded)