micro509 0.12.0 → 0.14.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.
Files changed (123) hide show
  1. package/README.md +78 -30
  2. package/dist/crypto/crypto.d.ts +73 -0
  3. package/dist/crypto/crypto.js +74 -0
  4. package/dist/crypto/crypto.js.map +1 -0
  5. package/dist/crypto.d.ts +4 -0
  6. package/dist/crypto.js +2 -0
  7. package/dist/der/der.d.ts +127 -0
  8. package/dist/der/der.js +171 -0
  9. package/dist/der/der.js.map +1 -0
  10. package/dist/der.d.ts +4 -0
  11. package/dist/der.js +4 -0
  12. package/dist/index.d.ts +13 -9
  13. package/dist/index.js +17 -15
  14. package/dist/internal/asn1/asn1.d.ts +20 -0
  15. package/dist/internal/asn1/asn1.js +80 -37
  16. package/dist/internal/asn1/asn1.js.map +1 -1
  17. package/dist/internal/asn1/der.d.ts +173 -0
  18. package/dist/internal/asn1/der.js +116 -38
  19. package/dist/internal/asn1/der.js.map +1 -1
  20. package/dist/internal/asn1/oids.js +7 -1
  21. package/dist/internal/asn1/oids2.js +9 -2
  22. package/dist/internal/asn1/oids2.js.map +1 -1
  23. package/dist/internal/crypto/algorithm-names.js +4 -0
  24. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  25. package/dist/internal/crypto/pbes2.d.ts +38 -0
  26. package/dist/internal/crypto/pbes2.js +9 -10
  27. package/dist/internal/crypto/pbes2.js.map +1 -1
  28. package/dist/internal/crypto/rsa-pss.js +2 -0
  29. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  30. package/dist/internal/crypto/sig-verify.d.ts +31 -0
  31. package/dist/internal/crypto/sig-verify.js +10 -8
  32. package/dist/internal/crypto/sig-verify.js.map +1 -1
  33. package/dist/internal/shared/base64.js +7 -1
  34. package/dist/internal/shared/base64.js.map +1 -1
  35. package/dist/internal/shared/dn.d.ts +16 -0
  36. package/dist/internal/shared/dn.js +149 -12
  37. package/dist/internal/shared/dn.js.map +1 -1
  38. package/dist/internal/shared/ip.d.ts +69 -0
  39. package/dist/internal/shared/ip.js +18 -1
  40. package/dist/internal/shared/ip.js.map +1 -1
  41. package/dist/internal/shared/rfc3454-tables.js +1782 -0
  42. package/dist/internal/shared/rfc3454-tables.js.map +1 -0
  43. package/dist/internal/verify/name-constraints-engine.js +47 -15
  44. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  45. package/dist/internal/verify/policy-engine.js +85 -94
  46. package/dist/internal/verify/policy-engine.js.map +1 -1
  47. package/dist/internal/verify/verify-path.d.ts +7 -0
  48. package/dist/internal/verify/verify-path.js +49 -45
  49. package/dist/internal/verify/verify-path.js.map +1 -1
  50. package/dist/internal/x509/directory-name.js +24 -0
  51. package/dist/internal/x509/directory-name.js.map +1 -0
  52. package/dist/internal/x509/extension-bits.js +14 -11
  53. package/dist/internal/x509/extension-bits.js.map +1 -1
  54. package/dist/internal/x509/extension-errors.d.ts +6 -0
  55. package/dist/internal/x509/extension-errors.js +20 -0
  56. package/dist/internal/x509/extension-errors.js.map +1 -0
  57. package/dist/internal/x509/extension-registry.js +113 -55
  58. package/dist/internal/x509/extension-registry.js.map +1 -1
  59. package/dist/internal/x509/general-name-tags.js +28 -0
  60. package/dist/internal/x509/general-name-tags.js.map +1 -0
  61. package/dist/internal/x509/general-name.js +97 -0
  62. package/dist/internal/x509/general-name.js.map +1 -0
  63. package/dist/internal/x509/name-fields.js +20 -10
  64. package/dist/internal/x509/name-fields.js.map +1 -1
  65. package/dist/keys/keys.d.ts +16 -2
  66. package/dist/keys/keys.js +311 -170
  67. package/dist/keys/keys.js.map +1 -1
  68. package/dist/keys.d.ts +3 -2
  69. package/dist/keys.js +3 -2
  70. package/dist/pem/pem.d.ts +3 -2
  71. package/dist/pem/pem.js +112 -30
  72. package/dist/pem/pem.js.map +1 -1
  73. package/dist/pkcs/pkcs12-mac.js +3 -3
  74. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  75. package/dist/pkcs/pkcs7.d.ts +85 -21
  76. package/dist/pkcs/pkcs7.js +261 -186
  77. package/dist/pkcs/pkcs7.js.map +1 -1
  78. package/dist/pkcs.d.ts +2 -2
  79. package/dist/result/result.d.ts +18 -10
  80. package/dist/result/result.js +20 -12
  81. package/dist/result/result.js.map +1 -1
  82. package/dist/result.d.ts +2 -2
  83. package/dist/result.js +2 -2
  84. package/dist/revocation/chain.js +154 -103
  85. package/dist/revocation/chain.js.map +1 -1
  86. package/dist/revocation/crl.d.ts +13 -2
  87. package/dist/revocation/crl.js +415 -236
  88. package/dist/revocation/crl.js.map +1 -1
  89. package/dist/revocation/ocsp.d.ts +58 -17
  90. package/dist/revocation/ocsp.js +186 -174
  91. package/dist/revocation/ocsp.js.map +1 -1
  92. package/dist/revocation/revocation.d.ts +4 -4
  93. package/dist/revocation/revocation.js +48 -30
  94. package/dist/revocation/revocation.js.map +1 -1
  95. package/dist/revocation.d.ts +4 -4
  96. package/dist/revocation.js +5 -5
  97. package/dist/verify/identity.d.ts +2 -1
  98. package/dist/verify/identity.js +2 -1
  99. package/dist/verify/identity.js.map +1 -1
  100. package/dist/verify/policy.d.ts +6 -1
  101. package/dist/verify/verify.d.ts +18 -3
  102. package/dist/verify/verify.js +66 -41
  103. package/dist/verify/verify.js.map +1 -1
  104. package/dist/verify.d.ts +2 -1
  105. package/dist/verify.js +4 -3
  106. package/dist/x509/certificate.d.ts +36 -13
  107. package/dist/x509/certificate.js +36 -19
  108. package/dist/x509/certificate.js.map +1 -1
  109. package/dist/x509/csr.d.ts +6 -3
  110. package/dist/x509/extensions.d.ts +59 -22
  111. package/dist/x509/extensions.js +384 -117
  112. package/dist/x509/extensions.js.map +1 -1
  113. package/dist/x509/name-text.js +2 -0
  114. package/dist/x509/name-text.js.map +1 -1
  115. package/dist/x509/name.d.ts +8 -5
  116. package/dist/x509/name.js +17 -12
  117. package/dist/x509/name.js.map +1 -1
  118. package/dist/x509/parse.d.ts +104 -18
  119. package/dist/x509/parse.js +127 -163
  120. package/dist/x509/parse.js.map +1 -1
  121. package/dist/x509.d.ts +8 -5
  122. package/dist/x509.js +10 -8
  123. package/package.json +52 -34
@@ -0,0 +1,173 @@
1
+ //#region src/internal/asn1/der.d.ts
2
+ /**
3
+ * Low-level DER encoding and reading helpers shared across the library.
4
+ *
5
+ * These utilities build and traverse ASN.1 TLV (tag-length-value) structures.
6
+ *
7
+ * @module
8
+ */
9
+ /**
10
+ * Maximum nesting depth allowed when recursively walking a DER structure.
11
+ *
12
+ * Guards against stack exhaustion from pathologically nested input.
13
+ */
14
+ declare const DEFAULT_MAX_DER_DEPTH = 64;
15
+ /** Concatenates multiple byte arrays into a single {@linkcode Uint8Array}. */
16
+ declare function concatBytes(parts: readonly Uint8Array[]): Uint8Array;
17
+ /**
18
+ * Builds a complete DER TLV (tag-length-value) element:
19
+ *
20
+ * - one tag octet,
21
+ * - the DER-encoded length, then
22
+ * - the raw value bytes.
23
+ */
24
+ declare function tlv(tag: number, value: Uint8Array): Uint8Array;
25
+ /** Wraps concatenated children in a SEQUENCE (tag `0x30`). */
26
+ declare function sequence(parts: readonly Uint8Array[]): Uint8Array;
27
+ /**
28
+ * Wraps children in a SET (tag `0x31`) after DER-sorting them lexicographically by encoded bytes,
29
+ * as required by {@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690} DER.
30
+ */
31
+ declare function setOf(parts: readonly Uint8Array[]): Uint8Array;
32
+ /**
33
+ * Wraps a value in an explicit context-specific constructed tag (`0xa0 + tag`).
34
+ *
35
+ * Used for optional SEQUENCE fields tagged with `[tag] EXPLICIT`.
36
+ */
37
+ declare function explicitContext(tag: number, value: Uint8Array): Uint8Array;
38
+ /**
39
+ * Wraps a value in an implicit context-specific constructed tag (`0xa0 + tag`).
40
+ *
41
+ * Used for `[tag] IMPLICIT` fields whose underlying type is constructed (e.g. SEQUENCE).
42
+ */
43
+ declare function implicitConstructedContext(tag: number, value: Uint8Array): Uint8Array;
44
+ /**
45
+ * Wraps a value in an implicit context-specific primitive tag (`0x80 + tag`).
46
+ *
47
+ * Used for `[tag] IMPLICIT` fields whose underlying type is primitive (e.g. OCTET STRING).
48
+ */
49
+ declare function implicitPrimitiveContext(tag: number, value: Uint8Array): Uint8Array;
50
+ /**
51
+ * Encodes raw big-endian bytes as a DER INTEGER (tag `0x02`).
52
+ *
53
+ * Strips leading zero bytes for minimal encoding and prepends a zero byte when the high bit is set
54
+ * to keep the value non-negative.
55
+ */
56
+ declare function integer(bytes: Uint8Array): Uint8Array;
57
+ /**
58
+ * Encodes a non-negative JavaScript `number` as a DER INTEGER.
59
+ *
60
+ * @throws if the value is not a non-negative safe integer.
61
+ */
62
+ declare function integerFromNumber(value: number): Uint8Array;
63
+ /** Encodes a DER BOOLEAN (tag `0x01`): `true` → `0xff`, `false` → `0x00`. */
64
+ declare function bool(value: boolean): Uint8Array;
65
+ /** Produces a DER NULL element (tag `0x05`, zero-length value). */
66
+ declare function nullValue(): Uint8Array;
67
+ /** Wraps raw bytes in an OCTET STRING element (tag `0x04`). */
68
+ declare function octetString(value: Uint8Array): Uint8Array;
69
+ /**
70
+ * Encodes a DER BIT STRING (tag `0x03`).
71
+ *
72
+ * The value is prefixed with a single octet indicating how many trailing bits in the last byte are unused.
73
+ *
74
+ * @param unusedBits Number of unused trailing bits (0–7). Defaults to 0.
75
+ */
76
+ declare function bitString(value: Uint8Array, unusedBits?: number): Uint8Array;
77
+ /** Encodes a DER UTF8String (tag `0x0c`). */
78
+ declare function utf8String(value: string): Uint8Array;
79
+ /**
80
+ * Encodes a DER PrintableString (tag `0x13`).
81
+ *
82
+ * @throws if the input contains characters outside the ITU-T X.680 §41.4 Table 10 PrintableString set.
83
+ */
84
+ declare function printableString(value: string): Uint8Array;
85
+ /**
86
+ * Encodes a DER IA5String (tag `0x16`).
87
+ *
88
+ * @throws if the input contains any non-ASCII character (code point > 0x7f).
89
+ */
90
+ declare function ia5String(value: string): Uint8Array;
91
+ /**
92
+ * Encodes a DER BMPString (tag `0x1e`) as big-endian UTF-16.
93
+ *
94
+ * @throws on lone surrogates and on code points above the Basic Multilingual Plane.
95
+ */
96
+ declare function bmpString(value: string): Uint8Array;
97
+ /**
98
+ * Encodes a DER UniversalString (tag `0x1c`) as big-endian UTF-32.
99
+ *
100
+ * @throws on lone surrogates.
101
+ */
102
+ declare function universalString(value: string): Uint8Array;
103
+ /**
104
+ * Encodes a dotted-decimal OID string as a DER OBJECT IDENTIFIER (tag `0x06`).
105
+ *
106
+ * Validates arc constraints per X.660 §7.6: the root arc must be 0–2, and under
107
+ * roots 0 and 1 the second arc must be 0–39. X.690 §8.19.4 defines the `(X*40)+Y`
108
+ * packing of the first two arcs into one subidentifier.\
109
+ * Sub-identifiers are encoded with base-128 continuation.
110
+ */
111
+ declare function objectIdentifier(oid: string): Uint8Array;
112
+ /**
113
+ * Encodes a `Date` as a DER UTCTime (tag `0x17`), format `YYMMDDHHMMSSZ`.
114
+ *
115
+ * Only the two-digit year is stored; suitable for dates in 1950–2049.
116
+ */
117
+ declare function utcTime(date: Date): Uint8Array;
118
+ /**
119
+ * Encodes a {@linkcode Date} as a DER GeneralizedTime (tag `0x18`), format `YYYYMMDDHHMMSSZ`.
120
+ *
121
+ * Uses a four-digit year; required for dates outside the 1950–2049 range.
122
+ */
123
+ declare function generalizedTime(date: Date): Uint8Array;
124
+ /**
125
+ * Encodes a {@linkcode Date} as the appropriate DER time type per RFC 5280.
126
+ *
127
+ * - {@linkcode utcTime} for 1950–2049
128
+ * - {@linkcode generalizedTime} otherwise
129
+ */
130
+ declare function time(date: Date): Uint8Array;
131
+ /** A single parsed ASN.1 TLV element with byte-range metadata. */
132
+ interface DerElement {
133
+ /** ASN.1 tag byte (e.g. `0x30` for SEQUENCE, `0x02` for INTEGER). */
134
+ readonly tag: number;
135
+ /** Number of bytes occupied by the tag + length octets. */
136
+ readonly headerLength: number;
137
+ /** Byte length of the value portion (excluding tag and length octets). */
138
+ readonly length: number;
139
+ /** Byte offset where the value portion begins in the source buffer. */
140
+ readonly start: number;
141
+ /** Byte offset one past the last value byte. Equals the next element's header offset. */
142
+ readonly end: number;
143
+ /** The raw value bytes (slice of the source buffer). */
144
+ readonly value: Uint8Array;
145
+ }
146
+ /** Options for {@linkcode readSequenceChildren}. */
147
+ interface ReadSequenceChildrenOptions {
148
+ /** Maximum nesting depth for the DER depth check. @default {@linkcode DEFAULT_MAX_DER_DEPTH}. */
149
+ readonly maxDepth?: number;
150
+ /** Constructed tags whose inner bytes may not parse as valid TLV children (e.g. opaque extension values). */
151
+ readonly allowOpaqueConstructedTags?: readonly number[];
152
+ }
153
+ /** Options for {@linkcode readRootElement}. */
154
+ interface ReadRootElementOptions {
155
+ /** Maximum nesting depth for the DER depth check. @default {@linkcode DEFAULT_MAX_DER_DEPTH}. */
156
+ readonly maxDepth?: number;
157
+ /** Constructed tags whose inner bytes may not parse as valid TLV children (e.g. opaque extension values). */
158
+ readonly allowOpaqueConstructedTags?: readonly number[];
159
+ }
160
+ /**
161
+ * Walks the full DER tree rooted in {@linkcode bytes}.
162
+ *
163
+ * Constructed tags with content that cannot be parsed as valid children are tolerated when listed in {@linkcode options | allowOpaqueConstructedTags}.
164
+ *
165
+ * @throws if nesting exceeds {@linkcode maxDepth}.
166
+ */
167
+ declare function assertDerMaxDepth(bytes: Uint8Array, maxDepth?: number, options?: {
168
+ /** Constructed tags whose inner bytes may not parse as valid TLV children. */
169
+ readonly allowOpaqueConstructedTags?: readonly number[];
170
+ }): void;
171
+ //#endregion
172
+ export { DEFAULT_MAX_DER_DEPTH, DerElement, ReadRootElementOptions, ReadSequenceChildrenOptions, assertDerMaxDepth, bitString, bmpString, bool, concatBytes, explicitContext, generalizedTime, ia5String, implicitConstructedContext, implicitPrimitiveContext, integer, integerFromNumber, nullValue, objectIdentifier, octetString, printableString, sequence, setOf, time, tlv, universalString, utcTime, utf8String };
173
+ //# sourceMappingURL=der.d.ts.map
@@ -1,22 +1,47 @@
1
+ //#region src/internal/asn1/der.ts
2
+ /**
3
+ * Low-level DER encoding and reading helpers shared across the library.
4
+ *
5
+ * These utilities build and traverse ASN.1 TLV (tag-length-value) structures.
6
+ *
7
+ * @module
8
+ */
9
+ /**
10
+ * Maximum nesting depth allowed when recursively walking a DER structure.
11
+ *
12
+ * Guards against stack exhaustion from pathologically nested input.
13
+ */
14
+ const e = 64;
1
15
  /**
2
16
  * Produces the DER length octets for a given byte count.
3
- * Values < 128 use the short form (one octet); larger values use the
4
- * long form (leading octet encodes the number of subsequent length bytes).
17
+ *
18
+ * Values < 128 use the short form (one octet);
19
+ * larger values use the long form (leading octet encodes the number of subsequent length bytes).
5
20
  */
6
21
  function encodeLength(e) {
7
22
  if (assertNonNegativeSafeInteger(e, "DER length"), e < 128) return Uint8Array.of(e);
8
23
  let t = encodeBase256(e);
9
24
  return Uint8Array.of(128 | t.length, ...t);
10
25
  }
11
- /** Concatenates multiple byte arrays into a single `Uint8Array`. */
26
+ /** Concatenates multiple byte arrays into a single {@linkcode Uint8Array}. */
12
27
  function concatBytes(e) {
13
28
  let t = e.reduce((e, t) => e + t.length, 0), n = new Uint8Array(t), r = 0;
14
29
  for (let t of e) n.set(t, r), r += t.length;
15
30
  return n;
16
31
  }
32
+ /** Compares two optional byte arrays; two absent values are equal. */
33
+ function optionalBytesEqual(e, t) {
34
+ if (e === void 0 || t === void 0) return e === t;
35
+ if (e.length !== t.length) return !1;
36
+ for (let n = 0; n < e.length; n += 1) if (e[n] !== t[n]) return !1;
37
+ return !0;
38
+ }
17
39
  /**
18
- * Builds a complete DER TLV (tag-length-value) element: one tag octet,
19
- * the DER-encoded length, then the raw value bytes.
40
+ * Builds a complete DER TLV (tag-length-value) element:
41
+ *
42
+ * - one tag octet,
43
+ * - the DER-encoded length, then
44
+ * - the raw value bytes.
20
45
  */
21
46
  function tlv(e, t) {
22
47
  return assertSingleOctetDerTag(e), concatBytes([
@@ -30,8 +55,8 @@ function sequence(e) {
30
55
  return tlv(48, concatBytes(e));
31
56
  }
32
57
  /**
33
- * Wraps children in a SET (tag `0x31`) after DER-sorting them
34
- * lexicographically by encoded bytes, as required by X.690 DER.
58
+ * Wraps children in a SET (tag `0x31`) after DER-sorting them lexicographically by encoded bytes,
59
+ * as required by {@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690} DER.
35
60
  */
36
61
  function setOf(e) {
37
62
  return tlv(49, concatBytes(e.slice().sort((e, t) => {
@@ -45,6 +70,7 @@ function setOf(e) {
45
70
  }
46
71
  /**
47
72
  * Wraps a value in an explicit context-specific constructed tag (`0xa0 + tag`).
73
+ *
48
74
  * Used for optional SEQUENCE fields tagged with `[tag] EXPLICIT`.
49
75
  */
50
76
  function explicitContext(e, t) {
@@ -52,6 +78,7 @@ function explicitContext(e, t) {
52
78
  }
53
79
  /**
54
80
  * Wraps a value in an implicit context-specific constructed tag (`0xa0 + tag`).
81
+ *
55
82
  * Used for `[tag] IMPLICIT` fields whose underlying type is constructed (e.g. SEQUENCE).
56
83
  */
57
84
  function implicitConstructedContext(e, t) {
@@ -59,6 +86,7 @@ function implicitConstructedContext(e, t) {
59
86
  }
60
87
  /**
61
88
  * Wraps a value in an implicit context-specific primitive tag (`0x80 + tag`).
89
+ *
62
90
  * Used for `[tag] IMPLICIT` fields whose underlying type is primitive (e.g. OCTET STRING).
63
91
  */
64
92
  function implicitPrimitiveContext(e, t) {
@@ -66,8 +94,9 @@ function implicitPrimitiveContext(e, t) {
66
94
  }
67
95
  /**
68
96
  * Encodes raw big-endian bytes as a DER INTEGER (tag `0x02`).
69
- * Strips leading zero bytes for minimal encoding and prepends a zero
70
- * byte when the high bit is set to keep the value non-negative.
97
+ *
98
+ * Strips leading zero bytes for minimal encoding and prepends a zero byte when the high bit is set
99
+ * to keep the value non-negative.
71
100
  */
72
101
  function integer(e) {
73
102
  if (e.length === 0) return tlv(2, Uint8Array.of(0));
@@ -78,7 +107,8 @@ function integer(e) {
78
107
  }
79
108
  /**
80
109
  * Encodes a non-negative JavaScript `number` as a DER INTEGER.
81
- * Throws if the value is not a non-negative safe integer.
110
+ *
111
+ * @throws if the value is not a non-negative safe integer.
82
112
  */
83
113
  function integerFromNumber(e) {
84
114
  if (!Number.isSafeInteger(e) || e < 0) throw Error("INTEGER must be a non-negative safe integer");
@@ -97,8 +127,9 @@ function octetString(e) {
97
127
  return tlv(4, e);
98
128
  }
99
129
  /**
100
- * Encodes a DER BIT STRING (tag `0x03`). The value is prefixed with a
101
- * single octet indicating how many trailing bits in the last byte are unused.
130
+ * Encodes a DER BIT STRING (tag `0x03`).
131
+ *
132
+ * The value is prefixed with a single octet indicating how many trailing bits in the last byte are unused.
102
133
  *
103
134
  * @param unusedBits Number of unused trailing bits (0–7). Defaults to 0.
104
135
  */
@@ -114,21 +145,56 @@ function utf8String(e) {
114
145
  }
115
146
  /**
116
147
  * Encodes a DER PrintableString (tag `0x13`).
117
- * Throws if the input contains characters outside the X.520 PrintableString set.
148
+ *
149
+ * @throws if the input contains characters outside the ITU-T X.680 §41.4 Table 10 PrintableString set.
118
150
  */
119
151
  function printableString(e) {
120
152
  if (!/^[A-Za-z0-9 '()+,\-./:=?]*$/.test(e)) throw Error("Invalid PrintableString: contains characters outside the allowed set");
121
153
  return tlv(19, new TextEncoder().encode(e));
122
154
  }
155
+ /** Validates a string is ASCII (IA5) and returns its content bytes, without a tag. */
156
+ function ia5Bytes(e) {
157
+ for (let t = 0; t < e.length; t++) if (e.charCodeAt(t) > 127) throw Error("Invalid IA5String: contains non-ASCII characters");
158
+ return new TextEncoder().encode(e);
159
+ }
123
160
  /**
124
161
  * Encodes a DER IA5String (tag `0x16`).
125
- * Throws if the input contains any non-ASCII character (code point > 0x7f).
162
+ *
163
+ * @throws if the input contains any non-ASCII character (code point > 0x7f).
126
164
  */
127
165
  function ia5String(e) {
128
- for (let t = 0; t < e.length; t++) if (e.charCodeAt(t) > 127) throw Error("Invalid IA5String: contains non-ASCII characters");
129
- return tlv(22, new TextEncoder().encode(e));
166
+ return tlv(22, ia5Bytes(e));
130
167
  }
131
- /** Encode a non-negative integer as a base-128 sub-identifier (X.690 §8.19.2). */
168
+ /**
169
+ * Encodes a DER BMPString (tag `0x1e`) as big-endian UTF-16.
170
+ *
171
+ * @throws on lone surrogates and on code points above the Basic Multilingual Plane.
172
+ */
173
+ function bmpString(e) {
174
+ let t = [];
175
+ for (let n of e) {
176
+ let e = n.codePointAt(0) ?? 0;
177
+ if (e > 65535) throw Error("Invalid BMPString: code point above the Basic Multilingual Plane");
178
+ if (e >= 55296 && e <= 57343) throw Error("Invalid BMPString: lone surrogate");
179
+ t.push(e >> 8 & 255, e & 255);
180
+ }
181
+ return tlv(30, Uint8Array.from(t));
182
+ }
183
+ /**
184
+ * Encodes a DER UniversalString (tag `0x1c`) as big-endian UTF-32.
185
+ *
186
+ * @throws on lone surrogates.
187
+ */
188
+ function universalString(e) {
189
+ let t = [];
190
+ for (let n of e) {
191
+ let e = n.codePointAt(0) ?? 0;
192
+ if (e >= 55296 && e <= 57343) throw Error("Invalid UniversalString: lone surrogate");
193
+ t.push(e >> 24 & 255, e >> 16 & 255, e >> 8 & 255, e & 255);
194
+ }
195
+ return tlv(28, Uint8Array.from(t));
196
+ }
197
+ /** 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}). */
132
198
  function encodeBase128(e) {
133
199
  let t = [Number(e & 127n)], n = e >> 7n;
134
200
  for (; n > 0n;) t.unshift(128 | Number(n & 127n)), n >>= 7n;
@@ -136,8 +202,11 @@ function encodeBase128(e) {
136
202
  }
137
203
  /**
138
204
  * Encodes a dotted-decimal OID string as a DER OBJECT IDENTIFIER (tag `0x06`).
139
- * Validates arc constraints per X.660: first arc must be 0–2, second < 40
140
- * for arcs 0 and 1. Sub-identifiers are encoded with base-128 continuation.
205
+ *
206
+ * Validates arc constraints per X.660 §7.6: the root arc must be 0–2, and under
207
+ * roots 0 and 1 the second arc must be 0–39. X.690 §8.19.4 defines the `(X*40)+Y`
208
+ * packing of the first two arcs into one subidentifier.\
209
+ * Sub-identifiers are encoded with base-128 continuation.
141
210
  */
142
211
  function objectIdentifier(e) {
143
212
  let t = /^\d+$/, n = e.split(".").map((e) => {
@@ -155,6 +224,7 @@ function objectIdentifier(e) {
155
224
  }
156
225
  /**
157
226
  * Encodes a `Date` as a DER UTCTime (tag `0x17`), format `YYMMDDHHMMSSZ`.
227
+ *
158
228
  * Only the two-digit year is stored; suitable for dates in 1950–2049.
159
229
  */
160
230
  function utcTime(e) {
@@ -172,7 +242,8 @@ function utcTime(e) {
172
242
  return tlv(23, new TextEncoder().encode(n));
173
243
  }
174
244
  /**
175
- * Encodes a `Date` as a DER GeneralizedTime (tag `0x18`), format `YYYYMMDDHHMMSSZ`.
245
+ * Encodes a {@linkcode Date} as a DER GeneralizedTime (tag `0x18`), format `YYYYMMDDHHMMSSZ`.
246
+ *
176
247
  * Uses a four-digit year; required for dates outside the 1950–2049 range.
177
248
  */
178
249
  function generalizedTime(e) {
@@ -190,8 +261,10 @@ function generalizedTime(e) {
190
261
  return tlv(24, new TextEncoder().encode(n));
191
262
  }
192
263
  /**
193
- * Encodes a `Date` as the appropriate DER time type per RFC 5280:
194
- * {@linkcode utcTime} for 1950–2049, {@linkcode generalizedTime} otherwise.
264
+ * Encodes a {@linkcode Date} as the appropriate DER time type per RFC 5280.
265
+ *
266
+ * - {@linkcode utcTime} for 1950–2049
267
+ * - {@linkcode generalizedTime} otherwise
195
268
  */
196
269
  function time(e) {
197
270
  return e.getUTCFullYear() >= 2050 || e.getUTCFullYear() < 1950 ? generalizedTime(e) : utcTime(e);
@@ -208,11 +281,11 @@ function encodeBase256(e) {
208
281
  return t;
209
282
  }
210
283
  /**
211
- * Reads one TLV element from `bytes` starting at `offset`.
212
- * Parses the tag byte, decodes the DER length octets, and slices out the
213
- * value bytes. Throws on truncated input, indefinite lengths, and
214
- * non-minimal length encodings.
284
+ * Reads one TLV element from {@linkcode bytes} starting at {@linkcode offset}.
285
+ *
286
+ * Parses the tag byte, decodes the DER length octets, and slices out the value bytes.
215
287
  *
288
+ * @throws on truncated input, indefinite lengths, and non-minimal length encodings.
216
289
  * @param offset Byte position of the tag octet. Defaults to 0.
217
290
  */
218
291
  function readElement(e, t = 0) {
@@ -261,9 +334,11 @@ function readLongFormDerLength(e, t, n) {
261
334
  return r;
262
335
  }
263
336
  /**
264
- * Walks the full DER tree rooted in `bytes` and throws if nesting exceeds
265
- * `maxDepth`. Constructed tags with content that cannot be parsed as valid
266
- * children are tolerated when listed in `allowOpaqueConstructedTags`.
337
+ * Walks the full DER tree rooted in {@linkcode bytes}.
338
+ *
339
+ * Constructed tags with content that cannot be parsed as valid children are tolerated when listed in {@linkcode options | allowOpaqueConstructedTags}.
340
+ *
341
+ * @throws if nesting exceeds {@linkcode maxDepth}.
267
342
  */
268
343
  function assertDerMaxDepth(e, t = 64, n) {
269
344
  if (!Number.isSafeInteger(t) || t < 1) throw Error("DER max depth must be a positive safe integer");
@@ -308,8 +383,11 @@ function readDerChildOrOpaque(e, t, n, r) {
308
383
  if (!canTreatAsOpaqueLeaf(t, n, r)) throw Error("DER child exceeds parent length");
309
384
  }
310
385
  /**
311
- * Reads the single top-level TLV element from `bytes`, optionally
312
- * validating nesting depth. Throws if there is trailing data after the element.
386
+ * Reads the single top-level TLV element from {@linkcode bytes}.
387
+ *
388
+ * Optionally validates nesting depth.
389
+ *
390
+ * @throws if there is trailing data after the element.
313
391
  */
314
392
  function readRootElement(e, t) {
315
393
  assertDerMaxDepth(e, t?.maxDepth ?? 64, t);
@@ -318,8 +396,9 @@ function readRootElement(e, t) {
318
396
  return n;
319
397
  }
320
398
  /**
321
- * Reads a DER-encoded SEQUENCE from `bytes` and returns its direct children.
322
- * Throws if the root element is not a SEQUENCE or if child boundaries are inconsistent.
399
+ * Reads a DER-encoded SEQUENCE from {@linkcode bytes} and returns its direct children.
400
+ *
401
+ * @throws if the root element is not a SEQUENCE or if child boundaries are inconsistent.
323
402
  */
324
403
  function readSequenceChildren(e, t) {
325
404
  let n = readRootElement(e, t);
@@ -333,7 +412,7 @@ function readSequenceChildren(e, t) {
333
412
  if (i !== n.end) throw Error("Malformed DER sequence");
334
413
  return r;
335
414
  }
336
- /** Throws if `value` is not a non-negative safe integer. */
415
+ /** @throws if {@linkcode value} is not a non-negative safe integer. */
337
416
  function assertNonNegativeSafeInteger(e, t) {
338
417
  if (!Number.isSafeInteger(e) || e < 0) throw Error(`${t} must be a non-negative safe integer`);
339
418
  }
@@ -348,14 +427,13 @@ function assertValidDate(e, t) {
348
427
  if (Number.isNaN(e.getTime())) throw RangeError(`${t} requires a valid Date`);
349
428
  }
350
429
  /**
351
- * Returns `true` when a constructed element's content should be treated as
352
- * an opaque leaf (not recursed into) because its tag appears in the
353
- * `allowOpaqueConstructedTags` list and the offset is at the element start.
430
+ * @returns `true` when a constructed element's content should be treated as an opaque leaf (not recursed into)
431
+ * because its tag appears in the {@linkcode options | allowOpaqueConstructedTags} list and the offset is at the element start.
354
432
  */
355
433
  function canTreatAsOpaqueLeaf(e, t, n) {
356
434
  return t === e.start && n?.allowOpaqueConstructedTags?.includes(e.tag) === !0;
357
435
  }
358
436
  //#endregion
359
- export { assertDerMaxDepth, bitString, bool, concatBytes, encodeLength, explicitContext, generalizedTime, ia5String, implicitConstructedContext, implicitPrimitiveContext, integer, integerFromNumber, nullValue, objectIdentifier, octetString, printableString, readElement, readRootElement, readSequenceChildren, sequence, setOf, time, tlv, utcTime, utf8String };
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 };
360
438
 
361
439
  //# 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 * without pulling in external dependencies.\n *\n * @module\n */\n\n/**\n * Maximum nesting depth allowed when recursively walking a DER structure.\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 * Values < 128 use the short form (one octet); larger values use the\n * 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 `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/**\n * Builds a complete DER TLV (tag-length-value) element: one tag octet,\n * the DER-encoded length, then 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\n * lexicographically by encoded bytes, as required by 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 * 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 * 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 * 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 * Strips leading zero bytes for minimal encoding and prepends a zero\n * byte when the high bit is set 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 * 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`). The value is prefixed with a\n * 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 * Throws if the input contains characters outside the X.520 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 IA5String (tag `0x16`).\n * Throws if the input contains any non-ASCII character (code point > 0x7f).\n */\nexport function ia5String(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 tlv(0x16, new TextEncoder().encode(value));\n}\n\n/** Encode a non-negative integer as a base-128 sub-identifier (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 * Validates arc constraints per X.660: first arc must be 0–2, second < 40\n * for arcs 0 and 1. 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 * 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 `Date` as a DER GeneralizedTime (tag `0x18`), format `YYYYMMDDHHMMSSZ`.\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 `Date` as the appropriate DER time type per RFC 5280:\n * {@linkcode utcTime} for 1950–2049, {@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 `bytes` starting at `offset`.\n * Parses the tag byte, decodes the DER length octets, and slices out the\n * value bytes. Throws on truncated input, indefinite lengths, and\n * non-minimal length encodings.\n *\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 `bytes` and throws if nesting exceeds\n * `maxDepth`. Constructed tags with content that cannot be parsed as valid\n * children are tolerated when listed in `allowOpaqueConstructedTags`.\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 `bytes`, optionally\n * validating nesting depth. 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 `bytes` and returns its direct children.\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 `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\n * an opaque leaf (not recursed into) because its tag appears in the\n * `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":";;;;;AAoBA,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,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BAAgB,GAAY,GAA4C;CAChF,IAAI,OAAO,MAAM,EAAK,QAAQ,CAAC,GAC9B,MAAU,WAAW,GAAG,EAAM,uBAAuB;AAEvD;;;;;;AAOA,SAAS,qBACR,GACA,GACA,GAIU;CACV,OACC,MAAW,EAAQ,SAAS,GAAS,4BAA4B,SAAS,EAAQ,GAAG,MAAM;AAE7F"}
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,KAAQ,GAElB,AADA,EAAI,IAAI,GAAM,CAAM,GACpB,KAAU,EAAK;CAEhB,OAAO;AACR;;AAGA,SAAgB,mBACf,GACA,GACU;CACV,IAAI,MAAS,KAAA,KAAa,MAAU,KAAA,GACnC,OAAO,MAAS;CAEjB,IAAI,EAAK,WAAW,EAAM,QACzB,OAAO;CAER,KAAK,IAAI,IAAQ,GAAG,IAAQ,EAAK,QAAQ,KAAS,GACjD,IAAI,EAAK,OAAW,EAAM,IACzB,OAAO;CAGT,OAAO;AACR;;;;;;;;AASA,SAAgB,IAAI,GAAa,GAA+B;CAE/D,OADA,wBAAwB,CAA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,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"}
@@ -150,7 +150,12 @@ var e = {
150
150
  },
151
151
  edwardsCurveAlgs: {
152
152
  arc: "101",
153
- oids: { ed25519: "112" }
153
+ oids: {
154
+ x25519: "110",
155
+ x448: "111",
156
+ ed25519: "112",
157
+ ed448: "113"
158
+ }
154
159
  },
155
160
  dod: {
156
161
  arc: "6",
@@ -252,6 +257,7 @@ var e = {
252
257
  subjectKeyIdentifier: "14",
253
258
  keyUsage: "15",
254
259
  subjectAltName: "17",
260
+ issuerAltName: "18",
255
261
  basicConstraints: "19",
256
262
  cRLNumber: "20",
257
263
  cRLReason: "21",