micro509 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2064 -0
- package/README.md +105 -225
- package/dist/crypto/crypto.d.ts +42 -11
- package/dist/crypto/crypto.js +53 -22
- package/dist/crypto/crypto.js.map +1 -1
- package/dist/crypto.d.ts +2 -2
- package/dist/crypto.js +1 -2
- package/dist/der/der.d.ts +41 -33
- package/dist/der/der.js +26 -24
- package/dist/der/der.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.js +19 -19
- package/dist/internal/asn1/asn1.d.ts +3 -6
- package/dist/internal/asn1/asn1.js +343 -43
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/ber.js +146 -0
- package/dist/internal/asn1/ber.js.map +1 -0
- package/dist/internal/asn1/decode-refusal.js +29 -0
- package/dist/internal/asn1/decode-refusal.js.map +1 -0
- package/dist/internal/asn1/der.d.ts +38 -41
- package/dist/internal/asn1/der.js +131 -52
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js +83 -53
- package/dist/internal/asn1/oids.js.map +1 -1
- package/dist/internal/asn1/oids2.js +1 -2
- package/dist/internal/asn1/oids2.js.map +1 -1
- package/dist/internal/crypto/algorithm-names.js +1 -2
- package/dist/internal/crypto/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/ecdsa.js +13 -8
- package/dist/internal/crypto/ecdsa.js.map +1 -1
- package/dist/internal/crypto/hash.js +1 -2
- package/dist/internal/crypto/hash.js.map +1 -1
- package/dist/internal/crypto/pbes2.d.ts +24 -11
- package/dist/internal/crypto/pbes2.js +79 -26
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/rsa-pss.js +46 -44
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +4 -7
- package/dist/internal/crypto/sig-verify.js +107 -60
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/crypto/signing.d.ts +1 -4
- package/dist/internal/crypto/signing.js +28 -29
- package/dist/internal/crypto/signing.js.map +1 -1
- package/dist/internal/crypto/webcrypto.js +1 -2
- package/dist/internal/crypto/webcrypto.js.map +1 -1
- package/dist/internal/shared/base64.js +1 -2
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.d.ts +3 -6
- package/dist/internal/shared/dn.js +99 -53
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/idna-tables.js +7217 -0
- package/dist/internal/shared/idna-tables.js.map +1 -0
- package/dist/internal/shared/idna.js +296 -0
- package/dist/internal/shared/idna.js.map +1 -0
- package/dist/internal/shared/ip.d.ts +4 -7
- package/dist/internal/shared/ip.js +1 -2
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/shared/mailbox.js +26 -0
- package/dist/internal/shared/mailbox.js.map +1 -0
- package/dist/internal/shared/punycode.js +101 -0
- package/dist/internal/shared/punycode.js.map +1 -0
- package/dist/internal/shared/rfc3454-tables.js +1 -2
- package/dist/internal/shared/rfc3454-tables.js.map +1 -1
- package/dist/internal/shared/rfc4518-tables.js +119 -0
- package/dist/internal/shared/rfc4518-tables.js.map +1 -0
- package/dist/internal/shared/uri-host.js +102 -0
- package/dist/internal/shared/uri-host.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +246 -131
- package/dist/internal/verify/name-constraints-engine.js.map +1 -1
- package/dist/internal/verify/policy-engine.js +6 -21
- package/dist/internal/verify/policy-engine.js.map +1 -1
- package/dist/internal/verify/verify-path.d.ts +1 -4
- package/dist/internal/verify/verify-path.js +267 -131
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/internal/x509/directory-name.js +1 -2
- package/dist/internal/x509/directory-name.js.map +1 -1
- package/dist/internal/x509/extension-bits.js +2 -3
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.d.ts +1 -4
- package/dist/internal/x509/extension-errors.js +1 -2
- package/dist/internal/x509/extension-errors.js.map +1 -1
- package/dist/internal/x509/extension-registry.js +107 -89
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-profile.js +129 -0
- package/dist/internal/x509/general-name-profile.js.map +1 -0
- package/dist/internal/x509/general-name-tags.js +1 -2
- package/dist/internal/x509/general-name-tags.js.map +1 -1
- package/dist/internal/x509/general-name.js +128 -42
- package/dist/internal/x509/general-name.js.map +1 -1
- package/dist/internal/x509/name-fields.js +1 -2
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/internal/x509/or-address.js +217 -0
- package/dist/internal/x509/or-address.js.map +1 -0
- package/dist/keys/keys.d.ts +112 -97
- package/dist/keys/keys.js +211 -204
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +3 -3
- package/dist/pem/pem.d.ts +14 -17
- package/dist/pem/pem.js +16 -17
- package/dist/pem/pem.js.map +1 -1
- package/dist/pem.js +1 -2
- package/dist/pkcs/pfx.d.ts +57 -32
- package/dist/pkcs/pfx.js +209 -173
- package/dist/pkcs/pfx.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.d.ts +104 -27
- package/dist/pkcs/pkcs12-mac.js +266 -79
- package/dist/pkcs/pkcs12-mac.js.map +1 -1
- package/dist/pkcs/pkcs7.d.ts +43 -37
- package/dist/pkcs/pkcs7.js +218 -217
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +4 -3
- package/dist/result/result.d.ts +27 -20
- package/dist/result/result.js +8 -3
- package/dist/result/result.js.map +1 -1
- package/dist/result.d.ts +2 -2
- package/dist/result.js +1 -2
- package/dist/revocation/chain.d.ts +101 -23
- package/dist/revocation/chain.js +436 -182
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +131 -67
- package/dist/revocation/crl.js +444 -323
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +94 -59
- package/dist/revocation/ocsp.js +331 -293
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +47 -35
- package/dist/revocation/revocation.js +88 -57
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +3 -3
- package/dist/verify/identity.d.ts +16 -19
- package/dist/verify/identity.js +118 -89
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/name-constraints.d.ts +1 -4
- package/dist/verify/policy.d.ts +9 -7
- package/dist/verify/verify.d.ts +84 -46
- package/dist/verify/verify.js +300 -152
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +2 -2
- package/dist/x509/certificate.d.ts +20 -21
- package/dist/x509/certificate.js +62 -46
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.d.ts +5 -7
- package/dist/x509/csr.js +10 -11
- package/dist/x509/csr.js.map +1 -1
- package/dist/x509/extensions.d.ts +154 -66
- package/dist/x509/extensions.js +317 -151
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.d.ts +4 -7
- package/dist/x509/fingerprint.js +1 -2
- package/dist/x509/fingerprint.js.map +1 -1
- package/dist/x509/name-text.d.ts +7 -9
- package/dist/x509/name-text.js +18 -4
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.d.ts +9 -11
- package/dist/x509/name.js +18 -19
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +84 -69
- package/dist/x509/parse.js +421 -400
- package/dist/x509/parse.js.map +1 -1
- package/dist/x509.d.ts +2 -2
- package/package.json +76 -59
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { throwDecodeRefusal as e } from "./decode-refusal.js";
|
|
2
|
+
// src/internal/asn1/der.ts
|
|
2
3
|
/**
|
|
3
4
|
* Low-level DER encoding and reading helpers shared across the library.
|
|
4
5
|
*
|
|
@@ -11,7 +12,7 @@
|
|
|
11
12
|
*
|
|
12
13
|
* Guards against stack exhaustion from pathologically nested input.
|
|
13
14
|
*/
|
|
14
|
-
const
|
|
15
|
+
const t = 64;
|
|
15
16
|
/**
|
|
16
17
|
* Produces the DER length octets for a given byte count.
|
|
17
18
|
*
|
|
@@ -114,6 +115,10 @@ function integerFromNumber(e) {
|
|
|
114
115
|
if (!Number.isSafeInteger(e) || e < 0) throw Error("INTEGER must be a non-negative safe integer");
|
|
115
116
|
return integer(e === 0 ? Uint8Array.of(0) : Uint8Array.from(encodeBase256(e)));
|
|
116
117
|
}
|
|
118
|
+
/** Encodes a DER ENUMERATED (tag `0x0a`) from a non-negative safe integer. */
|
|
119
|
+
function enumeratedFromNumber(e) {
|
|
120
|
+
return concatBytes([Uint8Array.of(10), integerFromNumber(e).subarray(1)]);
|
|
121
|
+
}
|
|
117
122
|
/** Encodes a DER BOOLEAN (tag `0x01`): `true` → `0xff`, `false` → `0x00`. */
|
|
118
123
|
function bool(e) {
|
|
119
124
|
return tlv(1, Uint8Array.of(e ? 255 : 0));
|
|
@@ -139,8 +144,28 @@ function bitString(e, t = 0) {
|
|
|
139
144
|
if (e.length > 0 && t > 0 && (e[e.length - 1] ?? 0) & (1 << t) - 1) throw Error("unused bits in the last byte must be zero");
|
|
140
145
|
return tlv(3, concatBytes([Uint8Array.of(t), e]));
|
|
141
146
|
}
|
|
142
|
-
|
|
147
|
+
function hasLoneSurrogate(e) {
|
|
148
|
+
for (let t = 0; t < e.length; t += 1) {
|
|
149
|
+
let n = e.charCodeAt(t);
|
|
150
|
+
if (n >= 55296 && n <= 56319) {
|
|
151
|
+
let n = e.charCodeAt(t + 1);
|
|
152
|
+
if (n >= 56320 && n <= 57343) {
|
|
153
|
+
t += 1;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
return !0;
|
|
157
|
+
}
|
|
158
|
+
if (n >= 56320 && n <= 57343) return !0;
|
|
159
|
+
}
|
|
160
|
+
return !1;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Encodes a DER UTF8String (tag `0x0c`).
|
|
164
|
+
*
|
|
165
|
+
* @throws on a lone surrogate, which has no UTF-8 encoding.
|
|
166
|
+
*/
|
|
143
167
|
function utf8String(e) {
|
|
168
|
+
if (hasLoneSurrogate(e)) throw Error("Invalid UTF8String: lone surrogate");
|
|
144
169
|
return tlv(12, new TextEncoder().encode(e));
|
|
145
170
|
}
|
|
146
171
|
/**
|
|
@@ -152,6 +177,15 @@ function printableString(e) {
|
|
|
152
177
|
if (!/^[A-Za-z0-9 '()+,\-./:=?]*$/.test(e)) throw Error("Invalid PrintableString: contains characters outside the allowed set");
|
|
153
178
|
return tlv(19, new TextEncoder().encode(e));
|
|
154
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Encodes a DER VisibleString (tag `0x1a`).
|
|
182
|
+
*
|
|
183
|
+
* @throws if the input contains a character outside the printable ASCII range 0x20 to 0x7e.
|
|
184
|
+
*/
|
|
185
|
+
function visibleString(e) {
|
|
186
|
+
if (!/^[\x20-\x7e]*$/.test(e)) throw Error("Invalid VisibleString: contains characters outside 0x20 to 0x7e");
|
|
187
|
+
return tlv(26, new TextEncoder().encode(e));
|
|
188
|
+
}
|
|
155
189
|
/** Validates a string is ASCII (IA5) and returns its content bytes, without a tag. */
|
|
156
190
|
function ia5Bytes(e) {
|
|
157
191
|
for (let t = 0; t < e.length; t++) if (e.charCodeAt(t) > 127) throw Error("Invalid IA5String: contains non-ASCII characters");
|
|
@@ -168,7 +202,8 @@ function ia5String(e) {
|
|
|
168
202
|
/**
|
|
169
203
|
* Encodes a DER BMPString (tag `0x1e`) as big-endian UTF-16.
|
|
170
204
|
*
|
|
171
|
-
* @throws on lone surrogates
|
|
205
|
+
* @throws on lone surrogates, on U+FFFE and U+FFFF, which X.680 §41.15 leaves
|
|
206
|
+
* out of BMPString, and on code points above the Basic Multilingual Plane.
|
|
172
207
|
*/
|
|
173
208
|
function bmpString(e) {
|
|
174
209
|
let t = [];
|
|
@@ -176,6 +211,7 @@ function bmpString(e) {
|
|
|
176
211
|
let e = n.codePointAt(0) ?? 0;
|
|
177
212
|
if (e > 65535) throw Error("Invalid BMPString: code point above the Basic Multilingual Plane");
|
|
178
213
|
if (e >= 55296 && e <= 57343) throw Error("Invalid BMPString: lone surrogate");
|
|
214
|
+
if (e >= 65534) throw Error("Invalid BMPString: U+FFFE and U+FFFF are not BMPString characters");
|
|
179
215
|
t.push(e >> 8 & 255, e & 255);
|
|
180
216
|
}
|
|
181
217
|
return tlv(30, Uint8Array.from(t));
|
|
@@ -194,11 +230,21 @@ function universalString(e) {
|
|
|
194
230
|
}
|
|
195
231
|
return tlv(28, Uint8Array.from(t));
|
|
196
232
|
}
|
|
233
|
+
const n = 1n << BigInt(448), r = n.toString().length;
|
|
234
|
+
function parseOidArc(e) {
|
|
235
|
+
if (!/^\d+$/.test(e)) throw Error(`Invalid OID segment: ${e}`);
|
|
236
|
+
let t = e.replace(/^0+/, "");
|
|
237
|
+
return t.length > r && throwOidLimit(), BigInt(t.length === 0 ? "0" : t);
|
|
238
|
+
}
|
|
239
|
+
function throwOidLimit() {
|
|
240
|
+
return e("limit_exceeded", "OID sub-identifier exceeds 64 octets");
|
|
241
|
+
}
|
|
197
242
|
/** Encode a non-negative integer as a base-128 sub-identifier ({@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690 §8.19.2}). */
|
|
198
243
|
function encodeBase128(e) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
244
|
+
e >= n && throwOidLimit();
|
|
245
|
+
let t = [Number(e & 127n)];
|
|
246
|
+
for (let n = e >> 7n; n > 0n; n >>= 7n) t.push(128 | Number(n & 127n));
|
|
247
|
+
return t.reverse();
|
|
202
248
|
}
|
|
203
249
|
/**
|
|
204
250
|
* Encodes a dotted-decimal OID string as a DER OBJECT IDENTIFIER (tag `0x06`).
|
|
@@ -209,18 +255,15 @@ function encodeBase128(e) {
|
|
|
209
255
|
* Sub-identifiers are encoded with base-128 continuation.
|
|
210
256
|
*/
|
|
211
257
|
function objectIdentifier(e) {
|
|
212
|
-
let t =
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
});
|
|
216
|
-
if (n
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
let o = encodeBase128(r * 40n + i);
|
|
222
|
-
for (let e of a) o.push(...encodeBase128(e));
|
|
223
|
-
return tlv(6, Uint8Array.from(o));
|
|
258
|
+
let t = e.split(".").map(parseOidArc);
|
|
259
|
+
if (t.length < 2) throw Error(`Invalid OID: ${e}`);
|
|
260
|
+
let [n, r, ...i] = t;
|
|
261
|
+
if (n === void 0 || r === void 0) throw Error(`Invalid OID: ${e}`);
|
|
262
|
+
if (n !== 0n && n !== 1n && n !== 2n) throw Error(`Invalid OID first arc: ${n}`);
|
|
263
|
+
if ((n === 0n || n === 1n) && r >= 40n) throw Error(`Invalid OID second arc: ${r} (must be < 40 when first arc is ${n})`);
|
|
264
|
+
let a = encodeBase128(n * 40n + r);
|
|
265
|
+
for (let e of i) a.push(...encodeBase128(e));
|
|
266
|
+
return tlv(6, Uint8Array.from(a));
|
|
224
267
|
}
|
|
225
268
|
/**
|
|
226
269
|
* Encodes a `Date` as a DER UTCTime (tag `0x17`), format `YYMMDDHHMMSSZ`.
|
|
@@ -281,52 +324,83 @@ function encodeBase256(e) {
|
|
|
281
324
|
return t;
|
|
282
325
|
}
|
|
283
326
|
/**
|
|
327
|
+
* Reads the identifier octets at {@linkcode offset} by X.690 §8.1.2, which BER
|
|
328
|
+
* and DER share.
|
|
329
|
+
*
|
|
330
|
+
* @throws on truncated identifier octets, a high-tag-number form with a leading
|
|
331
|
+
* zero group or a tag number below 31, and `limit_exceeded` on a tag number
|
|
332
|
+
* above {@linkcode Number.MAX_SAFE_INTEGER}.
|
|
333
|
+
*/
|
|
334
|
+
function readIdentifier(t, n) {
|
|
335
|
+
let r = t[n];
|
|
336
|
+
if (r === void 0) throw Error("Unexpected end of identifier octets");
|
|
337
|
+
if ((r & 31) != 31) return {
|
|
338
|
+
tag: r,
|
|
339
|
+
tagNumber: r & 31,
|
|
340
|
+
length: 1
|
|
341
|
+
};
|
|
342
|
+
if (t[n + 1] === 128) throw Error("High-tag-number form must not open with a zero group");
|
|
343
|
+
let i = n + 1;
|
|
344
|
+
for (; (t[i] ?? 0) & 128;) i += 1;
|
|
345
|
+
if (t[i] === void 0) throw Error("Unexpected end of identifier octets");
|
|
346
|
+
let a = 0;
|
|
347
|
+
for (let r = n + 1; r <= i; r += 1) {
|
|
348
|
+
let n = (t[r] ?? 0) & 127;
|
|
349
|
+
a > (2 ** 53 - 1 - n) / 128 && e("limit_exceeded", "Tag number exceeds Number.MAX_SAFE_INTEGER"), a = a * 128 + n;
|
|
350
|
+
}
|
|
351
|
+
if (a < 31) throw Error("Tag numbers below 31 must use the low-tag-number form");
|
|
352
|
+
return {
|
|
353
|
+
tag: r,
|
|
354
|
+
tagNumber: a,
|
|
355
|
+
length: i - n + 1
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
284
359
|
* Reads one TLV element from {@linkcode bytes} starting at {@linkcode offset}.
|
|
285
360
|
*
|
|
286
|
-
* Parses the
|
|
361
|
+
* Parses the identifier octets, decodes the DER length octets, and slices out the value bytes.
|
|
287
362
|
*
|
|
288
|
-
* @throws on truncated input, indefinite lengths, and non-minimal length encodings.
|
|
289
|
-
* @param offset Byte position of the
|
|
363
|
+
* @throws on truncated input, malformed identifier octets, indefinite lengths, and non-minimal length encodings.
|
|
364
|
+
* @param offset Byte position of the leading identifier octet. Defaults to 0.
|
|
290
365
|
*/
|
|
291
366
|
function readElement(e, t = 0) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
if (
|
|
295
|
-
let r =
|
|
296
|
-
if (
|
|
297
|
-
let { headerLength: i, length: a } = readDerLength(e, t, r), o = t + i, s = o + a;
|
|
298
|
-
if (s > e.length) throw Error("DER element exceeds input length");
|
|
367
|
+
if (e[t] === void 0) throw Error("Unexpected end of DER input");
|
|
368
|
+
let n = readIdentifier(e, t), r = t + n.length, i = e[r];
|
|
369
|
+
if (i === void 0) throw Error("Unexpected end of DER input");
|
|
370
|
+
let { lengthOctets: a, length: o } = readDerLength(e, r, i), s = n.length + a, c = t + s, l = c + o;
|
|
371
|
+
if (l > e.length) throw Error("DER element exceeds input length");
|
|
299
372
|
return {
|
|
300
|
-
tag: n,
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
373
|
+
tag: n.tag,
|
|
374
|
+
tagNumber: n.tagNumber,
|
|
375
|
+
headerLength: s,
|
|
376
|
+
length: o,
|
|
377
|
+
start: c,
|
|
378
|
+
end: l,
|
|
379
|
+
value: e.slice(c, l)
|
|
306
380
|
};
|
|
307
381
|
}
|
|
308
382
|
/** Decodes and validates the definite-length field of a DER element. */
|
|
309
383
|
function readDerLength(e, t, n) {
|
|
310
384
|
if (!(n & 128)) return {
|
|
311
|
-
|
|
385
|
+
lengthOctets: 1,
|
|
312
386
|
length: n
|
|
313
387
|
};
|
|
314
388
|
let r = n & 127;
|
|
315
389
|
if (r === 0) throw Error("Indefinite lengths are not supported");
|
|
316
|
-
let i = e[t +
|
|
390
|
+
let i = e[t + 1];
|
|
317
391
|
if (i === void 0) throw Error("Unexpected end of DER input");
|
|
318
392
|
if (i === 0) throw Error("Non-minimal DER length encoding");
|
|
319
393
|
let a = readLongFormDerLength(e, t, r);
|
|
320
394
|
if (a < 128) throw Error("Non-minimal DER length encoding");
|
|
321
395
|
return {
|
|
322
|
-
|
|
396
|
+
lengthOctets: 1 + r,
|
|
323
397
|
length: a
|
|
324
398
|
};
|
|
325
399
|
}
|
|
326
400
|
function readLongFormDerLength(e, t, n) {
|
|
327
401
|
let r = 0;
|
|
328
402
|
for (let i = 0; i < n; i += 1) {
|
|
329
|
-
let n = e[t +
|
|
403
|
+
let n = e[t + 1 + i];
|
|
330
404
|
if (n === void 0) throw Error("Unexpected end of DER input");
|
|
331
405
|
if (r > Math.floor((2 ** 53 - 1 - n) / 256)) throw Error("DER length exceeds safe integer range");
|
|
332
406
|
r = r * 256 + n;
|
|
@@ -341,19 +415,25 @@ function readLongFormDerLength(e, t, n) {
|
|
|
341
415
|
* @throws if nesting exceeds {@linkcode maxDepth}.
|
|
342
416
|
*/
|
|
343
417
|
function assertDerMaxDepth(e, t = 64, n) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
418
|
+
walkDerTree(e, t, n, () => void 0);
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Walks the full DER tree rooted in {@linkcode bytes}, calling {@linkcode visit}
|
|
422
|
+
* on each element before reading its children.
|
|
423
|
+
*
|
|
424
|
+
* @throws if the tree is malformed or nests beyond {@linkcode maxDepth}.
|
|
425
|
+
*/
|
|
426
|
+
function walkDerTree(t, n, r, i) {
|
|
427
|
+
if (!Number.isSafeInteger(n) || n < 1) throw Error("DER max depth must be a positive safe integer");
|
|
428
|
+
let a = readElement(t, 0);
|
|
429
|
+
if (a.end !== t.length) throw Error("Trailing data after DER element");
|
|
430
|
+
let o = [{
|
|
431
|
+
element: a,
|
|
349
432
|
depth: 1
|
|
350
433
|
}];
|
|
351
|
-
for (;
|
|
352
|
-
let
|
|
353
|
-
|
|
354
|
-
if (r.depth > t) throw Error(`DER exceeds max depth of ${t}`);
|
|
355
|
-
r.element.tag & 32 && pushDerChildren(e, r, i, n);
|
|
356
|
-
}
|
|
434
|
+
for (; o.length > 0;) {
|
|
435
|
+
let a = o.pop();
|
|
436
|
+
a !== void 0 && (a.depth > n && e("limit_exceeded", `DER exceeds max depth of ${n}`), i(a.element), a.element.tag & 32 && pushDerChildren(t, a, o, r));
|
|
357
437
|
}
|
|
358
438
|
}
|
|
359
439
|
function pushDerChildren(e, t, n, r) {
|
|
@@ -433,7 +513,6 @@ function assertValidDate(e, t) {
|
|
|
433
513
|
function canTreatAsOpaqueLeaf(e, t, n) {
|
|
434
514
|
return t === e.start && n?.allowOpaqueConstructedTags?.includes(e.tag) === !0;
|
|
435
515
|
}
|
|
436
|
-
|
|
437
|
-
export { e as DEFAULT_MAX_DER_DEPTH, assertDerMaxDepth, bitString, bmpString, bool, concatBytes, encodeLength, explicitContext, generalizedTime, ia5Bytes, ia5String, implicitConstructedContext, implicitPrimitiveContext, integer, integerFromNumber, nullValue, objectIdentifier, octetString, optionalBytesEqual, printableString, readElement, readRootElement, readSequenceChildren, sequence, setOf, time, tlv, universalString, utcTime, utf8String };
|
|
516
|
+
export { t as DEFAULT_MAX_DER_DEPTH, assertDerMaxDepth, bitString, bmpString, bool, concatBytes, encodeLength, enumeratedFromNumber, explicitContext, generalizedTime, hasLoneSurrogate, ia5Bytes, ia5String, implicitConstructedContext, implicitPrimitiveContext, integer, integerFromNumber, nullValue, objectIdentifier, octetString, optionalBytesEqual, printableString, readElement, readIdentifier, readRootElement, readSequenceChildren, sequence, setOf, time, tlv, universalString, utcTime, utf8String, visibleString, walkDerTree };
|
|
438
517
|
|
|
439
518
|
//# sourceMappingURL=der.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"der.js","names":[],"sources":["../../../src/internal/asn1/der.ts"],"sourcesContent":["/**\n * Low-level DER encoding and reading helpers shared across the library.\n *\n * These utilities build and traverse ASN.1 TLV (tag-length-value) structures.\n *\n * @module\n */\n\n/**\n * Maximum nesting depth allowed when recursively walking a DER structure.\n *\n * Guards against stack exhaustion from pathologically nested input.\n */\nexport const DEFAULT_MAX_DER_DEPTH = 64;\n\n/**\n * Produces the DER length octets for a given byte count.\n *\n * Values < 128 use the short form (one octet);\n * larger values use the long form (leading octet encodes the number of subsequent length bytes).\n */\nexport function encodeLength(length: number): Uint8Array {\n\tassertNonNegativeSafeInteger(length, 'DER length');\n\tif (length < 128) {\n\t\treturn Uint8Array.of(length);\n\t}\n\n\tconst parts = encodeBase256(length);\n\treturn Uint8Array.of(0x80 | parts.length, ...parts);\n}\n\n/** Concatenates multiple byte arrays into a single {@linkcode Uint8Array}. */\nexport function concatBytes(parts: readonly Uint8Array[]): Uint8Array {\n\tconst length = parts.reduce((sum, part) => sum + part.length, 0);\n\tconst out = new Uint8Array(length);\n\tlet offset = 0;\n\tfor (const part of parts) {\n\t\tout.set(part, offset);\n\t\toffset += part.length;\n\t}\n\treturn out;\n}\n\n/** Compares two optional byte arrays; two absent values are equal. */\nexport function optionalBytesEqual(\n\tleft: Uint8Array | undefined,\n\tright: Uint8Array | undefined,\n): boolean {\n\tif (left === undefined || right === undefined) {\n\t\treturn left === right;\n\t}\n\tif (left.length !== right.length) {\n\t\treturn false;\n\t}\n\tfor (let index = 0; index < left.length; index += 1) {\n\t\tif (left[index] !== right[index]) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/**\n * Builds a complete DER TLV (tag-length-value) element:\n *\n * - one tag octet,\n * - the DER-encoded length, then\n * - the raw value bytes.\n */\nexport function tlv(tag: number, value: Uint8Array): Uint8Array {\n\tassertSingleOctetDerTag(tag);\n\treturn concatBytes([Uint8Array.of(tag), encodeLength(value.length), value]);\n}\n\n/** Wraps concatenated children in a SEQUENCE (tag `0x30`). */\nexport function sequence(parts: readonly Uint8Array[]): Uint8Array {\n\treturn tlv(0x30, concatBytes(parts));\n}\n\n/**\n * Wraps children in a SET (tag `0x31`) after DER-sorting them lexicographically by encoded bytes,\n * as required by {@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690} DER.\n */\nexport function setOf(parts: readonly Uint8Array[]): Uint8Array {\n\tconst sorted = parts.slice().sort((a, b) => {\n\t\tconst len = Math.min(a.length, b.length);\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tconst diff = (a[i] ?? 0) - (b[i] ?? 0);\n\t\t\tif (diff !== 0) return diff;\n\t\t}\n\t\treturn a.length - b.length;\n\t});\n\treturn tlv(0x31, concatBytes(sorted));\n}\n\n/**\n * Wraps a value in an explicit context-specific constructed tag (`0xa0 + tag`).\n *\n * Used for optional SEQUENCE fields tagged with `[tag] EXPLICIT`.\n */\nexport function explicitContext(tag: number, value: Uint8Array): Uint8Array {\n\tassertContextSpecificTagNumber(tag);\n\treturn tlv(0xa0 + tag, value);\n}\n\n/**\n * Wraps a value in an implicit context-specific constructed tag (`0xa0 + tag`).\n *\n * Used for `[tag] IMPLICIT` fields whose underlying type is constructed (e.g. SEQUENCE).\n */\nexport function implicitConstructedContext(tag: number, value: Uint8Array): Uint8Array {\n\tassertContextSpecificTagNumber(tag);\n\treturn tlv(0xa0 + tag, value);\n}\n\n/**\n * Wraps a value in an implicit context-specific primitive tag (`0x80 + tag`).\n *\n * Used for `[tag] IMPLICIT` fields whose underlying type is primitive (e.g. OCTET STRING).\n */\nexport function implicitPrimitiveContext(tag: number, value: Uint8Array): Uint8Array {\n\tassertContextSpecificTagNumber(tag);\n\treturn tlv(0x80 + tag, value);\n}\n\n/**\n * Encodes raw big-endian bytes as a DER INTEGER (tag `0x02`).\n *\n * Strips leading zero bytes for minimal encoding and prepends a zero byte when the high bit is set\n * to keep the value non-negative.\n */\nexport function integer(bytes: Uint8Array): Uint8Array {\n\tif (bytes.length === 0) {\n\t\treturn tlv(0x02, Uint8Array.of(0));\n\t}\n\n\tlet start = 0;\n\twhile (start < bytes.length - 1 && bytes[start] === 0) {\n\t\tstart += 1;\n\t}\n\n\tconst value = bytes.slice(start);\n\tif ((value[0] ?? 0) >= 0x80) {\n\t\treturn tlv(0x02, concatBytes([Uint8Array.of(0), value]));\n\t}\n\n\treturn tlv(0x02, value);\n}\n\n/**\n * Encodes a non-negative JavaScript `number` as a DER INTEGER.\n *\n * @throws if the value is not a non-negative safe integer.\n */\nexport function integerFromNumber(value: number): Uint8Array {\n\tif (!Number.isSafeInteger(value) || value < 0) {\n\t\tthrow new Error('INTEGER must be a non-negative safe integer');\n\t}\n\n\tif (value === 0) {\n\t\treturn integer(Uint8Array.of(0));\n\t}\n\n\treturn integer(Uint8Array.from(encodeBase256(value)));\n}\n\n/** Encodes a DER BOOLEAN (tag `0x01`): `true` → `0xff`, `false` → `0x00`. */\nexport function bool(value: boolean): Uint8Array {\n\treturn tlv(0x01, Uint8Array.of(value ? 0xff : 0x00));\n}\n\n/** Produces a DER NULL element (tag `0x05`, zero-length value). */\nexport function nullValue(): Uint8Array {\n\treturn tlv(0x05, new Uint8Array());\n}\n\n/** Wraps raw bytes in an OCTET STRING element (tag `0x04`). */\nexport function octetString(value: Uint8Array): Uint8Array {\n\treturn tlv(0x04, value);\n}\n\n/**\n * Encodes a DER BIT STRING (tag `0x03`).\n *\n * The value is prefixed with a single octet indicating how many trailing bits in the last byte are unused.\n *\n * @param unusedBits Number of unused trailing bits (0–7). Defaults to 0.\n */\nexport function bitString(value: Uint8Array, unusedBits = 0): Uint8Array {\n\tif (unusedBits < 0 || unusedBits > 7) {\n\t\tthrow new Error('unusedBits must be between 0 and 7');\n\t}\n\tif (value.length === 0 && unusedBits !== 0) {\n\t\tthrow new Error('unusedBits must be 0 when value is empty');\n\t}\n\tif (value.length > 0 && unusedBits > 0) {\n\t\tconst lastByte = value[value.length - 1] ?? 0;\n\t\tif ((lastByte & ((1 << unusedBits) - 1)) !== 0) {\n\t\t\tthrow new Error('unused bits in the last byte must be zero');\n\t\t}\n\t}\n\treturn tlv(0x03, concatBytes([Uint8Array.of(unusedBits), value]));\n}\n\n/** Encodes a DER UTF8String (tag `0x0c`). */\nexport function utf8String(value: string): Uint8Array {\n\treturn tlv(0x0c, new TextEncoder().encode(value));\n}\n\n/**\n * Encodes a DER PrintableString (tag `0x13`).\n *\n * @throws if the input contains characters outside the ITU-T X.680 §41.4 Table 10 PrintableString set.\n */\nexport function printableString(value: string): Uint8Array {\n\tif (!/^[A-Za-z0-9 '()+,\\-./:=?]*$/.test(value)) {\n\t\tthrow new Error('Invalid PrintableString: contains characters outside the allowed set');\n\t}\n\treturn tlv(0x13, new TextEncoder().encode(value));\n}\n\n/** Validates a string is ASCII (IA5) and returns its content bytes, without a tag. */\nexport function ia5Bytes(value: string): Uint8Array {\n\tfor (let i = 0; i < value.length; i++) {\n\t\tif (value.charCodeAt(i) > 0x7f) {\n\t\t\tthrow new Error('Invalid IA5String: contains non-ASCII characters');\n\t\t}\n\t}\n\treturn new TextEncoder().encode(value);\n}\n\n/**\n * Encodes a DER IA5String (tag `0x16`).\n *\n * @throws if the input contains any non-ASCII character (code point > 0x7f).\n */\nexport function ia5String(value: string): Uint8Array {\n\treturn tlv(0x16, ia5Bytes(value));\n}\n\n/**\n * Encodes a DER BMPString (tag `0x1e`) as big-endian UTF-16.\n *\n * @throws on lone surrogates and on code points above the Basic Multilingual Plane.\n */\nexport function bmpString(value: string): Uint8Array {\n\tconst units: number[] = [];\n\tfor (const character of value) {\n\t\tconst codePoint = character.codePointAt(0) ?? 0;\n\t\tif (codePoint > 0xffff) {\n\t\t\tthrow new Error('Invalid BMPString: code point above the Basic Multilingual Plane');\n\t\t}\n\t\tif (codePoint >= 0xd800 && codePoint <= 0xdfff) {\n\t\t\tthrow new Error('Invalid BMPString: lone surrogate');\n\t\t}\n\t\tunits.push((codePoint >> 8) & 0xff, codePoint & 0xff);\n\t}\n\treturn tlv(0x1e, Uint8Array.from(units));\n}\n\n/**\n * Encodes a DER UniversalString (tag `0x1c`) as big-endian UTF-32.\n *\n * @throws on lone surrogates.\n */\nexport function universalString(value: string): Uint8Array {\n\tconst bytes: number[] = [];\n\tfor (const character of value) {\n\t\tconst codePoint = character.codePointAt(0) ?? 0;\n\t\tif (codePoint >= 0xd800 && codePoint <= 0xdfff) {\n\t\t\tthrow new Error('Invalid UniversalString: lone surrogate');\n\t\t}\n\t\tbytes.push(\n\t\t\t(codePoint >> 24) & 0xff,\n\t\t\t(codePoint >> 16) & 0xff,\n\t\t\t(codePoint >> 8) & 0xff,\n\t\t\tcodePoint & 0xff,\n\t\t);\n\t}\n\treturn tlv(0x1c, Uint8Array.from(bytes));\n}\n\n/** Encode a non-negative integer as a base-128 sub-identifier ({@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690 §8.19.2}). */\nfunction encodeBase128(value: bigint): number[] {\n\tconst encoded: number[] = [Number(value & 0x7fn)];\n\tlet current = value >> 7n;\n\twhile (current > 0n) {\n\t\tencoded.unshift(0x80 | Number(current & 0x7fn));\n\t\tcurrent >>= 7n;\n\t}\n\treturn encoded;\n}\n\n/**\n * Encodes a dotted-decimal OID string as a DER OBJECT IDENTIFIER (tag `0x06`).\n *\n * Validates arc constraints per X.660 §7.6: the root arc must be 0–2, and under\n * roots 0 and 1 the second arc must be 0–39. X.690 §8.19.4 defines the `(X*40)+Y`\n * packing of the first two arcs into one subidentifier.\\\n * Sub-identifiers are encoded with base-128 continuation.\n */\nexport function objectIdentifier(oid: string): Uint8Array {\n\tconst digitPattern = /^\\d+$/;\n\tconst segments = oid.split('.').map((segment) => {\n\t\tif (!digitPattern.test(segment)) {\n\t\t\tthrow new Error(`Invalid OID segment: ${segment}`);\n\t\t}\n\t\treturn BigInt(segment);\n\t});\n\tif (segments.length < 2) {\n\t\tthrow new Error(`Invalid OID: ${oid}`);\n\t}\n\n\tconst [first, second, ...rest] = segments;\n\tif (first === undefined || second === undefined) {\n\t\tthrow new Error(`Invalid OID: ${oid}`);\n\t}\n\tif (first !== 0n && first !== 1n && first !== 2n) {\n\t\tthrow new Error(`Invalid OID first arc: ${first}`);\n\t}\n\tif ((first === 0n || first === 1n) && second >= 40n) {\n\t\tthrow new Error(`Invalid OID second arc: ${second} (must be < 40 when first arc is ${first})`);\n\t}\n\tconst bytes: number[] = encodeBase128(first * 40n + second);\n\tfor (const segment of rest) {\n\t\tbytes.push(...encodeBase128(segment));\n\t}\n\n\treturn tlv(0x06, Uint8Array.from(bytes));\n}\n\n/**\n * Encodes a `Date` as a DER UTCTime (tag `0x17`), format `YYMMDDHHMMSSZ`.\n *\n * Only the two-digit year is stored; suitable for dates in 1950–2049.\n */\nexport function utcTime(date: Date): Uint8Array {\n\tassertValidDate(date, 'UTCTime');\n\tconst year = date.getUTCFullYear();\n\tif (year < 1950 || year > 2049) {\n\t\tthrow new RangeError('UTCTime year must be between 1950 and 2049');\n\t}\n\tconst value = `${[\n\t\ttwoDigits(year % 100),\n\t\ttwoDigits(date.getUTCMonth() + 1),\n\t\ttwoDigits(date.getUTCDate()),\n\t\ttwoDigits(date.getUTCHours()),\n\t\ttwoDigits(date.getUTCMinutes()),\n\t\ttwoDigits(date.getUTCSeconds()),\n\t].join('')}Z`;\n\treturn tlv(0x17, new TextEncoder().encode(value));\n}\n\n/**\n * Encodes a {@linkcode Date} as a DER GeneralizedTime (tag `0x18`), format `YYYYMMDDHHMMSSZ`.\n *\n * Uses a four-digit year; required for dates outside the 1950–2049 range.\n */\nexport function generalizedTime(date: Date): Uint8Array {\n\tassertValidDate(date, 'GeneralizedTime');\n\tconst year = date.getUTCFullYear();\n\tif (year < 0 || year > 9999) {\n\t\tthrow new RangeError('GeneralizedTime year must be between 0 and 9999');\n\t}\n\tconst value = `${[\n\t\tString(year).padStart(4, '0'),\n\t\ttwoDigits(date.getUTCMonth() + 1),\n\t\ttwoDigits(date.getUTCDate()),\n\t\ttwoDigits(date.getUTCHours()),\n\t\ttwoDigits(date.getUTCMinutes()),\n\t\ttwoDigits(date.getUTCSeconds()),\n\t].join('')}Z`;\n\treturn tlv(0x18, new TextEncoder().encode(value));\n}\n\n/**\n * Encodes a {@linkcode Date} as the appropriate DER time type per RFC 5280.\n *\n * - {@linkcode utcTime} for 1950–2049\n * - {@linkcode generalizedTime} otherwise\n */\nexport function time(date: Date): Uint8Array {\n\tif (date.getUTCFullYear() >= 2050 || date.getUTCFullYear() < 1950) {\n\t\treturn generalizedTime(date);\n\t}\n\treturn utcTime(date);\n}\n\n/** Zero-pads a number to two digits for time encoding. */\nfunction twoDigits(value: number): string {\n\treturn String(value).padStart(2, '0');\n}\n\n/** Encodes a non-negative integer as big-endian base-256 octets. */\nfunction encodeBase256(value: number): readonly number[] {\n\tassertNonNegativeSafeInteger(value, 'DER integer');\n\tconst parts: number[] = [];\n\tlet current = value;\n\twhile (current > 0) {\n\t\tparts.unshift(current & 0xff);\n\t\tcurrent = Math.floor(current / 256);\n\t}\n\treturn parts;\n}\n\n/** A single parsed ASN.1 TLV element with byte-range metadata. */\nexport interface DerElement {\n\t/** ASN.1 tag byte (e.g. `0x30` for SEQUENCE, `0x02` for INTEGER). */\n\treadonly tag: number;\n\t/** Number of bytes occupied by the tag + length octets. */\n\treadonly headerLength: number;\n\t/** Byte length of the value portion (excluding tag and length octets). */\n\treadonly length: number;\n\t/** Byte offset where the value portion begins in the source buffer. */\n\treadonly start: number;\n\t/** Byte offset one past the last value byte. Equals the next element's header offset. */\n\treadonly end: number;\n\t/** The raw value bytes (slice of the source buffer). */\n\treadonly value: Uint8Array;\n}\n\n/** Options for {@linkcode readSequenceChildren}. */\nexport interface ReadSequenceChildrenOptions {\n\t/** Maximum nesting depth for the DER depth check. @default {@linkcode DEFAULT_MAX_DER_DEPTH}. */\n\treadonly maxDepth?: number;\n\t/** Constructed tags whose inner bytes may not parse as valid TLV children (e.g. opaque extension values). */\n\treadonly allowOpaqueConstructedTags?: readonly number[];\n}\n\n/** Options for {@linkcode readRootElement}. */\nexport interface ReadRootElementOptions {\n\t/** Maximum nesting depth for the DER depth check. @default {@linkcode DEFAULT_MAX_DER_DEPTH}. */\n\treadonly maxDepth?: number;\n\t/** Constructed tags whose inner bytes may not parse as valid TLV children (e.g. opaque extension values). */\n\treadonly allowOpaqueConstructedTags?: readonly number[];\n}\n\n/**\n * Reads one TLV element from {@linkcode bytes} starting at {@linkcode offset}.\n *\n * Parses the tag byte, decodes the DER length octets, and slices out the value bytes.\n *\n * @throws on truncated input, indefinite lengths, and non-minimal length encodings.\n * @param offset Byte position of the tag octet. Defaults to 0.\n */\nexport function readElement(bytes: Uint8Array, offset = 0): DerElement {\n\tconst tag = bytes[offset];\n\tif (tag === undefined) {\n\t\tthrow new Error('Unexpected end of DER input');\n\t}\n\tif ((tag & 0x1f) === 0x1f) {\n\t\tthrow new Error('High-tag-number DER form is not supported');\n\t}\n\tconst lengthByte = bytes[offset + 1];\n\tif (lengthByte === undefined) {\n\t\tthrow new Error('Unexpected end of DER input');\n\t}\n\n\tconst { headerLength, length } = readDerLength(bytes, offset, lengthByte);\n\n\tconst start = offset + headerLength;\n\tconst end = start + length;\n\tif (end > bytes.length) {\n\t\tthrow new Error('DER element exceeds input length');\n\t}\n\n\treturn {\n\t\ttag,\n\t\theaderLength,\n\t\tlength,\n\t\tstart,\n\t\tend,\n\t\tvalue: bytes.slice(start, end),\n\t};\n}\n\n/** Decodes and validates the definite-length field of a DER element. */\nfunction readDerLength(\n\tbytes: Uint8Array,\n\toffset: number,\n\tlengthByte: number,\n): { readonly headerLength: number; readonly length: number } {\n\tif ((lengthByte & 0x80) === 0) {\n\t\treturn { headerLength: 2, length: lengthByte };\n\t}\n\tconst octets = lengthByte & 0x7f;\n\tif (octets === 0) {\n\t\tthrow new Error('Indefinite lengths are not supported');\n\t}\n\tconst firstLengthOctet = bytes[offset + 2];\n\tif (firstLengthOctet === undefined) {\n\t\tthrow new Error('Unexpected end of DER input');\n\t}\n\tif (firstLengthOctet === 0) {\n\t\tthrow new Error('Non-minimal DER length encoding');\n\t}\n\tconst length = readLongFormDerLength(bytes, offset, octets);\n\tif (length < 128) {\n\t\tthrow new Error('Non-minimal DER length encoding');\n\t}\n\treturn { headerLength: 2 + octets, length };\n}\n\nfunction readLongFormDerLength(bytes: Uint8Array, offset: number, octets: number): number {\n\tlet length = 0;\n\tfor (let index = 0; index < octets; index += 1) {\n\t\tconst next = bytes[offset + 2 + index];\n\t\tif (next === undefined) {\n\t\t\tthrow new Error('Unexpected end of DER input');\n\t\t}\n\t\tif (length > Math.floor((Number.MAX_SAFE_INTEGER - next) / 256)) {\n\t\t\tthrow new Error('DER length exceeds safe integer range');\n\t\t}\n\t\tlength = length * 256 + next;\n\t}\n\treturn length;\n}\n\n/**\n * Walks the full DER tree rooted in {@linkcode bytes}.\n *\n * Constructed tags with content that cannot be parsed as valid children are tolerated when listed in {@linkcode options | allowOpaqueConstructedTags}.\n *\n * @throws if nesting exceeds {@linkcode maxDepth}.\n */\nexport function assertDerMaxDepth(\n\tbytes: Uint8Array,\n\tmaxDepth: number = DEFAULT_MAX_DER_DEPTH,\n\toptions?: {\n\t\t/** Constructed tags whose inner bytes may not parse as valid TLV children. */\n\t\treadonly allowOpaqueConstructedTags?: readonly number[];\n\t},\n): void {\n\tif (!Number.isSafeInteger(maxDepth) || maxDepth < 1) {\n\t\tthrow new Error('DER max depth must be a positive safe integer');\n\t}\n\tconst root = readElement(bytes, 0);\n\tif (root.end !== bytes.length) {\n\t\tthrow new Error('Trailing data after DER element');\n\t}\n\tconst stack: {\n\t\treadonly element: DerElement;\n\t\treadonly depth: number;\n\t}[] = [{ element: root, depth: 1 }];\n\twhile (stack.length > 0) {\n\t\tconst current = stack.pop();\n\t\tif (current === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (current.depth > maxDepth) {\n\t\t\tthrow new Error(`DER exceeds max depth of ${maxDepth}`);\n\t\t}\n\t\tif ((current.element.tag & 0x20) === 0) {\n\t\t\tcontinue;\n\t\t}\n\t\tpushDerChildren(bytes, current, stack, options);\n\t}\n}\n\nfunction pushDerChildren(\n\tbytes: Uint8Array,\n\tcurrent: { readonly element: DerElement; readonly depth: number },\n\tstack: { readonly element: DerElement; readonly depth: number }[],\n\toptions?: {\n\t\treadonly allowOpaqueConstructedTags?: readonly number[];\n\t},\n): void {\n\tlet offset = current.element.start;\n\tlet treatedAsOpaqueLeaf = false;\n\twhile (offset < current.element.end) {\n\t\tconst child = readDerChildOrOpaque(bytes, current.element, offset, options);\n\t\tif (child === undefined) {\n\t\t\ttreatedAsOpaqueLeaf = true;\n\t\t\toffset = current.element.end;\n\t\t\tbreak;\n\t\t}\n\t\tstack.push({ element: child, depth: current.depth + 1 });\n\t\toffset = child.end;\n\t}\n\tif (!treatedAsOpaqueLeaf && offset !== current.element.end) {\n\t\tthrow new Error('Malformed DER container');\n\t}\n}\n\nfunction readDerChildOrOpaque(\n\tbytes: Uint8Array,\n\tparent: DerElement,\n\toffset: number,\n\toptions?: {\n\t\treadonly allowOpaqueConstructedTags?: readonly number[];\n\t},\n): DerElement | undefined {\n\tlet child: DerElement;\n\ttry {\n\t\tchild = readElement(bytes, offset);\n\t} catch (error) {\n\t\tif (canTreatAsOpaqueLeaf(parent, offset, options)) return undefined;\n\t\tthrow error;\n\t}\n\tif (child.end <= parent.end) {\n\t\treturn child;\n\t}\n\tif (canTreatAsOpaqueLeaf(parent, offset, options)) return undefined;\n\tthrow new Error('DER child exceeds parent length');\n}\n\n/**\n * Reads the single top-level TLV element from {@linkcode bytes}.\n *\n * Optionally validates nesting depth.\n *\n * @throws if there is trailing data after the element.\n */\nexport function readRootElement(bytes: Uint8Array, options?: ReadRootElementOptions): DerElement {\n\tconst maxDepth = options?.maxDepth ?? DEFAULT_MAX_DER_DEPTH;\n\tassertDerMaxDepth(bytes, maxDepth, options);\n\tconst element = readElement(bytes, 0);\n\tif (element.end !== bytes.length) {\n\t\tthrow new Error('Trailing data after DER element');\n\t}\n\treturn element;\n}\n\n/**\n * Reads a DER-encoded SEQUENCE from {@linkcode bytes} and returns its direct children.\n *\n * @throws if the root element is not a SEQUENCE or if child boundaries are inconsistent.\n */\nexport function readSequenceChildren(\n\tbytes: Uint8Array,\n\toptions?: ReadSequenceChildrenOptions,\n): DerElement[] {\n\tconst sequenceElement = readRootElement(bytes, options);\n\tif (sequenceElement.tag !== 0x30) {\n\t\tthrow new Error('Expected SEQUENCE');\n\t}\n\n\tconst children: DerElement[] = [];\n\tlet offset = sequenceElement.start;\n\twhile (offset < sequenceElement.end) {\n\t\tconst element = readElement(bytes, offset);\n\t\tif (element.end > sequenceElement.end) {\n\t\t\tthrow new Error('DER child exceeds parent length');\n\t\t}\n\t\tchildren.push(element);\n\t\toffset = element.end;\n\t}\n\tif (offset !== sequenceElement.end) {\n\t\tthrow new Error('Malformed DER sequence');\n\t}\n\treturn children;\n}\n\n/** @throws if {@linkcode value} is not a non-negative safe integer. */\nfunction assertNonNegativeSafeInteger(value: number, label: string): void {\n\tif (!Number.isSafeInteger(value) || value < 0) {\n\t\tthrow new Error(`${label} must be a non-negative safe integer`);\n\t}\n}\n\nfunction assertSingleOctetDerTag(tag: number): void {\n\tif (!Number.isSafeInteger(tag) || tag < 0 || tag > 0xff) {\n\t\tthrow new RangeError('DER tag octet must be between 0 and 255');\n\t}\n\tif ((tag & 0x1f) === 0x1f) {\n\t\tthrow new Error('High-tag-number DER tags are not supported');\n\t}\n}\n\nfunction assertContextSpecificTagNumber(tag: number): void {\n\tif (!Number.isSafeInteger(tag) || tag < 0 || tag >= 31) {\n\t\tthrow new RangeError('Context-specific tag number must be between 0 and 30');\n\t}\n}\n\nfunction assertValidDate(date: Date, label: 'UTCTime' | 'GeneralizedTime'): void {\n\tif (Number.isNaN(date.getTime())) {\n\t\tthrow new RangeError(`${label} requires a valid Date`);\n\t}\n}\n\n/**\n * @returns `true` when a constructed element's content should be treated as an opaque leaf (not recursed into)\n * because its tag appears in the {@linkcode options | allowOpaqueConstructedTags} list and the offset is at the element start.\n */\nfunction canTreatAsOpaqueLeaf(\n\telement: DerElement,\n\toffset: number,\n\toptions?: {\n\t\t/** Constructed tags whose inner bytes may not parse as valid TLV children. */\n\t\treadonly allowOpaqueConstructedTags?: readonly number[];\n\t},\n): boolean {\n\treturn (\n\t\toffset === element.start && options?.allowOpaqueConstructedTags?.includes(element.tag) === true\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,IAAwB;;;;;;;AAQrC,SAAgB,aAAa,GAA4B;CAExD,IADA,6BAA6B,GAAQ,YAAY,GAC7C,IAAS,KACZ,OAAO,WAAW,GAAG,CAAM;CAG5B,IAAM,IAAQ,cAAc,CAAM;CAClC,OAAO,WAAW,GAAG,MAAO,EAAM,QAAQ,GAAG,CAAK;AACnD;;AAGA,SAAgB,YAAY,GAA0C;CACrE,IAAM,IAAS,EAAM,QAAQ,GAAK,MAAS,IAAM,EAAK,QAAQ,CAAC,GACzD,IAAM,IAAI,WAAW,CAAM,GAC7B,IAAS;CACb,KAAK,IAAM,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R;;;;;;AAOA,SAAgB,qBACf,GACA,GACe;CACf,IAAM,IAAkB,gBAAgB,GAAO,CAAO;CACtD,IAAI,EAAgB,QAAQ,IAC3B,MAAU,MAAM,mBAAmB;CAGpC,IAAM,IAAyB,CAAC,GAC5B,IAAS,EAAgB;CAC7B,OAAO,IAAS,EAAgB,MAAK;EACpC,IAAM,IAAU,YAAY,GAAO,CAAM;EACzC,IAAI,EAAQ,MAAM,EAAgB,KACjC,MAAU,MAAM,iCAAiC;EAGlD,AADA,EAAS,KAAK,CAAO,GACrB,IAAS,EAAQ;CAClB;CACA,IAAI,MAAW,EAAgB,KAC9B,MAAU,MAAM,wBAAwB;CAEzC,OAAO;AACR;;AAGA,SAAS,6BAA6B,GAAe,GAAqB;CACzE,IAAI,CAAC,OAAO,cAAc,CAAK,KAAK,IAAQ,GAC3C,MAAU,MAAM,GAAG,EAAM,qCAAqC;AAEhE;AAEA,SAAS,wBAAwB,GAAmB;CACnD,IAAI,CAAC,OAAO,cAAc,CAAG,KAAK,IAAM,KAAK,IAAM,KAClD,MAAU,WAAW,yCAAyC;CAE/D,KAAK,IAAM,OAAU,IACpB,MAAU,MAAM,4CAA4C;AAE9D;AAEA,SAAS,+BAA+B,GAAmB;CAC1D,IAAI,CAAC,OAAO,cAAc,CAAG,KAAK,IAAM,KAAK,KAAO,IACnD,MAAU,WAAW,sDAAsD;AAE7E;AAEA,SAAS,gBAAgB,GAAY,GAA4C;CAChF,IAAI,OAAO,MAAM,EAAK,QAAQ,CAAC,GAC9B,MAAU,WAAW,GAAG,EAAM,uBAAuB;AAEvD;;;;;AAMA,SAAS,qBACR,GACA,GACA,GAIU;CACV,OACC,MAAW,EAAQ,SAAS,GAAS,4BAA4B,SAAS,EAAQ,GAAG,MAAM;AAE7F"}
|
|
1
|
+
{"version":3,"file":"der.js","names":["DEFAULT_MAX_DER_DEPTH","length","parts","sum","part","out","offset","left","right","index","tag","value","len","a","b","i","diff","bytes","start","unusedBits","unit","next","units","character","codePoint","OID_SUBIDENTIFIER_LIMIT","OID_SUBIDENTIFIER_MAX_DIGITS","segment","significant","throwDecodeRefusal","reversed","current","segments","oid","first","second","rest","date","year","end","tagNumber","group","identifier","lengthOffset","lengthByte","headerLength","lengthOctets","octets","firstLengthOctet","maxDepth","options","root","stack","visit","treatedAsOpaqueLeaf","child","error","parent","element","sequenceElement","children","label"],"sources":["../../../src/internal/asn1/der.ts"],"sourcesContent":["/**\n * Low-level DER encoding and reading helpers shared across the library.\n *\n * These utilities build and traverse ASN.1 TLV (tag-length-value) structures.\n *\n * @module\n */\n\nimport { throwDecodeRefusal } from '#micro509/internal/asn1/decode-refusal';\n\n/**\n * Maximum nesting depth allowed when recursively walking a DER structure.\n *\n * Guards against stack exhaustion from pathologically nested input.\n */\nexport const DEFAULT_MAX_DER_DEPTH = 64;\n\n/**\n * Produces the DER length octets for a given byte count.\n *\n * Values < 128 use the short form (one octet);\n * larger values use the long form (leading octet encodes the number of subsequent length bytes).\n */\nexport function encodeLength(length: number): Uint8Array {\n\tassertNonNegativeSafeInteger(length, 'DER length');\n\tif (length < 128) {\n\t\treturn Uint8Array.of(length);\n\t}\n\n\tconst parts = encodeBase256(length);\n\treturn Uint8Array.of(0x80 | parts.length, ...parts);\n}\n\n/** Concatenates multiple byte arrays into a single {@linkcode Uint8Array}. */\nexport function concatBytes(parts: readonly Uint8Array[]): Uint8Array {\n\tconst length = parts.reduce((sum, part) => sum + part.length, 0);\n\tconst out = new Uint8Array(length);\n\tlet offset = 0;\n\tfor (const part of parts) {\n\t\tout.set(part, offset);\n\t\toffset += part.length;\n\t}\n\treturn out;\n}\n\n/** Compares two optional byte arrays; two absent values are equal. */\nexport function optionalBytesEqual(\n\tleft: Uint8Array | undefined,\n\tright: Uint8Array | undefined,\n): boolean {\n\tif (left === undefined || right === undefined) {\n\t\treturn left === right;\n\t}\n\tif (left.length !== right.length) {\n\t\treturn false;\n\t}\n\tfor (let index = 0; index < left.length; index += 1) {\n\t\tif (left[index] !== right[index]) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/**\n * Builds a complete DER TLV (tag-length-value) element:\n *\n * - one tag octet,\n * - the DER-encoded length, then\n * - the raw value bytes.\n */\nexport function tlv(tag: number, value: Uint8Array): Uint8Array {\n\tassertSingleOctetDerTag(tag);\n\treturn concatBytes([Uint8Array.of(tag), encodeLength(value.length), value]);\n}\n\n/** Wraps concatenated children in a SEQUENCE (tag `0x30`). */\nexport function sequence(parts: readonly Uint8Array[]): Uint8Array {\n\treturn tlv(0x30, concatBytes(parts));\n}\n\n/**\n * Wraps children in a SET (tag `0x31`) after DER-sorting them lexicographically by encoded bytes,\n * as required by {@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690} DER.\n */\nexport function setOf(parts: readonly Uint8Array[]): Uint8Array {\n\tconst sorted = parts.slice().sort((a, b) => {\n\t\tconst len = Math.min(a.length, b.length);\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tconst diff = (a[i] ?? 0) - (b[i] ?? 0);\n\t\t\tif (diff !== 0) return diff;\n\t\t}\n\t\treturn a.length - b.length;\n\t});\n\treturn tlv(0x31, concatBytes(sorted));\n}\n\n/**\n * Wraps a value in an explicit context-specific constructed tag (`0xa0 + tag`).\n *\n * Used for optional SEQUENCE fields tagged with `[tag] EXPLICIT`.\n */\nexport function explicitContext(tag: number, value: Uint8Array): Uint8Array {\n\tassertContextSpecificTagNumber(tag);\n\treturn tlv(0xa0 + tag, value);\n}\n\n/**\n * Wraps a value in an implicit context-specific constructed tag (`0xa0 + tag`).\n *\n * Used for `[tag] IMPLICIT` fields whose underlying type is constructed (e.g. SEQUENCE).\n */\nexport function implicitConstructedContext(tag: number, value: Uint8Array): Uint8Array {\n\tassertContextSpecificTagNumber(tag);\n\treturn tlv(0xa0 + tag, value);\n}\n\n/**\n * Wraps a value in an implicit context-specific primitive tag (`0x80 + tag`).\n *\n * Used for `[tag] IMPLICIT` fields whose underlying type is primitive (e.g. OCTET STRING).\n */\nexport function implicitPrimitiveContext(tag: number, value: Uint8Array): Uint8Array {\n\tassertContextSpecificTagNumber(tag);\n\treturn tlv(0x80 + tag, value);\n}\n\n/**\n * Encodes raw big-endian bytes as a DER INTEGER (tag `0x02`).\n *\n * Strips leading zero bytes for minimal encoding and prepends a zero byte when the high bit is set\n * to keep the value non-negative.\n */\nexport function integer(bytes: Uint8Array): Uint8Array {\n\tif (bytes.length === 0) {\n\t\treturn tlv(0x02, Uint8Array.of(0));\n\t}\n\n\tlet start = 0;\n\twhile (start < bytes.length - 1 && bytes[start] === 0) {\n\t\tstart += 1;\n\t}\n\n\tconst value = bytes.slice(start);\n\tif ((value[0] ?? 0) >= 0x80) {\n\t\treturn tlv(0x02, concatBytes([Uint8Array.of(0), value]));\n\t}\n\n\treturn tlv(0x02, value);\n}\n\n/**\n * Encodes a non-negative JavaScript `number` as a DER INTEGER.\n *\n * @throws if the value is not a non-negative safe integer.\n */\nexport function integerFromNumber(value: number): Uint8Array {\n\tif (!Number.isSafeInteger(value) || value < 0) {\n\t\tthrow new Error('INTEGER must be a non-negative safe integer');\n\t}\n\n\tif (value === 0) {\n\t\treturn integer(Uint8Array.of(0));\n\t}\n\n\treturn integer(Uint8Array.from(encodeBase256(value)));\n}\n\n/** Encodes a DER ENUMERATED (tag `0x0a`) from a non-negative safe integer. */\nexport function enumeratedFromNumber(value: number): Uint8Array {\n\treturn concatBytes([Uint8Array.of(0x0a), integerFromNumber(value).subarray(1)]);\n}\n\n/** Encodes a DER BOOLEAN (tag `0x01`): `true` → `0xff`, `false` → `0x00`. */\nexport function bool(value: boolean): Uint8Array {\n\treturn tlv(0x01, Uint8Array.of(value ? 0xff : 0x00));\n}\n\n/** Produces a DER NULL element (tag `0x05`, zero-length value). */\nexport function nullValue(): Uint8Array {\n\treturn tlv(0x05, new Uint8Array());\n}\n\n/** Wraps raw bytes in an OCTET STRING element (tag `0x04`). */\nexport function octetString(value: Uint8Array): Uint8Array {\n\treturn tlv(0x04, value);\n}\n\n/**\n * Encodes a DER BIT STRING (tag `0x03`).\n *\n * The value is prefixed with a single octet indicating how many trailing bits in the last byte are unused.\n *\n * @param unusedBits Number of unused trailing bits (0–7). Defaults to 0.\n */\nexport function bitString(value: Uint8Array, unusedBits = 0): Uint8Array {\n\tif (unusedBits < 0 || unusedBits > 7) {\n\t\tthrow new Error('unusedBits must be between 0 and 7');\n\t}\n\tif (value.length === 0 && unusedBits !== 0) {\n\t\tthrow new Error('unusedBits must be 0 when value is empty');\n\t}\n\tif (value.length > 0 && unusedBits > 0) {\n\t\tconst lastByte = value[value.length - 1] ?? 0;\n\t\tif ((lastByte & ((1 << unusedBits) - 1)) !== 0) {\n\t\t\tthrow new Error('unused bits in the last byte must be zero');\n\t\t}\n\t}\n\treturn tlv(0x03, concatBytes([Uint8Array.of(unusedBits), value]));\n}\n\nexport function hasLoneSurrogate(value: string): boolean {\n\tfor (let index = 0; index < value.length; index += 1) {\n\t\tconst unit = value.charCodeAt(index);\n\t\tif (unit >= 0xd800 && unit <= 0xdbff) {\n\t\t\tconst next = value.charCodeAt(index + 1);\n\t\t\tif (next >= 0xdc00 && next <= 0xdfff) {\n\t\t\t\tindex += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tif (unit >= 0xdc00 && unit <= 0xdfff) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Encodes a DER UTF8String (tag `0x0c`).\n *\n * @throws on a lone surrogate, which has no UTF-8 encoding.\n */\nexport function utf8String(value: string): Uint8Array {\n\tif (hasLoneSurrogate(value)) {\n\t\tthrow new Error('Invalid UTF8String: lone surrogate');\n\t}\n\treturn tlv(0x0c, new TextEncoder().encode(value));\n}\n\n/**\n * Encodes a DER PrintableString (tag `0x13`).\n *\n * @throws if the input contains characters outside the ITU-T X.680 §41.4 Table 10 PrintableString set.\n */\nexport function printableString(value: string): Uint8Array {\n\tif (!/^[A-Za-z0-9 '()+,\\-./:=?]*$/.test(value)) {\n\t\tthrow new Error('Invalid PrintableString: contains characters outside the allowed set');\n\t}\n\treturn tlv(0x13, new TextEncoder().encode(value));\n}\n\n/**\n * Encodes a DER VisibleString (tag `0x1a`).\n *\n * @throws if the input contains a character outside the printable ASCII range 0x20 to 0x7e.\n */\nexport function visibleString(value: string): Uint8Array {\n\tif (!/^[\\x20-\\x7e]*$/.test(value)) {\n\t\tthrow new Error('Invalid VisibleString: contains characters outside 0x20 to 0x7e');\n\t}\n\treturn tlv(0x1a, new TextEncoder().encode(value));\n}\n\n/** Validates a string is ASCII (IA5) and returns its content bytes, without a tag. */\nexport function ia5Bytes(value: string): Uint8Array {\n\tfor (let i = 0; i < value.length; i++) {\n\t\tif (value.charCodeAt(i) > 0x7f) {\n\t\t\tthrow new Error('Invalid IA5String: contains non-ASCII characters');\n\t\t}\n\t}\n\treturn new TextEncoder().encode(value);\n}\n\n/**\n * Encodes a DER IA5String (tag `0x16`).\n *\n * @throws if the input contains any non-ASCII character (code point > 0x7f).\n */\nexport function ia5String(value: string): Uint8Array {\n\treturn tlv(0x16, ia5Bytes(value));\n}\n\n/**\n * Encodes a DER BMPString (tag `0x1e`) as big-endian UTF-16.\n *\n * @throws on lone surrogates, on U+FFFE and U+FFFF, which X.680 §41.15 leaves\n * out of BMPString, and on code points above the Basic Multilingual Plane.\n */\nexport function bmpString(value: string): Uint8Array {\n\tconst units: number[] = [];\n\tfor (const character of value) {\n\t\tconst codePoint = character.codePointAt(0) ?? 0;\n\t\tif (codePoint > 0xffff) {\n\t\t\tthrow new Error('Invalid BMPString: code point above the Basic Multilingual Plane');\n\t\t}\n\t\tif (codePoint >= 0xd800 && codePoint <= 0xdfff) {\n\t\t\tthrow new Error('Invalid BMPString: lone surrogate');\n\t\t}\n\t\tif (codePoint >= 0xfffe) {\n\t\t\tthrow new Error('Invalid BMPString: U+FFFE and U+FFFF are not BMPString characters');\n\t\t}\n\t\tunits.push((codePoint >> 8) & 0xff, codePoint & 0xff);\n\t}\n\treturn tlv(0x1e, Uint8Array.from(units));\n}\n\n/**\n * Encodes a DER UniversalString (tag `0x1c`) as big-endian UTF-32.\n *\n * @throws on lone surrogates.\n */\nexport function universalString(value: string): Uint8Array {\n\tconst bytes: number[] = [];\n\tfor (const character of value) {\n\t\tconst codePoint = character.codePointAt(0) ?? 0;\n\t\tif (codePoint >= 0xd800 && codePoint <= 0xdfff) {\n\t\t\tthrow new Error('Invalid UniversalString: lone surrogate');\n\t\t}\n\t\tbytes.push(\n\t\t\t(codePoint >> 24) & 0xff,\n\t\t\t(codePoint >> 16) & 0xff,\n\t\t\t(codePoint >> 8) & 0xff,\n\t\t\tcodePoint & 0xff,\n\t\t);\n\t}\n\treturn tlv(0x1c, Uint8Array.from(bytes));\n}\n\n/** micro509's bound on one OBJECT IDENTIFIER sub-identifier's base-128 encoding; X.660 §7.6 leaves arc values unbounded. */\nexport const MAX_OID_SUBIDENTIFIER_OCTETS = 64;\n\nconst OID_SUBIDENTIFIER_LIMIT = 1n << BigInt(7 * MAX_OID_SUBIDENTIFIER_OCTETS);\n\nconst OID_SUBIDENTIFIER_MAX_DIGITS = OID_SUBIDENTIFIER_LIMIT.toString().length;\n\nfunction parseOidArc(segment: string): bigint {\n\tif (!/^\\d+$/.test(segment)) {\n\t\tthrow new Error(`Invalid OID segment: ${segment}`);\n\t}\n\tconst significant = segment.replace(/^0+/, '');\n\tif (significant.length > OID_SUBIDENTIFIER_MAX_DIGITS) {\n\t\tthrowOidLimit();\n\t}\n\treturn BigInt(significant.length === 0 ? '0' : significant);\n}\n\nfunction throwOidLimit(): never {\n\treturn throwDecodeRefusal(\n\t\t'limit_exceeded',\n\t\t`OID sub-identifier exceeds ${MAX_OID_SUBIDENTIFIER_OCTETS} octets`,\n\t);\n}\n\n/** Encode a non-negative integer as a base-128 sub-identifier ({@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690 §8.19.2}). */\nfunction encodeBase128(value: bigint): number[] {\n\tif (value >= OID_SUBIDENTIFIER_LIMIT) {\n\t\tthrowOidLimit();\n\t}\n\tconst reversed: number[] = [Number(value & 0x7fn)];\n\tfor (let current = value >> 7n; current > 0n; current >>= 7n) {\n\t\treversed.push(0x80 | Number(current & 0x7fn));\n\t}\n\treturn reversed.reverse();\n}\n\n/**\n * Encodes a dotted-decimal OID string as a DER OBJECT IDENTIFIER (tag `0x06`).\n *\n * Validates arc constraints per X.660 §7.6: the root arc must be 0–2, and under\n * roots 0 and 1 the second arc must be 0–39. X.690 §8.19.4 defines the `(X*40)+Y`\n * packing of the first two arcs into one subidentifier.\\\n * Sub-identifiers are encoded with base-128 continuation.\n */\nexport function objectIdentifier(oid: string): Uint8Array {\n\tconst segments = oid.split('.').map(parseOidArc);\n\tif (segments.length < 2) {\n\t\tthrow new Error(`Invalid OID: ${oid}`);\n\t}\n\n\tconst [first, second, ...rest] = segments;\n\tif (first === undefined || second === undefined) {\n\t\tthrow new Error(`Invalid OID: ${oid}`);\n\t}\n\tif (first !== 0n && first !== 1n && first !== 2n) {\n\t\tthrow new Error(`Invalid OID first arc: ${first}`);\n\t}\n\tif ((first === 0n || first === 1n) && second >= 40n) {\n\t\tthrow new Error(`Invalid OID second arc: ${second} (must be < 40 when first arc is ${first})`);\n\t}\n\tconst bytes: number[] = encodeBase128(first * 40n + second);\n\tfor (const segment of rest) {\n\t\tbytes.push(...encodeBase128(segment));\n\t}\n\n\treturn tlv(0x06, Uint8Array.from(bytes));\n}\n\n/**\n * Encodes a `Date` as a DER UTCTime (tag `0x17`), format `YYMMDDHHMMSSZ`.\n *\n * Only the two-digit year is stored; suitable for dates in 1950–2049.\n */\nexport function utcTime(date: Date): Uint8Array {\n\tassertValidDate(date, 'UTCTime');\n\tconst year = date.getUTCFullYear();\n\tif (year < 1950 || year > 2049) {\n\t\tthrow new RangeError('UTCTime year must be between 1950 and 2049');\n\t}\n\tconst value = `${[\n\t\ttwoDigits(year % 100),\n\t\ttwoDigits(date.getUTCMonth() + 1),\n\t\ttwoDigits(date.getUTCDate()),\n\t\ttwoDigits(date.getUTCHours()),\n\t\ttwoDigits(date.getUTCMinutes()),\n\t\ttwoDigits(date.getUTCSeconds()),\n\t].join('')}Z`;\n\treturn tlv(0x17, new TextEncoder().encode(value));\n}\n\n/**\n * Encodes a {@linkcode Date} as a DER GeneralizedTime (tag `0x18`), format `YYYYMMDDHHMMSSZ`.\n *\n * Uses a four-digit year; required for dates outside the 1950–2049 range.\n */\nexport function generalizedTime(date: Date): Uint8Array {\n\tassertValidDate(date, 'GeneralizedTime');\n\tconst year = date.getUTCFullYear();\n\tif (year < 0 || year > 9999) {\n\t\tthrow new RangeError('GeneralizedTime year must be between 0 and 9999');\n\t}\n\tconst value = `${[\n\t\tString(year).padStart(4, '0'),\n\t\ttwoDigits(date.getUTCMonth() + 1),\n\t\ttwoDigits(date.getUTCDate()),\n\t\ttwoDigits(date.getUTCHours()),\n\t\ttwoDigits(date.getUTCMinutes()),\n\t\ttwoDigits(date.getUTCSeconds()),\n\t].join('')}Z`;\n\treturn tlv(0x18, new TextEncoder().encode(value));\n}\n\n/**\n * Encodes a {@linkcode Date} as the appropriate DER time type per RFC 5280.\n *\n * - {@linkcode utcTime} for 1950–2049\n * - {@linkcode generalizedTime} otherwise\n */\nexport function time(date: Date): Uint8Array {\n\tif (date.getUTCFullYear() >= 2050 || date.getUTCFullYear() < 1950) {\n\t\treturn generalizedTime(date);\n\t}\n\treturn utcTime(date);\n}\n\n/** Zero-pads a number to two digits for time encoding. */\nfunction twoDigits(value: number): string {\n\treturn String(value).padStart(2, '0');\n}\n\n/** Encodes a non-negative integer as big-endian base-256 octets. */\nfunction encodeBase256(value: number): readonly number[] {\n\tassertNonNegativeSafeInteger(value, 'DER integer');\n\tconst parts: number[] = [];\n\tlet current = value;\n\twhile (current > 0) {\n\t\tparts.unshift(current & 0xff);\n\t\tcurrent = Math.floor(current / 256);\n\t}\n\treturn parts;\n}\n\n/** A single parsed ASN.1 TLV element with byte-range metadata. */\nexport interface DerElement {\n\t/** Leading identifier octet (e.g. `0x30` for SEQUENCE, `0x02` for INTEGER, `0x9f` for any context-specific primitive tag from 31 up). */\n\treadonly tag: number;\n\t/** Tag number within the class, from the leading octet below 31 and from the subsequent identifier octets from 31 up. */\n\treadonly tagNumber: number;\n\t/** Number of bytes occupied by the identifier and length octets. */\n\treadonly headerLength: number;\n\t/** Byte length of the value portion (excluding tag and length octets). */\n\treadonly length: number;\n\t/** Byte offset where the value portion begins in the source buffer. */\n\treadonly start: number;\n\t/** Byte offset one past the last value byte. Equals the next element's header offset. */\n\treadonly end: number;\n\t/** The raw value bytes (slice of the source buffer). */\n\treadonly value: Uint8Array;\n}\n\n/** Options for {@linkcode readSequenceChildren}. */\nexport interface ReadSequenceChildrenOptions {\n\t/** Maximum nesting depth for the DER depth check. @default {@linkcode DEFAULT_MAX_DER_DEPTH}. */\n\treadonly maxDepth?: number;\n\t/** Constructed tags whose inner bytes may not parse as valid TLV children (e.g. opaque extension values). */\n\treadonly allowOpaqueConstructedTags?: readonly number[];\n}\n\n/** Options for {@linkcode readRootElement}. */\nexport interface ReadRootElementOptions {\n\t/** Maximum nesting depth for the DER depth check. @default {@linkcode DEFAULT_MAX_DER_DEPTH}. */\n\treadonly maxDepth?: number;\n\t/** Constructed tags whose inner bytes may not parse as valid TLV children (e.g. opaque extension values). */\n\treadonly allowOpaqueConstructedTags?: readonly number[];\n}\n\n/** The identifier octets of a BER or DER element. */\nexport interface Identifier {\n\t/** Leading identifier octet. */\n\treadonly tag: number;\n\t/** Tag number within the class. */\n\treadonly tagNumber: number;\n\t/** Number of identifier octets. */\n\treadonly length: number;\n}\n\n/**\n * Reads the identifier octets at {@linkcode offset} by X.690 §8.1.2, which BER\n * and DER share.\n *\n * @throws on truncated identifier octets, a high-tag-number form with a leading\n * zero group or a tag number below 31, and `limit_exceeded` on a tag number\n * above {@linkcode Number.MAX_SAFE_INTEGER}.\n */\nexport function readIdentifier(bytes: Uint8Array, offset: number): Identifier {\n\tconst tag = bytes[offset];\n\tif (tag === undefined) {\n\t\tthrow new Error('Unexpected end of identifier octets');\n\t}\n\tif ((tag & 0x1f) !== 0x1f) {\n\t\treturn { tag, tagNumber: tag & 0x1f, length: 1 };\n\t}\n\tif (bytes[offset + 1] === 0x80) {\n\t\tthrow new Error('High-tag-number form must not open with a zero group');\n\t}\n\tlet end = offset + 1;\n\twhile (((bytes[end] ?? 0) & 0x80) !== 0) {\n\t\tend += 1;\n\t}\n\tif (bytes[end] === undefined) {\n\t\tthrow new Error('Unexpected end of identifier octets');\n\t}\n\tlet tagNumber = 0;\n\tfor (let index = offset + 1; index <= end; index += 1) {\n\t\tconst group = (bytes[index] ?? 0) & 0x7f;\n\t\tif (tagNumber > (Number.MAX_SAFE_INTEGER - group) / 128) {\n\t\t\tthrowDecodeRefusal('limit_exceeded', 'Tag number exceeds Number.MAX_SAFE_INTEGER');\n\t\t}\n\t\ttagNumber = tagNumber * 128 + group;\n\t}\n\tif (tagNumber < 31) {\n\t\tthrow new Error('Tag numbers below 31 must use the low-tag-number form');\n\t}\n\treturn { tag, tagNumber, length: end - offset + 1 };\n}\n\n/**\n * Reads one TLV element from {@linkcode bytes} starting at {@linkcode offset}.\n *\n * Parses the identifier octets, decodes the DER length octets, and slices out the value bytes.\n *\n * @throws on truncated input, malformed identifier octets, indefinite lengths, and non-minimal length encodings.\n * @param offset Byte position of the leading identifier octet. Defaults to 0.\n */\nexport function readElement(bytes: Uint8Array, offset = 0): DerElement {\n\tif (bytes[offset] === undefined) {\n\t\tthrow new Error('Unexpected end of DER input');\n\t}\n\tconst identifier = readIdentifier(bytes, offset);\n\tconst lengthOffset = offset + identifier.length;\n\tconst lengthByte = bytes[lengthOffset];\n\tif (lengthByte === undefined) {\n\t\tthrow new Error('Unexpected end of DER input');\n\t}\n\n\tconst { lengthOctets, length } = readDerLength(bytes, lengthOffset, lengthByte);\n\n\tconst headerLength = identifier.length + lengthOctets;\n\tconst start = offset + headerLength;\n\tconst end = start + length;\n\tif (end > bytes.length) {\n\t\tthrow new Error('DER element exceeds input length');\n\t}\n\n\treturn {\n\t\ttag: identifier.tag,\n\t\ttagNumber: identifier.tagNumber,\n\t\theaderLength,\n\t\tlength,\n\t\tstart,\n\t\tend,\n\t\tvalue: bytes.slice(start, end),\n\t};\n}\n\n/** Decodes and validates the definite-length field of a DER element. */\nfunction readDerLength(\n\tbytes: Uint8Array,\n\tlengthOffset: number,\n\tlengthByte: number,\n): { readonly lengthOctets: number; readonly length: number } {\n\tif ((lengthByte & 0x80) === 0) {\n\t\treturn { lengthOctets: 1, length: lengthByte };\n\t}\n\tconst octets = lengthByte & 0x7f;\n\tif (octets === 0) {\n\t\tthrow new Error('Indefinite lengths are not supported');\n\t}\n\tconst firstLengthOctet = bytes[lengthOffset + 1];\n\tif (firstLengthOctet === undefined) {\n\t\tthrow new Error('Unexpected end of DER input');\n\t}\n\tif (firstLengthOctet === 0) {\n\t\tthrow new Error('Non-minimal DER length encoding');\n\t}\n\tconst length = readLongFormDerLength(bytes, lengthOffset, octets);\n\tif (length < 128) {\n\t\tthrow new Error('Non-minimal DER length encoding');\n\t}\n\treturn { lengthOctets: 1 + octets, length };\n}\n\nfunction readLongFormDerLength(bytes: Uint8Array, lengthOffset: number, octets: number): number {\n\tlet length = 0;\n\tfor (let index = 0; index < octets; index += 1) {\n\t\tconst next = bytes[lengthOffset + 1 + index];\n\t\tif (next === undefined) {\n\t\t\tthrow new Error('Unexpected end of DER input');\n\t\t}\n\t\tif (length > Math.floor((Number.MAX_SAFE_INTEGER - next) / 256)) {\n\t\t\tthrow new Error('DER length exceeds safe integer range');\n\t\t}\n\t\tlength = length * 256 + next;\n\t}\n\treturn length;\n}\n\n/**\n * Walks the full DER tree rooted in {@linkcode bytes}.\n *\n * Constructed tags with content that cannot be parsed as valid children are tolerated when listed in {@linkcode options | allowOpaqueConstructedTags}.\n *\n * @throws if nesting exceeds {@linkcode maxDepth}.\n */\nexport function assertDerMaxDepth(\n\tbytes: Uint8Array,\n\tmaxDepth: number = DEFAULT_MAX_DER_DEPTH,\n\toptions?: {\n\t\t/** Constructed tags whose inner bytes may not parse as valid TLV children. */\n\t\treadonly allowOpaqueConstructedTags?: readonly number[];\n\t},\n): void {\n\twalkDerTree(bytes, maxDepth, options, () => undefined);\n}\n\n/**\n * Walks the full DER tree rooted in {@linkcode bytes}, calling {@linkcode visit}\n * on each element before reading its children.\n *\n * @throws if the tree is malformed or nests beyond {@linkcode maxDepth}.\n */\nexport function walkDerTree(\n\tbytes: Uint8Array,\n\tmaxDepth: number,\n\toptions: { readonly allowOpaqueConstructedTags?: readonly number[] } | undefined,\n\tvisit: (element: DerElement) => void,\n): void {\n\tif (!Number.isSafeInteger(maxDepth) || maxDepth < 1) {\n\t\tthrow new Error('DER max depth must be a positive safe integer');\n\t}\n\tconst root = readElement(bytes, 0);\n\tif (root.end !== bytes.length) {\n\t\tthrow new Error('Trailing data after DER element');\n\t}\n\tconst stack: {\n\t\treadonly element: DerElement;\n\t\treadonly depth: number;\n\t}[] = [{ element: root, depth: 1 }];\n\twhile (stack.length > 0) {\n\t\tconst current = stack.pop();\n\t\tif (current === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (current.depth > maxDepth) {\n\t\t\tthrowDecodeRefusal('limit_exceeded', `DER exceeds max depth of ${maxDepth}`);\n\t\t}\n\t\tvisit(current.element);\n\t\tif ((current.element.tag & 0x20) === 0) {\n\t\t\tcontinue;\n\t\t}\n\t\tpushDerChildren(bytes, current, stack, options);\n\t}\n}\n\nfunction pushDerChildren(\n\tbytes: Uint8Array,\n\tcurrent: { readonly element: DerElement; readonly depth: number },\n\tstack: { readonly element: DerElement; readonly depth: number }[],\n\toptions?: {\n\t\treadonly allowOpaqueConstructedTags?: readonly number[];\n\t},\n): void {\n\tlet offset = current.element.start;\n\tlet treatedAsOpaqueLeaf = false;\n\twhile (offset < current.element.end) {\n\t\tconst child = readDerChildOrOpaque(bytes, current.element, offset, options);\n\t\tif (child === undefined) {\n\t\t\ttreatedAsOpaqueLeaf = true;\n\t\t\toffset = current.element.end;\n\t\t\tbreak;\n\t\t}\n\t\tstack.push({ element: child, depth: current.depth + 1 });\n\t\toffset = child.end;\n\t}\n\tif (!treatedAsOpaqueLeaf && offset !== current.element.end) {\n\t\tthrow new Error('Malformed DER container');\n\t}\n}\n\nfunction readDerChildOrOpaque(\n\tbytes: Uint8Array,\n\tparent: DerElement,\n\toffset: number,\n\toptions?: {\n\t\treadonly allowOpaqueConstructedTags?: readonly number[];\n\t},\n): DerElement | undefined {\n\tlet child: DerElement;\n\ttry {\n\t\tchild = readElement(bytes, offset);\n\t} catch (error) {\n\t\tif (canTreatAsOpaqueLeaf(parent, offset, options)) return undefined;\n\t\tthrow error;\n\t}\n\tif (child.end <= parent.end) {\n\t\treturn child;\n\t}\n\tif (canTreatAsOpaqueLeaf(parent, offset, options)) return undefined;\n\tthrow new Error('DER child exceeds parent length');\n}\n\n/**\n * Reads the single top-level TLV element from {@linkcode bytes}.\n *\n * Optionally validates nesting depth.\n *\n * @throws if there is trailing data after the element.\n */\nexport function readRootElement(bytes: Uint8Array, options?: ReadRootElementOptions): DerElement {\n\tconst maxDepth = options?.maxDepth ?? DEFAULT_MAX_DER_DEPTH;\n\tassertDerMaxDepth(bytes, maxDepth, options);\n\tconst element = readElement(bytes, 0);\n\tif (element.end !== bytes.length) {\n\t\tthrow new Error('Trailing data after DER element');\n\t}\n\treturn element;\n}\n\n/**\n * Reads a DER-encoded SEQUENCE from {@linkcode bytes} and returns its direct children.\n *\n * @throws if the root element is not a SEQUENCE or if child boundaries are inconsistent.\n */\nexport function readSequenceChildren(\n\tbytes: Uint8Array,\n\toptions?: ReadSequenceChildrenOptions,\n): DerElement[] {\n\tconst sequenceElement = readRootElement(bytes, options);\n\tif (sequenceElement.tag !== 0x30) {\n\t\tthrow new Error('Expected SEQUENCE');\n\t}\n\n\tconst children: DerElement[] = [];\n\tlet offset = sequenceElement.start;\n\twhile (offset < sequenceElement.end) {\n\t\tconst element = readElement(bytes, offset);\n\t\tif (element.end > sequenceElement.end) {\n\t\t\tthrow new Error('DER child exceeds parent length');\n\t\t}\n\t\tchildren.push(element);\n\t\toffset = element.end;\n\t}\n\tif (offset !== sequenceElement.end) {\n\t\tthrow new Error('Malformed DER sequence');\n\t}\n\treturn children;\n}\n\n/** @throws if {@linkcode value} is not a non-negative safe integer. */\nfunction assertNonNegativeSafeInteger(value: number, label: string): void {\n\tif (!Number.isSafeInteger(value) || value < 0) {\n\t\tthrow new Error(`${label} must be a non-negative safe integer`);\n\t}\n}\n\nfunction assertSingleOctetDerTag(tag: number): void {\n\tif (!Number.isSafeInteger(tag) || tag < 0 || tag > 0xff) {\n\t\tthrow new RangeError('DER tag octet must be between 0 and 255');\n\t}\n\tif ((tag & 0x1f) === 0x1f) {\n\t\tthrow new Error('High-tag-number DER tags are not supported');\n\t}\n}\n\nfunction assertContextSpecificTagNumber(tag: number): void {\n\tif (!Number.isSafeInteger(tag) || tag < 0 || tag >= 31) {\n\t\tthrow new RangeError('Context-specific tag number must be between 0 and 30');\n\t}\n}\n\nfunction assertValidDate(date: Date, label: 'UTCTime' | 'GeneralizedTime'): void {\n\tif (Number.isNaN(date.getTime())) {\n\t\tthrow new RangeError(`${label} requires a valid Date`);\n\t}\n}\n\n/**\n * @returns `true` when a constructed element's content should be treated as an opaque leaf (not recursed into)\n * because its tag appears in the {@linkcode options | allowOpaqueConstructedTags} list and the offset is at the element start.\n */\nfunction canTreatAsOpaqueLeaf(\n\telement: DerElement,\n\toffset: number,\n\toptions?: {\n\t\t/** Constructed tags whose inner bytes may not parse as valid TLV children. */\n\t\treadonly allowOpaqueConstructedTags?: readonly number[];\n\t},\n): boolean {\n\treturn (\n\t\toffset === element.start && options?.allowOpaqueConstructedTags?.includes(element.tag) === true\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,MAAaA,IAAwB;;;;;;;AAQrC,SAAgB,aAAa,GAA4B;CAExD,IADA,6BAA6BC,GAAQ,YAAY,GAC7CA,IAAS,KACZ,OAAO,WAAW,GAAGA,CAAM;CAG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B,EAAM,uBAAuB;AAEvD;;;;;AAMA,SAAS,qBACR,GACA,GACA,GAIU;CACV,OACCvD,MAAWoD,EAAQ,SAASR,GAAS,4BAA4B,SAASQ,EAAQ,GAAG,MAAM;AAE7F"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/internal/asn1/oids.json
|
|
2
2
|
var e = {
|
|
3
3
|
$schema: "./oids.schema.json",
|
|
4
4
|
ituT: {
|
|
@@ -53,7 +53,8 @@ var e = {
|
|
|
53
53
|
arc: "5",
|
|
54
54
|
oids: {
|
|
55
55
|
pbkdf2: "12",
|
|
56
|
-
pbes2: "13"
|
|
56
|
+
pbes2: "13",
|
|
57
|
+
pbmac1: "14"
|
|
57
58
|
}
|
|
58
59
|
},
|
|
59
60
|
pkcs7: {
|
|
@@ -98,7 +99,9 @@ var e = {
|
|
|
98
99
|
arc: "2",
|
|
99
100
|
oids: {
|
|
100
101
|
hmacWithSHA1: "7",
|
|
101
|
-
hmacWithSHA256: "9"
|
|
102
|
+
hmacWithSHA256: "9",
|
|
103
|
+
hmacWithSHA384: "10",
|
|
104
|
+
hmacWithSHA512: "11"
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
}
|
|
@@ -161,58 +164,85 @@ var e = {
|
|
|
161
164
|
arc: "6",
|
|
162
165
|
children: { internet: {
|
|
163
166
|
arc: "1",
|
|
164
|
-
children: {
|
|
165
|
-
|
|
166
|
-
children: { mechanisms: {
|
|
167
|
+
children: {
|
|
168
|
+
security: {
|
|
167
169
|
arc: "5",
|
|
168
|
-
children: {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
arc: "
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
170
|
+
children: {
|
|
171
|
+
mechanisms: {
|
|
172
|
+
arc: "5",
|
|
173
|
+
children: { pkix: {
|
|
174
|
+
arc: "7",
|
|
175
|
+
children: {
|
|
176
|
+
extensions: {
|
|
177
|
+
arc: "1",
|
|
178
|
+
oids: { authorityInfoAccess: "1" }
|
|
179
|
+
},
|
|
180
|
+
policyQualifiers: {
|
|
181
|
+
arc: "2",
|
|
182
|
+
oids: {
|
|
183
|
+
cpsPolicyQualifier: "1",
|
|
184
|
+
userNoticePolicyQualifier: "2"
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
extendedKeyUsage: {
|
|
188
|
+
arc: "3",
|
|
189
|
+
oids: {
|
|
190
|
+
serverAuth: "1",
|
|
191
|
+
clientAuth: "2",
|
|
192
|
+
codeSigning: "3",
|
|
193
|
+
emailProtection: "4",
|
|
194
|
+
timeStamping: "8",
|
|
195
|
+
ocspSigning: "9"
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
otherNameForms: {
|
|
199
|
+
arc: "8",
|
|
200
|
+
oids: {
|
|
201
|
+
idOnDnsSrv: "7",
|
|
202
|
+
idOnSmtpUtf8Mailbox: "9"
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
accessMethods: {
|
|
206
|
+
arc: "48",
|
|
207
|
+
oids: {
|
|
208
|
+
ocspAccessMethod: "1",
|
|
209
|
+
caIssuersAccessMethod: "2"
|
|
210
|
+
},
|
|
211
|
+
children: { ocsp: {
|
|
212
|
+
arc: "1",
|
|
213
|
+
oids: {
|
|
214
|
+
ocspBasicResponse: "1",
|
|
215
|
+
ocspNonce: "2",
|
|
216
|
+
ocspNoCheck: "5"
|
|
217
|
+
}
|
|
218
|
+
} }
|
|
209
219
|
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
220
|
+
}
|
|
221
|
+
} }
|
|
222
|
+
},
|
|
223
|
+
kerberosV5: {
|
|
224
|
+
arc: "2",
|
|
225
|
+
oids: { idPkinitSan: "2" }
|
|
212
226
|
}
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
private: {
|
|
230
|
+
arc: "4",
|
|
231
|
+
children: { enterprise: {
|
|
232
|
+
arc: "1",
|
|
233
|
+
children: { microsoft: {
|
|
234
|
+
arc: "311",
|
|
235
|
+
children: { msEnrollment: {
|
|
236
|
+
arc: "20",
|
|
237
|
+
children: { msPrincipalNameForms: {
|
|
238
|
+
arc: "2",
|
|
239
|
+
oids: { ntPrincipalName: "3" }
|
|
240
|
+
} }
|
|
241
|
+
} }
|
|
242
|
+
} }
|
|
213
243
|
} }
|
|
214
|
-
}
|
|
215
|
-
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
216
246
|
} }
|
|
217
247
|
},
|
|
218
248
|
oiw: {
|
|
@@ -273,7 +303,8 @@ var e = {
|
|
|
273
303
|
policyConstraints: "36",
|
|
274
304
|
extendedKeyUsage: "37",
|
|
275
305
|
freshestCRL: "46",
|
|
276
|
-
inhibitAnyPolicy: "54"
|
|
306
|
+
inhibitAnyPolicy: "54",
|
|
307
|
+
noRevAvail: "56"
|
|
277
308
|
},
|
|
278
309
|
children: { certificatePolicies: {
|
|
279
310
|
arc: "32",
|
|
@@ -321,7 +352,6 @@ var e = {
|
|
|
321
352
|
}
|
|
322
353
|
}
|
|
323
354
|
};
|
|
324
|
-
//#endregion
|
|
325
355
|
export { e as default };
|
|
326
356
|
|
|
327
357
|
//# sourceMappingURL=oids.js.map
|