Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ DecodeLength()

static LengthDecodeStatus System.Formats.Asn1.AsnDecoder.DecodeLength ( ReadOnlySpan< byte > source,
AsnEncodingRules ruleSet,
out int? length,
out int bytesRead )
inlinestaticprivate

Definition at line 122 of file AsnDecoder.cs.

123 {
124 length = null;
125 bytesRead = 0;
126 if (source.IsEmpty)
127 {
128 return LengthDecodeStatus.NeedMoreData;
129 }
130 byte b = source[bytesRead];
131 bytesRead++;
132 if (b == 128)
133 {
134 if (ruleSet == AsnEncodingRules.DER)
135 {
136 bytesRead = 0;
137 return LengthDecodeStatus.DerIndefinite;
138 }
139 return LengthDecodeStatus.Success;
140 }
141 if (b < 128)
142 {
143 length = b;
144 return LengthDecodeStatus.Success;
145 }
146 if (b == byte.MaxValue)
147 {
148 bytesRead = 0;
149 return LengthDecodeStatus.ReservedValue;
150 }
151 byte b2 = (byte)(b & 0xFFFFFF7Fu);
152 if (b2 + 1 > source.Length)
153 {
154 bytesRead = 0;
155 return LengthDecodeStatus.NeedMoreData;
156 }
157 bool flag = ruleSet == AsnEncodingRules.DER || ruleSet == AsnEncodingRules.CER;
158 if (flag && b2 > 4)
159 {
160 bytesRead = 0;
161 return LengthDecodeStatus.LengthTooBig;
162 }
163 uint num = 0u;
164 for (int i = 0; i < b2; i++)
165 {
166 byte b3 = source[bytesRead];
167 bytesRead++;
168 if (num == 0)
169 {
170 if (flag && b3 == 0)
171 {
172 bytesRead = 0;
173 return LengthDecodeStatus.LaxEncodingProhibited;
174 }
175 if (!flag && b3 != 0 && b2 - i > 4)
176 {
177 bytesRead = 0;
178 return LengthDecodeStatus.LengthTooBig;
179 }
180 }
181 num <<= 8;
182 num |= b3;
183 }
184 if (num > int.MaxValue)
185 {
186 bytesRead = 0;
187 return LengthDecodeStatus.LengthTooBig;
188 }
189 if (flag && num < 128)
190 {
191 bytesRead = 0;
192 return LengthDecodeStatus.LaxEncodingProhibited;
193 }
194 length = (int)num;
195 return LengthDecodeStatus.Success;
196 }

References System.length, and System.source.

Referenced by System.Formats.Asn1.AsnDecoder.ReadLength(), and System.Formats.Asn1.AsnDecoder.TryReadLength().