Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
X509ExtensionAsn.cs
Go to the documentation of this file.
3
5
6internal struct X509ExtensionAsn
7{
8 internal string ExtnId;
9
10 internal bool Critical;
11
13
14 private static ReadOnlySpan<byte> DefaultCritical => new byte[3] { 1, 1, 0 };
15
16 internal void Encode(AsnWriter writer)
17 {
19 }
20
21 internal void Encode(AsnWriter writer, Asn1Tag tag)
22 {
23 writer.PushSequence(tag);
24 try
25 {
26 writer.WriteObjectIdentifier(ExtnId);
27 }
28 catch (ArgumentException inner)
29 {
31 }
32 AsnWriter asnWriter = new AsnWriter(AsnEncodingRules.DER);
33 asnWriter.WriteBoolean(Critical);
34 if (!asnWriter.EncodedValueEquals(DefaultCritical))
35 {
36 asnWriter.CopyTo(writer);
37 }
38 writer.WriteOctetString(ExtnValue.Span);
39 writer.PopSequence(tag);
40 }
41
42 internal static void Decode(ref System.Formats.Asn1.AsnValueReader reader, ReadOnlyMemory<byte> rebind, out X509ExtensionAsn decoded)
43 {
44 Decode(ref reader, Asn1Tag.Sequence, rebind, out decoded);
45 }
46
47 internal static void Decode(ref System.Formats.Asn1.AsnValueReader reader, Asn1Tag expectedTag, ReadOnlyMemory<byte> rebind, out X509ExtensionAsn decoded)
48 {
49 try
50 {
51 DecodeCore(ref reader, expectedTag, rebind, out decoded);
52 }
53 catch (AsnContentException inner)
54 {
56 }
57 }
58
59 private static void DecodeCore(ref System.Formats.Asn1.AsnValueReader reader, Asn1Tag expectedTag, ReadOnlyMemory<byte> rebind, out X509ExtensionAsn decoded)
60 {
61 decoded = default(X509ExtensionAsn);
62 System.Formats.Asn1.AsnValueReader asnValueReader = reader.ReadSequence(expectedTag);
63 ReadOnlySpan<byte> span = rebind.Span;
64 decoded.ExtnId = asnValueReader.ReadObjectIdentifier();
65 if (asnValueReader.HasData && asnValueReader.PeekTag().HasSameClassAndValue(Asn1Tag.Boolean))
66 {
67 decoded.Critical = asnValueReader.ReadBoolean();
68 }
69 else
70 {
72 }
73 if (asnValueReader.TryReadPrimitiveOctetString(out var value))
74 {
75 decoded.ExtnValue = (span.Overlaps(value, out var elementOffset) ? rebind.Slice(elementOffset, value.Length) : ((ReadOnlyMemory<byte>)value.ToArray()));
76 }
77 else
78 {
79 decoded.ExtnValue = asnValueReader.ReadOctetString();
80 }
81 asnValueReader.ThrowIfNotEmpty();
82 }
83
85 {
86 if (extension == null)
87 {
88 throw new ArgumentNullException("extension");
89 }
90 ExtnId = extension.Oid.Value;
91 Critical = extension.Critical;
92 ExtnValue = extension.RawData;
93 }
94}
bool EncodedValueEquals(ReadOnlySpan< byte > other)
Definition AsnWriter.cs:232
void CopyTo(AsnWriter destination)
Definition AsnWriter.cs:328
void WriteBoolean(bool value, Asn1Tag? tag=null)
Definition AsnWriter.cs:565
static string Cryptography_Der_Invalid_Encoding
Definition SR.cs:50
Definition SR.cs:7
static readonly Asn1Tag Sequence
Definition Asn1Tag.cs:29
static readonly Asn1Tag Boolean
Definition Asn1Tag.cs:11
bool HasSameClassAndValue(Asn1Tag other)
Definition Asn1Tag.cs:251
bool ReadBoolean(Asn1Tag? expectedTag=null)
string ReadObjectIdentifier(Asn1Tag? expectedTag=null)
bool TryReadPrimitiveOctetString(out ReadOnlySpan< byte > value, Asn1Tag? expectedTag=null)
byte[] ReadOctetString(Asn1Tag? expectedTag=null)
AsnValueReader ReadSequence(Asn1Tag? expectedTag=null)
unsafe ReadOnlySpan< T > Span
ReadOnlyMemory< T > Slice(int start)
void Encode(AsnWriter writer, Asn1Tag tag)
static void Decode(ref System.Formats.Asn1.AsnValueReader reader, Asn1Tag expectedTag, ReadOnlyMemory< byte > rebind, out X509ExtensionAsn decoded)
static void Decode(ref System.Formats.Asn1.AsnValueReader reader, ReadOnlyMemory< byte > rebind, out X509ExtensionAsn decoded)
static void DecodeCore(ref System.Formats.Asn1.AsnValueReader reader, Asn1Tag expectedTag, ReadOnlyMemory< byte > rebind, out X509ExtensionAsn decoded)