Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ECPrivateKey.cs
Go to the documentation of this file.
2
4
5internal struct ECPrivateKey
6{
7 internal int Version;
8
10
12
14
16 {
17 return Decode(Asn1Tag.Sequence, encoded, ruleSet);
18 }
19
21 {
22 try
23 {
25 DecodeCore(ref reader, expectedTag, encoded, out var decoded);
26 reader.ThrowIfNotEmpty();
27 return decoded;
28 }
29 catch (AsnContentException inner)
30 {
32 }
33 }
34
35 private static void DecodeCore(ref System.Formats.Asn1.AsnValueReader reader, Asn1Tag expectedTag, ReadOnlyMemory<byte> rebind, out System.Security.Cryptography.Asn1.ECPrivateKey decoded)
36 {
37 decoded = default(System.Security.Cryptography.Asn1.ECPrivateKey);
38 System.Formats.Asn1.AsnValueReader asnValueReader = reader.ReadSequence(expectedTag);
39 ReadOnlySpan<byte> span = rebind.Span;
40 if (!asnValueReader.TryReadInt32(out decoded.Version))
41 {
42 asnValueReader.ThrowIfNotEmpty();
43 }
44 int elementOffset;
45 if (asnValueReader.TryReadPrimitiveOctetString(out var value))
46 {
47 decoded.PrivateKey = (span.Overlaps(value, out elementOffset) ? rebind.Slice(elementOffset, value.Length) : ((ReadOnlyMemory<byte>)value.ToArray()));
48 }
49 else
50 {
51 decoded.PrivateKey = asnValueReader.ReadOctetString();
52 }
54 if (asnValueReader.HasData && asnValueReader.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0)))
55 {
56 reader2 = asnValueReader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
57 System.Security.Cryptography.Asn1.ECDomainParameters.Decode(ref reader2, rebind, out var decoded2);
58 decoded.Parameters = decoded2;
59 reader2.ThrowIfNotEmpty();
60 }
61 if (asnValueReader.HasData && asnValueReader.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1)))
62 {
63 reader2 = asnValueReader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 1));
64 if (reader2.TryReadPrimitiveBitString(out var unusedBitCount, out value))
65 {
66 decoded.PublicKey = (span.Overlaps(value, out elementOffset) ? rebind.Slice(elementOffset, value.Length) : ((ReadOnlyMemory<byte>)value.ToArray()));
67 }
68 else
69 {
70 decoded.PublicKey = reader2.ReadBitString(out unusedBitCount);
71 }
72 reader2.ThrowIfNotEmpty();
73 }
74 asnValueReader.ThrowIfNotEmpty();
75 }
76}
static string Cryptography_Der_Invalid_Encoding
Definition SR.cs:50
Definition SR.cs:7
static readonly Asn1Tag Sequence
Definition Asn1Tag.cs:29
bool HasSameClassAndValue(Asn1Tag other)
Definition Asn1Tag.cs:251
bool TryReadInt32(out int value, Asn1Tag? expectedTag=null)
bool TryReadPrimitiveOctetString(out ReadOnlySpan< byte > value, Asn1Tag? expectedTag=null)
byte[] ReadOctetString(Asn1Tag? expectedTag=null)
byte[] ReadBitString(out int unusedBitCount, Asn1Tag? expectedTag=null)
bool TryReadPrimitiveBitString(out int unusedBitCount, out ReadOnlySpan< byte > value, Asn1Tag? expectedTag=null)
AsnValueReader ReadSequence(Asn1Tag? expectedTag=null)
unsafe ReadOnlySpan< T > Span
ReadOnlyMemory< T > Slice(int start)
static ECDomainParameters Decode(ReadOnlyMemory< byte > encoded, AsnEncodingRules ruleSet)
System.Security.Cryptography.Asn1.? ECDomainParameters Parameters
static void DecodeCore(ref AsnValueReader reader, Asn1Tag expectedTag, ReadOnlyMemory< byte > rebind, out ECPrivateKey decoded)
static ECPrivateKey Decode(ReadOnlyMemory< byte > encoded, AsnEncodingRules ruleSet)
static System.Security.Cryptography.Asn1.ECPrivateKey Decode(ReadOnlyMemory< byte > encoded, AsnEncodingRules ruleSet)
static System.Security.Cryptography.Asn1.ECPrivateKey Decode(Asn1Tag expectedTag, ReadOnlyMemory< byte > encoded, AsnEncodingRules ruleSet)
static void DecodeCore(ref System.Formats.Asn1.AsnValueReader reader, Asn1Tag expectedTag, ReadOnlyMemory< byte > rebind, out System.Security.Cryptography.Asn1.ECPrivateKey decoded)