Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Helpers.cs
Go to the documentation of this file.
1using System;
8
10
11internal static class Helpers
12{
15 public static bool IsDSASupported
16 {
17 get
18 {
20 {
21 return !OperatingSystem.IsTvOS();
22 }
23 return false;
24 }
25 }
26
27 [return: NotNullIfNotNull("src")]
28 public static byte[] CloneByteArray(this byte[] src)
29 {
30 if (src == null)
31 {
32 return null;
33 }
34 return (byte[])src.Clone();
35 }
36
37 internal static ReadOnlySpan<byte> AsSpanParameter(this byte[] array, string paramName)
38 {
39 if (array == null)
40 {
42 }
43 return new ReadOnlySpan<byte>(array);
44 }
45
46 public static char[] ToHexArrayUpper(this byte[] bytes)
47 {
48 char[] array = new char[bytes.Length * 2];
50 return array;
51 }
52
53 public static string ToHexStringUpper(this byte[] bytes)
54 {
56 }
57
58 public static byte[] DecodeHexString(this string hexString)
59 {
60 int num = 0;
62 if (readOnlySpan.Length != 0 && readOnlySpan[0] == '\u200e')
63 {
64 readOnlySpan = readOnlySpan.Slice(1);
65 }
66 for (int i = 0; i < readOnlySpan.Length; i++)
67 {
68 if (char.IsWhiteSpace(readOnlySpan[i]))
69 {
70 num++;
71 }
72 }
73 uint num2 = (uint)(readOnlySpan.Length - num) / 2u;
74 byte[] array = new byte[num2];
75 byte b = 0;
76 bool flag = false;
77 int num3 = 0;
78 for (int j = 0; j < readOnlySpan.Length; j++)
79 {
80 char c = readOnlySpan[j];
81 if (!char.IsWhiteSpace(c))
82 {
83 b <<= 4;
84 b |= (byte)System.HexConverter.FromChar(c);
85 flag = !flag;
86 if (!flag)
87 {
88 array[num3] = b;
89 num3++;
90 }
91 }
92 }
93 return array;
94 }
95
96 public static bool ContentsEqual(this byte[] a1, byte[] a2)
97 {
98 if (a1 == null)
99 {
100 return a2 == null;
101 }
102 if (a2 == null || a1.Length != a2.Length)
103 {
104 return false;
105 }
106 for (int i = 0; i < a1.Length; i++)
107 {
108 if (a1[i] != a2[i])
109 {
110 return false;
111 }
112 }
113 return true;
114 }
115
117 {
118 foreach (T newDatum in newData)
119 {
121 }
122 }
123
124 public static bool IsValidDay(this Calendar calendar, int year, int month, int day, int era)
125 {
126 if (calendar.IsValidMonth(year, month, era) && day >= 1)
127 {
128 return day <= calendar.GetDaysInMonth(year, month, era);
129 }
130 return false;
131 }
132
133 private static bool IsValidMonth(this Calendar calendar, int year, int month, int era)
134 {
135 if (calendar.IsValidYear(year, era) && month >= 1)
136 {
137 return month <= calendar.GetMonthsInYear(year, era);
138 }
139 return false;
140 }
141
142 private static bool IsValidYear(this Calendar calendar, int year, int era)
143 {
144 if (year >= calendar.GetYear(calendar.MinSupportedDateTime))
145 {
146 return year <= calendar.GetYear(calendar.MaxSupportedDateTime);
147 }
148 return false;
149 }
150
152 {
153 try
154 {
156 while (asnReader.HasData)
157 {
158 Asn1Tag asn1Tag = asnReader.PeekTag();
159 if (asn1Tag.TagClass == TagClass.Universal)
160 {
161 switch ((UniversalTagNumber)asn1Tag.TagValue)
162 {
163 case UniversalTagNumber.External:
164 case UniversalTagNumber.Embedded:
165 case UniversalTagNumber.Sequence:
166 case UniversalTagNumber.Set:
167 case UniversalTagNumber.UnrestrictedCharacterString:
168 if (!asn1Tag.IsConstructed)
169 {
171 }
172 break;
173 default:
174 if (asn1Tag.IsConstructed)
175 {
177 }
178 break;
179 }
180 }
181 if (asn1Tag.IsConstructed)
182 {
183 ValidateDer(asnReader.PeekContentBytes());
184 }
185 asnReader.ReadEncodedValue();
186 }
187 }
188 catch (AsnContentException inner)
189 {
191 }
192 }
193
195 {
196 if (aParameters.Curve.CurveType != bParameters.Curve.CurveType)
197 {
198 return false;
199 }
200 if (!aParameters.Q.X.ContentsEqual(bParameters.Q.X) || !aParameters.Q.Y.ContentsEqual(bParameters.Q.Y))
201 {
202 return false;
203 }
204 ECCurve curve = aParameters.Curve;
205 ECCurve curve2 = bParameters.Curve;
206 if (curve.IsNamed)
207 {
208 if (curve.Oid.Value == curve2.Oid.Value)
209 {
210 return curve.Oid.FriendlyName == curve2.Oid.FriendlyName;
211 }
212 return false;
213 }
214 if (!curve.IsExplicit)
215 {
216 return false;
217 }
218 if (!curve.G.X.ContentsEqual(curve2.G.X) || !curve.G.Y.ContentsEqual(curve2.G.Y) || !curve.Order.ContentsEqual(curve2.Order) || !curve.A.ContentsEqual(curve2.A) || !curve.B.ContentsEqual(curve2.B))
219 {
220 return false;
221 }
222 if (curve.IsPrime)
223 {
224 return curve.Prime.ContentsEqual(curve2.Prime);
225 }
226 if (curve.IsCharacteristic2)
227 {
228 return curve.Polynomial.ContentsEqual(curve2.Polynomial);
229 }
230 return false;
231 }
232}
static byte[] DecodeHexString(this string hexString)
Definition Helpers.cs:58
static void ValidateDer(ReadOnlyMemory< byte > encodedValue)
Definition Helpers.cs:151
static bool IsValidYear(this Calendar calendar, int year, int era)
Definition Helpers.cs:142
static bool AreSamePublicECParameters(ECParameters aParameters, ECParameters bParameters)
Definition Helpers.cs:194
static bool IsValidMonth(this Calendar calendar, int year, int month, int era)
Definition Helpers.cs:133
static string ToHexStringUpper(this byte[] bytes)
Definition Helpers.cs:53
static void AddRange< T >(this ICollection< T > coll, IEnumerable< T > newData)
Definition Helpers.cs:116
static byte[] CloneByteArray(this byte[] src)
Definition Helpers.cs:28
static bool ContentsEqual(this byte[] a1, byte[] a2)
Definition Helpers.cs:96
static ReadOnlySpan< byte > AsSpanParameter(this byte[] array, string paramName)
Definition Helpers.cs:37
static char[] ToHexArrayUpper(this byte[] bytes)
Definition Helpers.cs:46
static bool IsValidDay(this Calendar calendar, int year, int month, int day, int era)
Definition Helpers.cs:124
void Add(TKey key, TValue value)
static string ToHexString(byte[] inArray)
Definition Convert.cs:3159
virtual DateTime MaxSupportedDateTime
Definition Calendar.cs:15
virtual bool IsValidYear(int year, int era)
Definition Calendar.cs:325
virtual bool IsValidMonth(int year, int month, int era)
Definition Calendar.cs:334
int GetYear(DateTime time)
virtual DateTime MinSupportedDateTime
Definition Calendar.cs:13
virtual int GetMonthsInYear(int year)
Definition Calendar.cs:183
virtual int GetDaysInMonth(int year, int month)
Definition Calendar.cs:150
static void EncodeToUtf16(ReadOnlySpan< byte > bytes, Span< char > chars, Casing casing=Casing.Upper)
static int FromChar(int c)
static string Cryptography_Der_Invalid_Encoding
Definition SR.cs:50
Definition SR.cs:7