micro509 0.13.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.
Files changed (165) hide show
  1. package/CHANGELOG.md +2064 -0
  2. package/README.md +111 -183
  3. package/dist/crypto/crypto.d.ts +104 -0
  4. package/dist/crypto/crypto.js +105 -0
  5. package/dist/crypto/crypto.js.map +1 -0
  6. package/dist/crypto.d.ts +4 -0
  7. package/dist/crypto.js +1 -0
  8. package/dist/der/der.d.ts +41 -33
  9. package/dist/der/der.js +26 -24
  10. package/dist/der/der.js.map +1 -1
  11. package/dist/index.d.ts +18 -14
  12. package/dist/index.js +19 -17
  13. package/dist/internal/asn1/asn1.d.ts +3 -6
  14. package/dist/internal/asn1/asn1.js +355 -44
  15. package/dist/internal/asn1/asn1.js.map +1 -1
  16. package/dist/internal/asn1/ber.js +146 -0
  17. package/dist/internal/asn1/ber.js.map +1 -0
  18. package/dist/internal/asn1/decode-refusal.js +29 -0
  19. package/dist/internal/asn1/decode-refusal.js.map +1 -0
  20. package/dist/internal/asn1/der.d.ts +42 -43
  21. package/dist/internal/asn1/der.js +148 -56
  22. package/dist/internal/asn1/der.js.map +1 -1
  23. package/dist/internal/asn1/oids.js +90 -54
  24. package/dist/internal/asn1/oids.js.map +1 -1
  25. package/dist/internal/asn1/oids2.js +1 -2
  26. package/dist/internal/asn1/oids2.js.map +1 -1
  27. package/dist/internal/crypto/algorithm-names.js +5 -2
  28. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  29. package/dist/internal/crypto/ecdsa.js +13 -8
  30. package/dist/internal/crypto/ecdsa.js.map +1 -1
  31. package/dist/internal/crypto/hash.js +1 -2
  32. package/dist/internal/crypto/hash.js.map +1 -1
  33. package/dist/internal/crypto/pbes2.d.ts +51 -0
  34. package/dist/internal/crypto/pbes2.js +86 -34
  35. package/dist/internal/crypto/pbes2.js.map +1 -1
  36. package/dist/internal/crypto/rsa-pss.js +48 -44
  37. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  38. package/dist/internal/crypto/sig-verify.d.ts +28 -0
  39. package/dist/internal/crypto/sig-verify.js +111 -62
  40. package/dist/internal/crypto/sig-verify.js.map +1 -1
  41. package/dist/internal/crypto/signing.d.ts +1 -4
  42. package/dist/internal/crypto/signing.js +28 -29
  43. package/dist/internal/crypto/signing.js.map +1 -1
  44. package/dist/internal/crypto/webcrypto.js +1 -2
  45. package/dist/internal/crypto/webcrypto.js.map +1 -1
  46. package/dist/internal/shared/base64.js +8 -3
  47. package/dist/internal/shared/base64.js.map +1 -1
  48. package/dist/internal/shared/dn.d.ts +13 -0
  49. package/dist/internal/shared/dn.js +101 -48
  50. package/dist/internal/shared/dn.js.map +1 -1
  51. package/dist/internal/shared/idna-tables.js +7217 -0
  52. package/dist/internal/shared/idna-tables.js.map +1 -0
  53. package/dist/internal/shared/idna.js +296 -0
  54. package/dist/internal/shared/idna.js.map +1 -0
  55. package/dist/internal/shared/ip.d.ts +66 -0
  56. package/dist/internal/shared/ip.js +19 -3
  57. package/dist/internal/shared/ip.js.map +1 -1
  58. package/dist/internal/shared/mailbox.js +26 -0
  59. package/dist/internal/shared/mailbox.js.map +1 -0
  60. package/dist/internal/shared/punycode.js +101 -0
  61. package/dist/internal/shared/punycode.js.map +1 -0
  62. package/dist/internal/shared/rfc3454-tables.js +1 -2
  63. package/dist/internal/shared/rfc3454-tables.js.map +1 -1
  64. package/dist/internal/shared/rfc4518-tables.js +119 -0
  65. package/dist/internal/shared/rfc4518-tables.js.map +1 -0
  66. package/dist/internal/shared/uri-host.js +102 -0
  67. package/dist/internal/shared/uri-host.js.map +1 -0
  68. package/dist/internal/verify/name-constraints-engine.js +246 -131
  69. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  70. package/dist/internal/verify/policy-engine.js +6 -21
  71. package/dist/internal/verify/policy-engine.js.map +1 -1
  72. package/dist/internal/verify/verify-path.d.ts +4 -0
  73. package/dist/internal/verify/verify-path.js +264 -128
  74. package/dist/internal/verify/verify-path.js.map +1 -1
  75. package/dist/internal/x509/directory-name.js +23 -0
  76. package/dist/internal/x509/directory-name.js.map +1 -0
  77. package/dist/internal/x509/extension-bits.js +15 -13
  78. package/dist/internal/x509/extension-bits.js.map +1 -1
  79. package/dist/internal/x509/extension-errors.d.ts +3 -0
  80. package/dist/internal/x509/extension-errors.js +19 -0
  81. package/dist/internal/x509/extension-errors.js.map +1 -0
  82. package/dist/internal/x509/extension-registry.js +157 -81
  83. package/dist/internal/x509/extension-registry.js.map +1 -1
  84. package/dist/internal/x509/general-name-profile.js +129 -0
  85. package/dist/internal/x509/general-name-profile.js.map +1 -0
  86. package/dist/internal/x509/general-name-tags.js +27 -0
  87. package/dist/internal/x509/general-name-tags.js.map +1 -0
  88. package/dist/internal/x509/general-name.js +183 -0
  89. package/dist/internal/x509/general-name.js.map +1 -0
  90. package/dist/internal/x509/name-fields.js +21 -12
  91. package/dist/internal/x509/name-fields.js.map +1 -1
  92. package/dist/internal/x509/or-address.js +217 -0
  93. package/dist/internal/x509/or-address.js.map +1 -0
  94. package/dist/keys/keys.d.ts +124 -95
  95. package/dist/keys/keys.js +362 -214
  96. package/dist/keys/keys.js.map +1 -1
  97. package/dist/keys.d.ts +3 -2
  98. package/dist/keys.js +3 -2
  99. package/dist/pem/pem.d.ts +17 -19
  100. package/dist/pem/pem.js +122 -41
  101. package/dist/pem/pem.js.map +1 -1
  102. package/dist/pem.js +1 -2
  103. package/dist/pkcs/pfx.d.ts +57 -32
  104. package/dist/pkcs/pfx.js +209 -173
  105. package/dist/pkcs/pfx.js.map +1 -1
  106. package/dist/pkcs/pkcs12-mac.d.ts +104 -27
  107. package/dist/pkcs/pkcs12-mac.js +266 -79
  108. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  109. package/dist/pkcs/pkcs7.d.ts +123 -53
  110. package/dist/pkcs/pkcs7.js +314 -238
  111. package/dist/pkcs/pkcs7.js.map +1 -1
  112. package/dist/pkcs.d.ts +5 -4
  113. package/dist/result/result.d.ts +43 -28
  114. package/dist/result/result.js +27 -14
  115. package/dist/result/result.js.map +1 -1
  116. package/dist/result.d.ts +2 -2
  117. package/dist/result.js +1 -2
  118. package/dist/revocation/chain.d.ts +101 -23
  119. package/dist/revocation/chain.js +456 -206
  120. package/dist/revocation/chain.js.map +1 -1
  121. package/dist/revocation/crl.d.ts +140 -65
  122. package/dist/revocation/crl.js +691 -391
  123. package/dist/revocation/crl.js.map +1 -1
  124. package/dist/revocation/ocsp.d.ts +145 -69
  125. package/dist/revocation/ocsp.js +347 -297
  126. package/dist/revocation/ocsp.js.map +1 -1
  127. package/dist/revocation/revocation.d.ts +48 -36
  128. package/dist/revocation/revocation.js +112 -63
  129. package/dist/revocation/revocation.js.map +1 -1
  130. package/dist/revocation.d.ts +5 -5
  131. package/dist/revocation.js +5 -5
  132. package/dist/verify/identity.d.ts +18 -20
  133. package/dist/verify/identity.js +120 -90
  134. package/dist/verify/identity.js.map +1 -1
  135. package/dist/verify/name-constraints.d.ts +1 -4
  136. package/dist/verify/policy.d.ts +15 -8
  137. package/dist/verify/verify.d.ts +86 -46
  138. package/dist/verify/verify.js +309 -143
  139. package/dist/verify/verify.js.map +1 -1
  140. package/dist/verify.d.ts +3 -2
  141. package/dist/verify.js +4 -3
  142. package/dist/x509/certificate.d.ts +50 -28
  143. package/dist/x509/certificate.js +69 -36
  144. package/dist/x509/certificate.js.map +1 -1
  145. package/dist/x509/csr.d.ts +9 -8
  146. package/dist/x509/csr.js +10 -11
  147. package/dist/x509/csr.js.map +1 -1
  148. package/dist/x509/extensions.d.ts +207 -82
  149. package/dist/x509/extensions.js +561 -128
  150. package/dist/x509/extensions.js.map +1 -1
  151. package/dist/x509/fingerprint.d.ts +4 -7
  152. package/dist/x509/fingerprint.js +1 -2
  153. package/dist/x509/fingerprint.js.map +1 -1
  154. package/dist/x509/name-text.d.ts +7 -9
  155. package/dist/x509/name-text.js +20 -4
  156. package/dist/x509/name-text.js.map +1 -1
  157. package/dist/x509/name.d.ts +15 -14
  158. package/dist/x509/name.js +23 -19
  159. package/dist/x509/name.js.map +1 -1
  160. package/dist/x509/parse.d.ts +165 -64
  161. package/dist/x509/parse.js +444 -459
  162. package/dist/x509/parse.js.map +1 -1
  163. package/dist/x509.d.ts +8 -5
  164. package/dist/x509.js +10 -8
  165. package/package.json +90 -65
@@ -1,21 +1,22 @@
1
- import { bitString as e, concatBytes as t, explicitContext as n, generalizedTime as r, implicitConstructedContext as i, implicitPrimitiveContext as a, integer as o, integerFromNumber as s, readElement as c, readRootElement as l, readSequenceChildren as u, sequence as d, time as f, tlv as p } from "../internal/asn1/der.js";
2
- import { childrenOf as m, decodeBoolean as h, decodeIntegerNumber as g, decodeObjectIdentifier as _, decodeString as v, extractBitStringValue as y, hexToBytes as b, parseTime as x, requireElement as S, toHex as C } from "../internal/asn1/asn1.js";
3
- import { OIDS as w } from "../internal/asn1/oids2.js";
4
- import { base64Encode as T } from "../internal/shared/base64.js";
5
- import { failureResult as E, rethrowIfInvariant as D, successResult as O } from "../result/result.js";
6
- import { pemDecodeOrThrow as k, pemEncode as A } from "../pem/pem.js";
7
- import { exportSpkiDer as j } from "../keys/keys.js";
8
- import { describeSignatureAlgorithm as M } from "../internal/crypto/algorithm-names.js";
9
- import { decodeIpAddress as N } from "../internal/shared/ip.js";
10
- import { encodeDistributionPointReasonFlagsContent as P, parseDistributionPointReasonFlagsContent as F } from "../internal/x509/extension-bits.js";
11
- import { nameFieldKeyFromOid as I } from "../internal/x509/name-fields.js";
12
- import { encodeName as L, encodeRelativeDistinguishedName as R } from "../x509/name.js";
13
- import { buildSubjectKeyIdentifier as z, encodeCrlDistributionPoints as B, encodeExtension as V, encodeSubjectAltName as H } from "../x509/extensions.js";
14
- import { parseCertificateDerOrThrow as U, parseCertificateFromSource as W } from "../x509/parse.js";
15
- import { verifySignedDataDetailed as G } from "../internal/crypto/sig-verify.js";
16
- import { encodeAlgorithmIdentifier as K, getSignatureAlgorithm as q, signBytes as J } from "../internal/crypto/signing.js";
17
- import { compareDistinguishedNames as Y, compareNameAttributeValue as X } from "../internal/shared/dn.js";
18
- //#region src/revocation/crl.ts
1
+ import { DECODE_REFUSAL_CODES as e, failureResult as t, rethrowIfInvariant as n, successResult as r, throwMicro509Error as i } from "../result/result.js";
2
+ import { decodeFailureResult as a, decodeRefusalOf as o, rethrowDecodeRefusal as s } from "../internal/asn1/decode-refusal.js";
3
+ import { bitString as c, concatBytes as l, explicitContext as u, generalizedTime as d, implicitConstructedContext as f, implicitPrimitiveContext as p, integer as m, integerFromNumber as h, optionalBytesEqual as ee, readElement as g, readRootElement as _, readSequenceChildren as v, sequence as y, time as b, tlv as x } from "../internal/asn1/der.js";
4
+ import { childrenOf as S, decodeBoolean as C, decodeIntegerMagnitude as w, decodeIntegerNumber as T, decodeNonNegativeIntegerBigInt as te, decodeObjectIdentifier as E, decodeString as D, extractBitStringValue as O, hexToBytes as k, parseTime as A, requireElement as j, toHex as M } from "../internal/asn1/asn1.js";
5
+ import { OIDS as N } from "../internal/asn1/oids2.js";
6
+ import { base64Encode as P } from "../internal/shared/base64.js";
7
+ import { pemDecodeOrThrow as F, pemEncode as I } from "../pem/pem.js";
8
+ import { verifySignedDataDetailed as L } from "../internal/crypto/sig-verify.js";
9
+ import { encodeAlgorithmIdentifier as R, getSignatureAlgorithm as ne, signBytes as re } from "../internal/crypto/signing.js";
10
+ import { describeSignatureAlgorithm as z } from "../internal/crypto/algorithm-names.js";
11
+ import { encodeDistributionPointReasonFlagsContent as B, parseDistributionPointReasonFlagsContent as V } from "../internal/x509/extension-bits.js";
12
+ import { parseGeneralName as H, parseGeneralNames as U } from "../internal/x509/general-name.js";
13
+ import { parsePresentedSrvName as W } from "../internal/x509/general-name-profile.js";
14
+ import { nameFieldKeyFromOid as G } from "../internal/x509/name-fields.js";
15
+ import { compareDistinguishedNames as K, compareRelativeDistinguishedNames as q } from "../internal/shared/dn.js";
16
+ import { encodeName as J, encodeRelativeDistinguishedName as Y, isNameInputEmpty as ie } from "../x509/name.js";
17
+ import { encodeCrlDistributionPoints as ae, encodeExtension as X, encodeSubjectAltName as oe, issuerKeyIdentifier as se } from "../x509/extensions.js";
18
+ import { parseCertificateDerOrThrow as ce, parseCertificateFromSource as Z } from "../x509/parse.js";
19
+ // src/revocation/crl.ts
19
20
  /**
20
21
  * Full CRL lifecycle: create, parse, verify, validate, and revocation check.
21
22
  *
@@ -25,7 +26,7 @@ import { compareDistinguishedNames as Y, compareNameAttributeValue as X } from "
25
26
  * @module
26
27
  */
27
28
  /** RFC 5280 §5.3.1 CRLReason integer codes, keyed by reason name. */
28
- const Z = {
29
+ const le = {
29
30
  unspecified: 0,
30
31
  keyCompromise: 1,
31
32
  cACompromise: 2,
@@ -36,12 +37,27 @@ const Z = {
36
37
  removeFromCRL: 8,
37
38
  privilegeWithdrawn: 9,
38
39
  aACompromise: 10
39
- };
40
+ }, Q = Object.freeze([
41
+ "keyCompromise",
42
+ "cACompromise",
43
+ "affiliationChanged",
44
+ "superseded",
45
+ "cessationOfOperation",
46
+ "certificateHold",
47
+ "privilegeWithdrawn",
48
+ "aACompromise"
49
+ ]);
50
+ /** True when `reasons` covers every RFC 5280 §4.2.1.13 reason — a complete-scope CRL verdict. */
51
+ function coversAllDistributionPointReasons(e) {
52
+ let t = e instanceof Set ? e : new Set(e);
53
+ return Q.every((e) => t.has(e));
54
+ }
40
55
  /**
41
56
  * Signs and encodes an X.509 v2 CRL.
42
57
  *
43
- * Embeds Authority Key Identifier, CRLNumber, delta CRL indicator,
44
- * issuing distribution point, and freshest-CRL extensions as configured.
58
+ * Always embeds the Authority Key Identifier and CRLNumber extensions
59
+ * (RFC 5280 §5.2), plus delta CRL indicator, issuing distribution point and
60
+ * freshest-CRL extensions as configured.
45
61
  *
46
62
  * @example
47
63
  * ```ts
@@ -50,7 +66,7 @@ const Z = {
50
66
  * const crl = await createCertificateRevocationList({
51
67
  * issuer: { commonName: 'Example CA' },
52
68
  * signerPrivateKey: caPrivateKey,
53
- * issuerPublicKey: caPublicKey,
69
+ * issuerCertificate: caCertificatePem,
54
70
  * thisUpdate: new Date('2025-01-01'),
55
71
  * nextUpdate: new Date('2025-02-01'),
56
72
  * crlNumber: 42,
@@ -61,24 +77,29 @@ const Z = {
61
77
  * // crl.pem, crl.der, crl.base64
62
78
  * ```
63
79
  */
64
- async function createCertificateRevocationList(t) {
65
- let r = q(t.signerPrivateKey), i = t.thisUpdate ?? /* @__PURE__ */ new Date(), a = t.nextUpdate, o = await buildCrlExtensions(t.issuerPublicKey, t.crlNumber, t.baseCrlNumber, t.issuingDistributionPoint, t.freshestCrlDistributionPoints), c = t.revokedCertificates ?? [], l = c.length === 0 ? [] : [d(c.map((e) => createRevokedCertificate(e, i)))], u = d([
66
- s(1),
67
- K(r),
68
- L(t.issuer),
69
- f(i),
70
- ...a === void 0 ? [] : [f(a)],
71
- ...l,
72
- ...o.length === 0 ? [] : [n(0, d(o))]
73
- ]), p = await J(t.signerPrivateKey, r, u), m = d([
74
- u,
75
- K(r),
76
- e(p)
80
+ async function createCertificateRevocationList(e) {
81
+ ie(e.issuer) && throwCrlEncoderError("issuer_distinguished_name_empty", "issuer must be a non-empty distinguished name");
82
+ let t = issuerCertificateOf(e.issuerCertificate), n = encodeCrlNumber(e.crlNumber, "crlNumber"), r = e.baseCrlNumber === void 0 ? void 0 : encodeCrlNumber(e.baseCrlNumber, "baseCrlNumber"), i = ne(e.signerPrivateKey), a = e.thisUpdate ?? /* @__PURE__ */ new Date(), o = e.nextUpdate;
83
+ assertCrlDate(a, "thisUpdate"), assertCrlDate(o, "nextUpdate");
84
+ for (let t of e.revokedCertificates ?? []) assertCrlDate(t.revocationDate, "revocationDate"), assertCrlDate(t.invalidityDate, "invalidityDate");
85
+ Math.floor(o.getTime() / 1e3) <= Math.floor(a.getTime() / 1e3) && throwCrlEncoderError("next_update_not_after_this_update", "nextUpdate must be at least one second later than thisUpdate");
86
+ let s = buildCrlExtensions(t, n, r, e.issuingDistributionPoint, e.freshestCrlDistributionPoints), l = e.revokedCertificates ?? [], d = l.length === 0 ? [] : [y(l.map((e) => createRevokedCertificate(e, a)))], f = y([
87
+ h(1),
88
+ R(i),
89
+ J(e.issuer),
90
+ b(a),
91
+ b(o),
92
+ ...d,
93
+ u(0, y(s))
94
+ ]), p = await re(e.signerPrivateKey, i, f), m = y([
95
+ f,
96
+ R(i),
97
+ c(p)
77
98
  ]);
78
99
  return {
79
100
  der: m,
80
- pem: A("X509 CRL", m),
81
- base64: T(m)
101
+ pem: I("X509 CRL", m),
102
+ base64: P(m)
82
103
  };
83
104
  }
84
105
  /**
@@ -88,19 +109,19 @@ async function createCertificateRevocationList(t) {
88
109
  * {@linkcode validateCertificateRevocationList} for that.
89
110
  */
90
111
  function parseCertificateRevocationListDerOrThrow(e) {
91
- let t = u(e, { maxDepth: 64 });
112
+ let t = v(e, { maxDepth: 64 });
92
113
  if (t.length !== 3) throw Error("Malformed CRL");
93
- let n = S(t[0], "TBSCertList"), r = S(t[1], "signatureAlgorithm"), i = S(t[2], "signatureValue"), a = parseSignedCrlFields(e.slice(n.start - n.headerLength, n.end)), o = parseAlgorithmIdentifier(e, r);
94
- return {
114
+ let n = j(t[0], "TBSCertList"), r = j(t[1], "signatureAlgorithm"), i = j(t[2], "signatureValue"), a = parseSignedCrlFields(e.slice(n.start - n.headerLength, n.end)), o = parseAlgorithmIdentifier(e, r);
115
+ return assertMatchingCrlSignatureAlgorithms(a.signature, o), {
95
116
  der: new Uint8Array(e),
96
117
  version: a.version,
97
118
  tbsCertListDer: e.slice(n.start - n.headerLength, n.end),
98
- signatureValue: y(i),
119
+ signatureValue: O(i),
99
120
  issuer: a.issuer,
100
121
  thisUpdate: a.thisUpdate,
101
122
  ...a.nextUpdate === void 0 ? {} : { nextUpdate: a.nextUpdate },
102
123
  signatureAlgorithmOid: o.oid,
103
- signatureAlgorithmName: M(o.oid, o.parametersDer),
124
+ signatureAlgorithmName: z(o.oid, o.parametersDer),
104
125
  ...o.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: o.parametersDer },
105
126
  ...a.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: a.authorityKeyIdentifier },
106
127
  ...a.crlNumber === void 0 ? {} : { crlNumber: a.crlNumber },
@@ -122,7 +143,7 @@ function parseCertificateRevocationListDerOrThrow(e) {
122
143
  * ```
123
144
  */
124
145
  function parseCertificateRevocationListPemOrThrow(e) {
125
- return parseCertificateRevocationListDerOrThrow(k("X509 CRL", e));
146
+ return parseCertificateRevocationListDerOrThrow(F("X509 CRL", e));
126
147
  }
127
148
  /**
128
149
  * Decodes a DER-encoded X.509 CRL into a structured {@linkcode ParsedCertificateRevocationList}.
@@ -132,11 +153,11 @@ function parseCertificateRevocationListPemOrThrow(e) {
132
153
  * Does not verify the signature — call {@linkcode verifyCertificateRevocationListSignature} or
133
154
  * {@linkcode validateCertificateRevocationList} for that.
134
155
  */
135
- function parseCertificateRevocationListDer(e) {
156
+ function parseCertificateRevocationListDer(t) {
136
157
  try {
137
- return O(parseCertificateRevocationListDerOrThrow(e));
138
- } catch (e) {
139
- return D(e), E("malformed", e instanceof Error ? e.message : "Malformed CRL");
158
+ return r(parseCertificateRevocationListDerOrThrow(t));
159
+ } catch (t) {
160
+ return n(t), a(t, e, "Malformed CRL");
140
161
  }
141
162
  }
142
163
  /**
@@ -145,11 +166,11 @@ function parseCertificateRevocationListDer(e) {
145
166
  * Returns a typed failure (`code: 'malformed'`) on malformed input. For the
146
167
  * throwing form use {@linkcode parseCertificateRevocationListPemOrThrow}.
147
168
  */
148
- function parseCertificateRevocationListPem(e) {
169
+ function parseCertificateRevocationListPem(t) {
149
170
  try {
150
- return O(parseCertificateRevocationListPemOrThrow(e));
151
- } catch (e) {
152
- return D(e), E("malformed", e instanceof Error ? e.message : "Malformed CRL");
171
+ return r(parseCertificateRevocationListPemOrThrow(t));
172
+ } catch (t) {
173
+ return n(t), a(t, e, "Malformed CRL");
153
174
  }
154
175
  }
155
176
  /**
@@ -158,58 +179,88 @@ function parseCertificateRevocationListPem(e) {
158
179
  * Does **not** check issuer name match, key-usage, or freshness — use
159
180
  * {@linkcode validateCertificateRevocationList} for full validation.
160
181
  */
161
- async function verifyCertificateRevocationListSignature(e, t) {
162
- let n, r;
182
+ async function verifyCertificateRevocationListSignature(t, n) {
183
+ let r, i;
163
184
  try {
164
- n = typeof e == "string" ? parseCertificateRevocationListPemOrThrow(e) : parseCertificateRevocationListDerOrThrow(new Uint8Array(e)), r = typeof t == "string" ? parseIssuerCertificatePem(t) : parseIssuerCertificateDer(new Uint8Array(t));
165
- } catch {
166
- return verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list or issuer certificate input is malformed");
185
+ r = typeof t == "string" ? parseCertificateRevocationListPemOrThrow(t) : parseCertificateRevocationListDerOrThrow(new Uint8Array(t)), i = typeof n == "string" ? parseIssuerCertificatePem(n) : parseIssuerCertificateDer(new Uint8Array(n));
186
+ } catch (t) {
187
+ let n = o(t, e);
188
+ return n === void 0 ? verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list or issuer certificate input is malformed") : verifyCertificateRevocationListFailureResult(n.code, n.message);
167
189
  }
168
- let i;
190
+ let a;
169
191
  try {
170
- i = await G(n.signatureAlgorithmOid, n.signatureAlgorithmParametersDer, r.publicKeyAlgorithmOid, r.publicKeyParametersOid, r.subjectPublicKeyInfoDer, n.signatureValue, n.tbsCertListDer);
171
- } catch {
172
- return verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed");
192
+ a = await L(r.signatureAlgorithmOid, r.signatureAlgorithmParametersDer, i.publicKeyAlgorithmOid, i.publicKeyParametersOid, i.subjectPublicKeyInfoDer, r.signatureValue, r.tbsCertListDer);
193
+ } catch (t) {
194
+ let n = o(t, e);
195
+ return n === void 0 ? verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed") : verifyCertificateRevocationListFailureResult(n.code, n.message);
173
196
  }
174
- return i.ok ? i.valid ? {
197
+ return a.ok ? a.valid ? {
175
198
  ok: !0,
176
- value: n
177
- } : verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify") : i.code === "verification_error" ? verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed") : verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature uses unsupported algorithm parameters");
199
+ value: r
200
+ } : verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify") : a.code === "verification_error" ? verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed") : verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature uses unsupported algorithm parameters");
178
201
  }
179
202
  /**
180
203
  * Full CRL validation: issuer name match, authority key identifier match,
181
- * cRLSign key-usage check, signature verification, and `thisUpdate`/`nextUpdate`
182
- * freshness check (with optional clock-skew tolerance).
204
+ * a v3 issuer certificate's key usage must be present and assert cRLSign
205
+ * (RFC 10007 §4), signature verification, `thisUpdate`/`nextUpdate`
206
+ * freshness check (with optional clock-skew tolerance), and the optional
207
+ * `maxAgeMs` bound on `thisUpdate`. A CRL that omits `nextUpdate` fails with
208
+ * `stale_crl` unless `maxAgeMs` is set.
183
209
  */
184
210
  async function validateCertificateRevocationList(e) {
185
- let t;
211
+ assertCrlMaxAge(e.maxAgeMs);
212
+ let t = await authenticateCrl(e.crl, e.issuerCertificate);
213
+ if (!t.ok) return t;
214
+ let n = crlFreshnessFailure(t.value, e.at ?? /* @__PURE__ */ new Date(), e.clockSkewMs ?? 0, e.maxAgeMs);
215
+ return n === void 0 ? t : validateCertificateRevocationListFailureResult("stale_crl", n);
216
+ }
217
+ /**
218
+ * Verifies the issuer binding, cRLSign permission and signature of `crl`
219
+ * against `issuerCertificate`, without freshness checks.
220
+ *
221
+ * @internal
222
+ */
223
+ async function authenticateCrl(t, n) {
224
+ let r;
186
225
  try {
187
- t = normalizeCrl(e.crl);
188
- } catch {
189
- return validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signed content is malformed");
226
+ r = normalizeCrl(t);
227
+ } catch (t) {
228
+ let n = o(t, e);
229
+ return n === void 0 ? validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signed content is malformed") : validateCertificateRevocationListFailureResult(n.code, n.message);
190
230
  }
191
- let n;
231
+ let i;
192
232
  try {
193
- n = normalizeCrlCertificate(e.issuerCertificate);
194
- } catch {
195
- return validateCertificateRevocationListFailureResult("signature_invalid", "issuer certificate input is malformed");
233
+ i = normalizeCrlCertificate(n);
234
+ } catch (t) {
235
+ let n = o(t, e);
236
+ return n === void 0 ? validateCertificateRevocationListFailureResult("signature_invalid", "issuer certificate input is malformed") : validateCertificateRevocationListFailureResult(n.code, n.message);
196
237
  }
197
- if (!Y(t.issuer, n.subject)) return validateCertificateRevocationListFailureResult("issuer_mismatch", "CRL issuer name does not match certificate subject");
198
- if (t.authorityKeyIdentifier !== void 0 && n.subjectKeyIdentifier !== void 0 && t.authorityKeyIdentifier !== n.subjectKeyIdentifier) return validateCertificateRevocationListFailureResult("issuer_mismatch", "CRL authority key identifier does not match issuer subject key identifier");
199
- if (n.keyUsage !== void 0 && !n.keyUsage.flags.includes("cRLSign")) return validateCertificateRevocationListFailureResult("crl_sign_not_permitted", "issuer certificate key usage does not permit CRL signing");
200
- let r;
238
+ if (!K(r.issuer, i.subject)) return validateCertificateRevocationListFailureResult("issuer_mismatch", "CRL issuer name does not match certificate subject");
239
+ if (r.authorityKeyIdentifier !== void 0 && i.subjectKeyIdentifier !== void 0 && r.authorityKeyIdentifier !== i.subjectKeyIdentifier) return validateCertificateRevocationListFailureResult("issuer_mismatch", "CRL authority key identifier does not match issuer subject key identifier");
240
+ if (i.keyUsage === void 0 && i.version === 3) return validateCertificateRevocationListFailureResult("crl_sign_not_permitted", "v3 issuer certificate has no key usage extension");
241
+ if (i.keyUsage !== void 0 && !i.keyUsage.flags.includes("cRLSign")) return validateCertificateRevocationListFailureResult("crl_sign_not_permitted", "issuer certificate key usage does not permit CRL signing");
242
+ let a;
201
243
  try {
202
- r = await G(t.signatureAlgorithmOid, t.signatureAlgorithmParametersDer, n.publicKeyAlgorithmOid, n.publicKeyParametersOid, n.subjectPublicKeyInfoDer, t.signatureValue, t.tbsCertListDer);
203
- } catch {
204
- return validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed");
244
+ a = await L(r.signatureAlgorithmOid, r.signatureAlgorithmParametersDer, i.publicKeyAlgorithmOid, i.publicKeyParametersOid, i.subjectPublicKeyInfoDer, r.signatureValue, r.tbsCertListDer);
245
+ } catch (t) {
246
+ let n = o(t, e);
247
+ return n === void 0 ? validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed") : validateCertificateRevocationListFailureResult(n.code, n.message);
205
248
  }
206
- if (!r.ok) return r.code === "verification_error" ? validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed") : validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature uses unsupported algorithm parameters");
207
- if (!r.valid) return validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify");
208
- let i = e.at ?? /* @__PURE__ */ new Date(), a = e.clockSkewMs ?? 0;
209
- return t.thisUpdate.getTime() - a > i.getTime() || t.nextUpdate !== void 0 && t.nextUpdate.getTime() + a < i.getTime() ? validateCertificateRevocationListFailureResult("stale_crl", "CRL is not valid at requested time") : {
249
+ return a.ok ? a.valid ? {
210
250
  ok: !0,
211
- value: t
212
- };
251
+ value: r
252
+ } : validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify") : a.code === "verification_error" ? validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed") : validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature uses unsupported algorithm parameters");
253
+ }
254
+ function assertCrlMaxAge(e) {
255
+ if (e !== void 0 && (!Number.isFinite(e) || e < 0)) throw RangeError(`Invalid maxAgeMs: must be a non-negative number, got ${e}`);
256
+ }
257
+ function crlFreshnessFailure(e, t, n, r) {
258
+ if (e.thisUpdate.getTime() - n > t.getTime() || e.nextUpdate !== void 0 && e.nextUpdate.getTime() + n < t.getTime()) return "CRL is not valid at requested time";
259
+ if (e.nextUpdate === void 0 && r === void 0) return "CRL has no nextUpdate and no maximum age is set";
260
+ if (r !== void 0 && t.getTime() - e.thisUpdate.getTime() > r + n) return "CRL thisUpdate is older than the maximum age";
261
+ }
262
+ function isCurrentDeltaCrl(e, t, n, r) {
263
+ return e.nextUpdate !== void 0 && crlFreshnessFailure(e, t, n, r) === void 0;
213
264
  }
214
265
  /**
215
266
  * End-to-end revocation check: validates the CRL (and optional delta CRL),
@@ -233,33 +284,75 @@ async function validateCertificateRevocationList(e) {
233
284
  * }
234
285
  * ```
235
286
  */
236
- async function checkCertificateRevocationAgainstCrl(e) {
237
- let t;
287
+ async function checkCertificateRevocationAgainstCrl(t) {
288
+ assertCrlMaxAge(t.maxAgeMs);
289
+ let n;
238
290
  try {
239
- t = normalizeCrlCertificate(e.certificate);
240
- } catch {
241
- return checkCertificateRevocationAgainstCrlFailureResult("non_applicable", "certificate input is malformed");
291
+ n = normalizeCrlCertificate(t.certificate);
292
+ } catch (t) {
293
+ let n = o(t, e);
294
+ return n === void 0 ? checkCertificateRevocationAgainstCrlFailureResult("non_applicable", "certificate input is malformed") : checkCertificateRevocationAgainstCrlFailureResult(n.code, n.message);
242
295
  }
243
- let n = await validateCertificateRevocationList({
244
- crl: e.crl,
245
- issuerCertificate: e.issuerCertificate,
246
- ...e.at === void 0 ? {} : { at: e.at },
247
- ...e.clockSkewMs === void 0 ? {} : { clockSkewMs: e.clockSkewMs }
248
- });
249
- if (!n.ok) return checkCertificateRevocationAgainstCrlFailureResult(n.code, n.message);
250
- let r = await validateOptionalDeltaCrl(e, n.value);
251
- if (!r.ok) return r;
252
- let i = checkCrlAndDeltaApplicability(t, n.value, r.value);
253
- if (i !== void 0) return i;
254
- let a = findRevokedCertificateEntry(t, n.value);
255
- if (!a.ok) return a;
256
- let o;
257
- if (r.value !== void 0) {
258
- let e = findRevokedCertificateEntry(t, r.value);
259
- if (!e.ok) return e;
260
- o = e.entry;
296
+ let r = await authenticateCrl(t.crl, t.issuerCertificate);
297
+ if (!r.ok) return checkCertificateRevocationAgainstCrlFailureResult(r.code, r.message);
298
+ let i = await checkRevocationAgainstAuthenticatedCrl(n, r.value, t);
299
+ return i.kind === "checked" ? i.result : i.failure;
300
+ }
301
+ /**
302
+ * Checks `certificate` against a complete CRL that {@linkcode authenticateCrl}
303
+ * accepted for `input.issuerCertificate`, updated by `input.deltaCrl` when given.
304
+ *
305
+ * @internal
306
+ */
307
+ async function checkRevocationAgainstAuthenticatedCrl(e, t, n) {
308
+ if (n.deltaCrl === void 0) {
309
+ let e = crlFreshnessFailure(t, n.at ?? /* @__PURE__ */ new Date(), n.clockSkewMs ?? 0, n.maxAgeMs);
310
+ if (e !== void 0) return {
311
+ kind: "checked",
312
+ result: checkCertificateRevocationAgainstCrlFailureResult("stale_crl", e)
313
+ };
314
+ }
315
+ let r = await validateOptionalDeltaCrl(n, t);
316
+ if (!r.ok) return {
317
+ kind: "delta_rejected",
318
+ failure: r
319
+ };
320
+ let i = r.value, a = checkCrlApplicability(e, t);
321
+ if (!a.ok) return {
322
+ kind: "checked",
323
+ result: a.failure
324
+ };
325
+ if (i !== void 0) {
326
+ let t = checkCrlApplicability(e, i, !0);
327
+ if (!t.ok) return {
328
+ kind: "delta_rejected",
329
+ failure: t.failure
330
+ };
331
+ }
332
+ let o = findRevokedCertificateEntry(e, t);
333
+ if (!o.ok) return {
334
+ kind: "checked",
335
+ result: o
336
+ };
337
+ let s;
338
+ if (i !== void 0) {
339
+ let r = findRevokedCertificateEntry(e, i);
340
+ if (!r.ok) return {
341
+ kind: "delta_unresolved",
342
+ failure: r,
343
+ complete: resolveCertificateRevocationStatus(e, void 0, t, o.entry, void 0, a.coveredReasons, n.unrecognizedReasonCode ?? "revoked")
344
+ };
345
+ s = r.entry;
261
346
  }
262
- return resolveCertificateRevocationStatus(t, e.at ?? /* @__PURE__ */ new Date(), n.value, a.entry, o);
347
+ return {
348
+ kind: "checked",
349
+ result: resolveCertificateRevocationStatus(e, i?.thisUpdate, t, o.entry, s, a.coveredReasons, n.unrecognizedReasonCode ?? "revoked")
350
+ };
351
+ }
352
+ /** RFC 5280 §6.3.3 (d): interim_reasons_mask from the matched DP and the CRL's IDP. */
353
+ function interimReasonsMask(e, t) {
354
+ let n = e?.reasons?.flags, r = t?.onlySomeReasons?.flags;
355
+ return n !== void 0 && r !== void 0 ? n.filter((e) => r.includes(e)) : n === void 0 ? r === void 0 ? Q : [...r] : [...n];
263
356
  }
264
357
  /** Validates an optional delta CRL and checks compatibility with its complete CRL. */
265
358
  async function validateOptionalDeltaCrl(e, t) {
@@ -268,28 +361,33 @@ async function validateOptionalDeltaCrl(e, t) {
268
361
  crl: e.deltaCrl,
269
362
  issuerCertificate: e.issuerCertificate,
270
363
  ...e.at === void 0 ? {} : { at: e.at },
271
- ...e.clockSkewMs === void 0 ? {} : { clockSkewMs: e.clockSkewMs }
364
+ ...e.clockSkewMs === void 0 ? {} : { clockSkewMs: e.clockSkewMs },
365
+ ...e.maxAgeMs === void 0 ? {} : { maxAgeMs: e.maxAgeMs }
272
366
  });
273
- return n.ok ? checkDeltaCrlCompatibility(t, n.value) ?? {
367
+ if (!n.ok) return checkCertificateRevocationAgainstCrlFailureResult(n.code, n.message);
368
+ if (n.value.nextUpdate === void 0) return checkCertificateRevocationAgainstCrlFailureResult("stale_crl", "delta CRL has no nextUpdate");
369
+ let r;
370
+ try {
371
+ r = checkDeltaCrlCompatibility(t, n.value);
372
+ } catch (e) {
373
+ return crlNameRefusalFailure(e);
374
+ }
375
+ return r ?? {
274
376
  ok: !0,
275
377
  value: n.value
276
- } : checkCertificateRevocationAgainstCrlFailureResult(n.code, n.message);
277
- }
278
- function checkCrlAndDeltaApplicability(e, t, n) {
279
- let r = checkCrlApplicability(e, t);
280
- return r === void 0 ? n === void 0 ? void 0 : checkCrlApplicability(e, n, !0) : r;
378
+ };
281
379
  }
282
380
  /** Builds a `VerifyCertificateRevocationListSignatureFailureResult`. */
283
- function verifyCertificateRevocationListFailureResult(e, t) {
284
- return E(e, t);
381
+ function verifyCertificateRevocationListFailureResult(e, n) {
382
+ return t(e, n);
285
383
  }
286
384
  /** Builds a `ValidateCertificateRevocationListFailureResult`. */
287
- function validateCertificateRevocationListFailureResult(e, t) {
288
- return E(e, t);
385
+ function validateCertificateRevocationListFailureResult(e, n) {
386
+ return t(e, n);
289
387
  }
290
388
  /** Builds a `CheckCertificateRevocationAgainstCrlFailureResult`. */
291
- function checkCertificateRevocationAgainstCrlFailureResult(e, t, n) {
292
- return E(e, t, n);
389
+ function checkCertificateRevocationAgainstCrlFailureResult(e, n, r) {
390
+ return t(e, n, r);
293
391
  }
294
392
  /** Wraps a success value into a `CheckCertificateRevocationAgainstCrlResult`. */
295
393
  function checkCertificateRevocationAgainstCrlSuccess(e) {
@@ -303,11 +401,18 @@ function checkCertificateRevocationAgainstCrlSuccess(e) {
303
401
  * CRL's revoked entries. Does **not** validate the CRL or check applicability.
304
402
  */
305
403
  function isCertificateRevoked(e, t) {
306
- let n = typeof e == "string" ? normalizeHex(e) : C(e);
404
+ let n = typeof e == "string" ? normalizeHex(e) : M(e);
307
405
  return t.revokedCertificates.some((e) => normalizeHex(e.serialNumberHex) === n);
308
406
  }
309
407
  /** Searches CRL entries for the certificate's serial, respecting indirect-CRL issuer overrides. */
310
408
  function findRevokedCertificateEntry(e, t) {
409
+ try {
410
+ return lookupRevokedCertificateEntry(e, t);
411
+ } catch (e) {
412
+ return crlNameRefusalFailure(e);
413
+ }
414
+ }
415
+ function lookupRevokedCertificateEntry(e, t) {
311
416
  let n = normalizeHex(e.serialNumberHex), r, i = !1, a;
312
417
  for (let o of t.revokedCertificates) {
313
418
  if (o.certificateIssuer !== void 0 && (r = o.certificateIssuer), normalizeHex(o.serialNumberHex) !== n) continue;
@@ -315,112 +420,180 @@ function findRevokedCertificateEntry(e, t) {
315
420
  if (s === "match") {
316
421
  if (a !== void 0) return checkCertificateRevocationAgainstCrlFailureResult("signature_invalid", "CRL contains multiple revoked entries for certificate");
317
422
  a = o;
318
- continue;
319
- }
320
- s === "unsupported" && (i = !0);
423
+ } else s === "unsupported" && (i = !0);
321
424
  }
322
425
  return a === void 0 ? i ? nonApplicable("unsupported_indirect_crl", "indirect CRL entry certificateIssuer must include a directoryName") : { ok: !0 } : {
323
426
  ok: !0,
324
427
  entry: a
325
428
  };
326
429
  }
430
+ /**
431
+ * Whether `crl` covers `certificate` under {@linkcode checkCrlApplicability}.
432
+ *
433
+ * @internal
434
+ */
435
+ function isCrlApplicableTo(e, t) {
436
+ return checkCrlApplicability(e, t).ok;
437
+ }
327
438
  /** RFC 5280 §6.3 CRL applicability: scope, distribution-point, reason, and indirect-CRL checks. */
328
439
  function checkCrlApplicability(e, t, n = !1) {
329
- if (!n && t.baseCrlNumber !== void 0) return nonApplicable("unsupported_delta_crl", "a delta CRL cannot be used as the primary complete CRL input");
440
+ try {
441
+ return evaluateCrlApplicability(e, t, n);
442
+ } catch (e) {
443
+ return {
444
+ ok: !1,
445
+ failure: crlNameRefusalFailure(e)
446
+ };
447
+ }
448
+ }
449
+ function evaluateCrlApplicability(e, t, n) {
450
+ if (!n && t.baseCrlNumber !== void 0) return notApplicableOutcome("unsupported_delta_crl", "a delta CRL cannot be used as the primary complete CRL input");
330
451
  let r = t.issuingDistributionPoint, i = r?.indirectCrl === !0;
331
- if (!i && !Y(e.issuer, t.issuer)) return nonApplicable("issuer_mismatch", "CRL issuer does not match certificate issuer for direct CRL processing");
332
- if (r?.onlyContainsAttributeCerts === !0) return nonApplicable("certificate_scope_mismatch", "attribute-certificate-only CRLs are not applicable to public-key certificates");
452
+ if (!i && !K(e.issuer, t.issuer)) return notApplicableOutcome("issuer_mismatch", "CRL issuer does not match certificate issuer for direct CRL processing");
453
+ if (r?.onlyContainsAttributeCerts === !0) return notApplicableOutcome("certificate_scope_mismatch", "attribute-certificate-only CRLs are not applicable to public-key certificates");
333
454
  let a = e.basicConstraints?.ca === !0;
334
- if (r?.onlyContainsUserCerts === !0 && a) return nonApplicable("certificate_scope_mismatch", "CRL only applies to end-entity certificates");
335
- if (r?.onlyContainsCACerts === !0 && !a) return nonApplicable("certificate_scope_mismatch", "CRL only applies to CA certificates");
455
+ if (r?.onlyContainsUserCerts === !0 && a) return notApplicableOutcome("certificate_scope_mismatch", "CRL only applies to end-entity certificates");
456
+ if (r?.onlyContainsCACerts === !0 && !a) return notApplicableOutcome("certificate_scope_mismatch", "CRL only applies to CA certificates");
336
457
  let o = e.crlDistributionPoints ?? [];
337
- return o.length === 0 ? r?.distributionPoint === void 0 ? i && !Y(e.issuer, t.issuer) ? nonApplicable("issuer_mismatch", "indirect CRLs for alternate certificate issuers require matching CRLIssuer distribution points") : void 0 : nonApplicable("distribution_point_mismatch", "certificates without CRL distribution points only accept full-scope CRLs") : crlDistributionPointScanFailure(scanCrlDistributionPoints(o, e, t, r, i));
458
+ if (o.length === 0) return r?.distributionPoint !== void 0 && !matchesDistributionPointName(issuerFallbackDistributionPointName(e), r.distributionPoint, t.issuer, void 0) ? notApplicableOutcome("distribution_point_mismatch", "CRL issuing distribution point does not name the certificate issuer") : i && !K(e.issuer, t.issuer) ? notApplicableOutcome("issuer_mismatch", "indirect CRLs for alternate certificate issuers require matching CRLIssuer distribution points") : {
459
+ ok: !0,
460
+ coveredReasons: interimReasonsMask(void 0, r)
461
+ };
462
+ let s = scanCrlDistributionPoints(o, e, t, r, i);
463
+ return typeof s == "string" ? {
464
+ ok: !1,
465
+ failure: crlDistributionPointScanFailure(s)
466
+ } : {
467
+ ok: !0,
468
+ coveredReasons: s.coveredReasons
469
+ };
338
470
  }
339
- /** Aggregates distribution-point matching outcomes across a certificate. */
471
+ /** Wraps a non-applicability failure into a {@linkcode CrlApplicabilityOutcome}. */
472
+ function notApplicableOutcome(e, t) {
473
+ return {
474
+ ok: !1,
475
+ failure: nonApplicable(e, t)
476
+ };
477
+ }
478
+ /**
479
+ * RFC 5280 §6.3.3 final paragraph: for a certificate without a CRLDP extension,
480
+ * assume a distribution point named by the certificate issuer and its
481
+ * issuerAltName entries, with reasons and cRLIssuer omitted.
482
+ */
483
+ function issuerFallbackDistributionPointName(e) {
484
+ return {
485
+ type: "fullName",
486
+ fullName: [{
487
+ type: "directoryName",
488
+ derHex: e.issuer.derHex
489
+ }, ...e.issuerAltNames ?? []]
490
+ };
491
+ }
492
+ /**
493
+ * Aggregates distribution-point matching across a certificate.
494
+ *
495
+ * RFC 5280 §6.3.3 processes every corresponding DP, so when several match the same CRL their
496
+ * interim reason masks (d) are unioned rather than stopping at the first.
497
+ */
340
498
  function scanCrlDistributionPoints(e, t, n, r, i) {
341
- let a = !1, o = !1, s = !1, c = !1, l = !1;
342
- for (let u of e) {
343
- let e = scanCrlDistributionPoint(u, t, n, r, i);
344
- if (e === "matched") return e;
345
- e === "indirect_distribution_point" && (a = !0), e === "distribution_point_mismatch" && (o = !0), e === "indirect_issuer_mismatch" && (s = !0), e === "unsupported_indirect_crl_issuer" && (c = !0), e === "reasons_mismatch" && (l = !0);
499
+ let a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), s = !1;
500
+ for (let c of e) {
501
+ let e = scanCrlDistributionPoint(c, t, n, r, i);
502
+ if (e === "matched") {
503
+ s = !0;
504
+ for (let e of interimReasonsMask(c, r)) a.add(e);
505
+ } else o.add(e);
346
506
  }
347
- return l ? "reasons_mismatch" : c ? "unsupported_indirect_crl_issuer" : s ? "indirect_issuer_mismatch" : o ? "distribution_point_mismatch" : a ? "indirect_distribution_point" : "scope_mismatch";
507
+ return s ? { coveredReasons: [...a] } : resolveScanFailure(o);
508
+ }
509
+ /** Reports the highest-precedence distribution-point scan failure. */
510
+ function resolveScanFailure(e) {
511
+ return [
512
+ "reasons_mismatch",
513
+ "unsupported_indirect_crl_issuer",
514
+ "indirect_issuer_mismatch",
515
+ "distribution_point_mismatch",
516
+ "indirect_distribution_point"
517
+ ].find((t) => e.has(t)) ?? "scope_mismatch";
348
518
  }
349
519
  function scanCrlDistributionPoint(e, t, n, r, i) {
350
520
  let a = scanCrlDistributionPointIssuer(e, t, n, i);
351
- return a === void 0 ? matchesDistributionPointName(e.distributionPoint, r?.distributionPoint, n.issuer) ? hasOverlappingReasons(e.reasons, r?.onlySomeReasons) ? "matched" : "reasons_mismatch" : "distribution_point_mismatch" : a;
521
+ return a === void 0 ? matchesDistributionPointName(e.distributionPoint, r?.distributionPoint, n.issuer, e.crlIssuer) ? hasOverlappingReasons(e.reasons, r?.onlySomeReasons) ? "matched" : "reasons_mismatch" : "distribution_point_mismatch" : a;
352
522
  }
353
523
  function scanCrlDistributionPointIssuer(e, t, n, r) {
354
524
  if (!r) return e.crlIssuer === void 0 ? void 0 : "indirect_distribution_point";
355
- if (Y(t.issuer, n.issuer) && e.crlIssuer === void 0) return;
525
+ if (K(t.issuer, n.issuer) && e.crlIssuer === void 0) return;
356
526
  let i = matchesIndirectCrlIssuer(e.crlIssuer, n);
357
527
  return i === "unsupported" ? "unsupported_indirect_crl_issuer" : i ? void 0 : "indirect_issuer_mismatch";
358
528
  }
359
529
  function crlDistributionPointScanFailure(e) {
360
- if (e !== "matched") return e === "reasons_mismatch" ? nonApplicable("reasons_mismatch", "certificate distribution point reasons do not overlap the CRL reason scope") : e === "unsupported_indirect_crl_issuer" ? nonApplicable("unsupported_indirect_crl", "indirect CRL distribution points must identify the CRL issuer with directoryName") : e === "indirect_issuer_mismatch" ? nonApplicable("issuer_mismatch", "certificate distribution points do not authorize this indirect CRL issuer") : e === "distribution_point_mismatch" ? nonApplicable("distribution_point_mismatch", "certificate distribution points do not match the CRL issuing distribution point") : e === "indirect_distribution_point" ? nonApplicable("unsupported_indirect_crl", "certificate distribution points that name alternate CRL issuers are not supported yet") : nonApplicable("distribution_point_mismatch", "certificate distribution points do not match the CRL scope");
530
+ return e === "reasons_mismatch" ? nonApplicable("reasons_mismatch", "certificate distribution point reasons do not overlap the CRL reason scope") : e === "unsupported_indirect_crl_issuer" ? nonApplicable("unsupported_indirect_crl", "indirect CRL distribution points must identify the CRL issuer with directoryName") : e === "indirect_issuer_mismatch" ? nonApplicable("issuer_mismatch", "certificate distribution points do not authorize this indirect CRL issuer") : e === "distribution_point_mismatch" ? nonApplicable("distribution_point_mismatch", "certificate distribution points do not match the CRL issuing distribution point") : e === "indirect_distribution_point" ? nonApplicable("unsupported_indirect_crl", "certificate distribution points that name alternate CRL issuers are not supported yet") : nonApplicable("distribution_point_mismatch", "certificate distribution points do not match the CRL scope");
361
531
  }
362
532
  /** Verifies that a delta CRL is compatible with the given complete CRL (same issuer, AKI, IDP, and valid numbering). */
363
533
  function checkDeltaCrlCompatibility(e, t) {
364
534
  if (e.baseCrlNumber !== void 0) return nonApplicable("delta_crl_incompatible", "complete CRL input must not itself be a delta CRL");
365
535
  if (t.baseCrlNumber === void 0) return nonApplicable("delta_crl_incompatible", "delta CRL input must include a delta CRL indicator");
366
- if (!Y(e.issuer, t.issuer)) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same issuer");
536
+ if (!K(e.issuer, t.issuer)) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same issuer");
367
537
  if (e.authorityKeyIdentifier !== t.authorityKeyIdentifier) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same authority key identifier");
368
538
  if (!sameIssuingDistributionPoint(e.issuingDistributionPoint, t.issuingDistributionPoint)) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same issuing distribution point scope");
369
539
  if (e.crlNumber === void 0 || t.crlNumber === void 0) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must both carry CRL numbers for delta processing");
370
540
  if (e.crlNumber < t.baseCrlNumber) return nonApplicable("delta_crl_incompatible", "delta CRL base number must not exceed the complete CRL number");
371
541
  if (e.crlNumber >= t.crlNumber) return nonApplicable("delta_crl_incompatible", "delta CRL number must be newer than the complete CRL number");
542
+ if (e.thisUpdate.getTime() > t.thisUpdate.getTime()) return nonApplicable("delta_crl_incompatible", "delta CRL thisUpdate must not precede the complete CRL thisUpdate");
372
543
  }
373
544
  /** Checks whether any `crlIssuer` GeneralName matches the CRL's issuer via directoryName DER comparison. */
374
545
  function matchesIndirectCrlIssuer(e, t) {
375
546
  if (e === void 0) return !1;
376
547
  let n = !1;
377
- for (let r of e) {
378
- if (r.type === "directoryName") {
379
- if (directoryNameDerHexMatchesParsedName(r.derHex, t.issuer)) return !0;
380
- continue;
381
- }
382
- n = !0;
383
- }
548
+ for (let r of e) if (r.type === "directoryName") {
549
+ if (directoryNameDerHexMatchesParsedName(r.derHex, t.issuer)) return !0;
550
+ } else n = !0;
384
551
  return n ? "unsupported" : !1;
385
552
  }
386
553
  /** Determines whether a revoked entry's effective issuer matches the certificate's issuer. */
387
554
  function matchesRevokedEntryIssuer(e, t, n) {
388
- if (n === void 0) return Y(e.issuer, t.issuer) ? "match" : "mismatch";
555
+ if (n === void 0) return K(e.issuer, t.issuer) ? "match" : "mismatch";
389
556
  let r = !1;
390
- for (let t of n) {
391
- if (t.type === "directoryName") {
392
- if (directoryNameDerHexMatchesParsedName(t.derHex, e.issuer)) return "match";
393
- continue;
394
- }
395
- r = !0;
396
- }
557
+ for (let t of n) if (t.type === "directoryName") {
558
+ if (directoryNameDerHexMatchesParsedName(t.derHex, e.issuer)) return "match";
559
+ } else r = !0;
397
560
  return r ? "unsupported" : "mismatch";
398
561
  }
399
562
  /** Shorthand for building a `non_applicable` failure result with the given reason. */
400
563
  function nonApplicable(e, t) {
401
564
  return checkCertificateRevocationAgainstCrlFailureResult("non_applicable", t, { reason: e });
402
565
  }
403
- /** Merges complete and delta CRL entries per RFC 5280 §5.2.4 to produce a final `good`/`revoked` status. */
404
- function resolveCertificateRevocationStatus(e, t, n, r, i) {
405
- if (i !== void 0) if (i.reasonCode === "removeFromCRL") {
406
- if (r?.reasonCode === "certificateHold" || e.notAfter.getTime() < t.getTime()) return checkCertificateRevocationAgainstCrlSuccess({
407
- status: "good",
408
- crl: n
409
- });
410
- } else return checkCertificateRevocationAgainstCrlSuccess({
411
- status: "revoked",
412
- crl: n,
413
- revocationDate: i.revocationDate,
414
- ...i.reasonCode === void 0 ? {} : { reasonCode: i.reasonCode }
415
- });
416
- return checkCertificateRevocationAgainstCrlSuccess(r === void 0 ? {
566
+ /**
567
+ * Merges complete and delta CRL entries into a final `good`/`revoked` status
568
+ * per the RFC 5280 §6.3.3 (i)-(k) relying-party algorithm.
569
+ *
570
+ * Deliberately harder than (i)-(k) on `removeFromCRL`: the entry clears a
571
+ * revocation only in the two situations §5.2.4(b)/§5.3.1 permit an issuer to
572
+ * emit it, a complete-CRL `certificateHold` entry or a certificate that
573
+ * expired before the delta CRL's thisUpdate.
574
+ */
575
+ function resolveCertificateRevocationStatus(e, t, n, r, i, a, o) {
576
+ if (i !== void 0) {
577
+ if (i.reasonCode === "removeFromCRL") {
578
+ if (r?.reasonCode === "certificateHold" || t !== void 0 && e.notAfter.getTime() < t.getTime()) return checkCertificateRevocationAgainstCrlSuccess({
579
+ status: "good",
580
+ crl: n,
581
+ coveredReasons: a
582
+ });
583
+ } else return revokedEntryResult(n, i, o);
584
+ }
585
+ return r === void 0 ? checkCertificateRevocationAgainstCrlSuccess({
417
586
  status: "good",
418
- crl: n
419
- } : {
420
- status: "revoked",
421
587
  crl: n,
422
- revocationDate: r.revocationDate,
423
- ...r.reasonCode === void 0 ? {} : { reasonCode: r.reasonCode }
588
+ coveredReasons: a
589
+ }) : revokedEntryResult(n, r, o);
590
+ }
591
+ function revokedEntryResult(e, t, n) {
592
+ return n === "reject" && typeof t.reasonCode == "object" ? checkCertificateRevocationAgainstCrlFailureResult("reason_code_unrecognized", `CRL entry carries unrecognized reason code ${String(t.reasonCode.code)}`) : checkCertificateRevocationAgainstCrlSuccess({
593
+ status: "revoked",
594
+ crl: e,
595
+ revocationDate: t.revocationDate,
596
+ ...t.reasonCode === void 0 ? {} : { reasonCode: t.reasonCode }
424
597
  });
425
598
  }
426
599
  /**
@@ -430,29 +603,41 @@ function resolveCertificateRevocationStatus(e, t, n, r, i) {
430
603
  * the full distribution point name is formed by appending that RDN to the CRL issuer's DN.
431
604
  * This resolved name is then compared against the CRL's IDP fullName directoryName entries.
432
605
  */
433
- function matchesDistributionPointName(e, t, n) {
606
+ function matchesDistributionPointName(e, t, n, r) {
434
607
  if (t === void 0) return !0;
435
- if (e === void 0) return !1;
436
- if (e.fullName !== void 0 && t.fullName !== void 0) return e.fullName.some((e) => t.fullName?.some((t) => compareGeneralNames(e, t)) === !0);
437
- if (e.relativeName !== void 0 && t.fullName !== void 0) {
608
+ if (e === void 0) return matchesIdpNameAgainstCrlIssuer(t, r, n);
609
+ if (e.type === "fullName" && t.type === "fullName") return e.fullName.some((e) => t.fullName.some((t) => compareGeneralNames(e, t)));
610
+ if (e.type === "relativeName" && t.type === "fullName") {
438
611
  let r = resolveRelativeNameToDnHex(n, e.relativeName);
439
612
  return t.fullName.some((e) => e.type === "directoryName" && e.derHex === r);
440
613
  }
441
- if (e.relativeName !== void 0 && t.relativeName !== void 0) return compareRelativeDistinguishedNames(e.relativeName, t.relativeName);
442
- if (e.fullName !== void 0 && t.relativeName !== void 0) {
614
+ if (e.type === "relativeName" && t.type === "relativeName") return q(e.relativeName, t.relativeName);
615
+ if (e.type === "fullName" && t.type === "relativeName") {
443
616
  let r = resolveRelativeNameToDnHex(n, t.relativeName);
444
617
  return e.fullName.some((e) => e.type === "directoryName" && e.derHex === r);
445
618
  }
446
619
  return !1;
447
620
  }
621
+ /**
622
+ * RFC 5280 §6.3.3 (b)(2)(i): when the certificate's distribution point omits the
623
+ * distributionPoint field, match the CRL IDP's distributionPoint names against
624
+ * the distribution point's `cRLIssuer` names.
625
+ */
626
+ function matchesIdpNameAgainstCrlIssuer(e, t, n) {
627
+ if (t === void 0) return !1;
628
+ if (e.type === "fullName") return t.some((t) => e.fullName.some((e) => compareGeneralNames(t, e)));
629
+ let r = resolveRelativeNameToDnHex(n, e.relativeName);
630
+ return t.some((e) => e.type === "directoryName" && e.derHex === r);
631
+ }
448
632
  /** Constructs a full DN by appending an RDN to an existing Name, returning hex-encoded DER. */
449
633
  function resolveRelativeNameToDnHex(e, t) {
450
- let n = e.rdns.map((e) => b(e.derHex)), r = rebuildRelativeNameAsSet(b(t.derHex));
451
- return n.push(r), C(d(n));
634
+ let n = e.rdns.map((e) => k(e.derHex)), r = rebuildRelativeNameAsSet(k(t.derHex));
635
+ return n.push(r), M(y(n));
452
636
  }
453
637
  /** Converts an implicit-tagged [1] relativeName to a proper SET-tagged RDN. */
454
638
  function rebuildRelativeNameAsSet(e) {
455
- return p(49, l(e, { maxDepth: 64 }).value);
639
+ let t = _(e, { maxDepth: 64 });
640
+ return x(49, t.value);
456
641
  }
457
642
  /** Deep-compares two issuing distribution point extensions for delta-CRL compatibility. */
458
643
  function sameIssuingDistributionPoint(e, t) {
@@ -460,7 +645,7 @@ function sameIssuingDistributionPoint(e, t) {
460
645
  }
461
646
  /** Compares two DistributionPointName values (fullName set or relativeName). */
462
647
  function sameDistributionPointName(e, t) {
463
- return e === void 0 || t === void 0 ? e === t : e.fullName !== void 0 || t.fullName !== void 0 ? e.fullName === void 0 || t.fullName === void 0 ? !1 : sameGeneralNameSet(e.fullName, t.fullName) : e.relativeName === void 0 || t.relativeName === void 0 ? !1 : compareRelativeDistinguishedNames(e.relativeName, t.relativeName);
648
+ return e === void 0 || t === void 0 ? e === t : e.type === "fullName" && t.type === "fullName" ? sameGeneralNameSet(e.fullName, t.fullName) : e.type === "relativeName" && t.type === "relativeName" && q(e.relativeName, t.relativeName);
464
649
  }
465
650
  /** Set-equality comparison for GeneralName arrays (order-independent). */
466
651
  function sameGeneralNameSet(e, t) {
@@ -489,12 +674,105 @@ function hasOverlappingReasons(e, t) {
489
674
  }
490
675
  /** Value-equality for two GeneralName entries, using DER comparison for directoryName. */
491
676
  function compareGeneralNames(e, t) {
492
- if (e.type === "dns" && t.type === "dns" || e.type === "email" && t.type === "email" || e.type === "ip" && t.type === "ip" || e.type === "uri" && t.type === "uri") return e.value === t.value;
677
+ if (e.type === "dns" && t.type === "dns") return e.value.toLowerCase() === t.value.toLowerCase();
678
+ if (e.type === "srv" && t.type === "srv") return compareSrvNames(e.value.toLowerCase(), t.value.toLowerCase());
679
+ if (e.type === "email" && t.type === "email") return compareRfc822Names(e.value, t.value);
680
+ if (e.type === "smtpUtf8Mailbox" && t.type === "smtpUtf8Mailbox" || e.type === "ip" && t.type === "ip") return e.value === t.value;
681
+ if (e.type === "uri" && t.type === "uri") return compareUniformResourceIdentifiers(e.value, t.value);
493
682
  if (e.type === "directoryName" && t.type === "directoryName") {
494
683
  let n = parseDerHexName(e.derHex), r = parseDerHexName(t.derHex);
495
- return n === void 0 || r === void 0 ? !1 : Y(n, r);
684
+ return n === void 0 || r === void 0 ? !1 : K(n, r);
496
685
  }
497
- return e.type === "unknown" && t.type === "unknown" && e.tag === t.tag && bytesEqual(e.value, t.value);
686
+ return compareOpaqueGeneralNames(e, t);
687
+ }
688
+ function compareSrvNames(e, t) {
689
+ let n = W(e), r = W(t);
690
+ return n === void 0 || r === void 0 ? e === t : n.service === r.service && n.name === r.name;
691
+ }
692
+ /** Encoding equality for the GeneralName alternatives carried as DER or an OID. */
693
+ function compareOpaqueGeneralNames(e, t) {
694
+ return e.type === "otherName" && t.type === "otherName" ? e.typeId === t.typeId && bytesEqual(e.value, t.value) : e.type === "upn" && t.type === "upn" ? e.value === t.value : e.type === "krb5PrincipalName" && t.type === "krb5PrincipalName" ? e.realm === t.realm && e.nameType === t.nameType && e.nameString.length === t.nameString.length && e.nameString.every((e, n) => e === t.nameString[n]) : e.type === "x400Address" && t.type === "x400Address" || e.type === "ediPartyName" && t.type === "ediPartyName" ? bytesEqual(e.value, t.value) : e.type === "registeredID" && t.type === "registeredID" ? e.value === t.value : e.type === "unknown" && t.type === "unknown" && e.tag === t.tag && bytesEqual(e.value, t.value);
695
+ }
696
+ /** RFC 5280 §7.5: rfc822Name local-part is case-sensitive, the host-part case-insensitive. */
697
+ function compareRfc822Names(e, t) {
698
+ let n = e.lastIndexOf("@"), r = t.lastIndexOf("@");
699
+ return n < 0 || r < 0 ? e.toLowerCase() === t.toLowerCase() : e.slice(0, n) === t.slice(0, r) && e.slice(n + 1).toLowerCase() === t.slice(r + 1).toLowerCase();
700
+ }
701
+ /** RFC 5280 §7.4: URIs compare only after syntax-based and scheme-based normalization. */
702
+ function compareUniformResourceIdentifiers(e, t) {
703
+ if (e === t) return !0;
704
+ let n = normalizeUriForComparison(e);
705
+ return n !== void 0 && n === normalizeUriForComparison(t);
706
+ }
707
+ /**
708
+ * The schemes RFC 5280 §7.4 step 5 requires implementations to recognise, with
709
+ * the default port that scheme-based normalization elides. `ldaps` is included
710
+ * as the TLS form of the mandatory `ldap` scheme.
711
+ */
712
+ const ue = /* @__PURE__ */ new Map([
713
+ ["ftp", "21"],
714
+ ["http", "80"],
715
+ ["https", "443"],
716
+ ["ldap", "389"],
717
+ ["ldaps", "636"]
718
+ ]);
719
+ /**
720
+ * Applies the RFC 5280 §7.4 comparison preparation: IDN labels to ASCII
721
+ * Compatible Encoding, lowercased scheme and host, percent-encoding and path
722
+ * segment normalization, and scheme-based normalization. The URL parser covers
723
+ * path segments for every scheme and the scheme case; the remaining steps are
724
+ * applied here because it leaves the host of a non-special scheme such as
725
+ * `ldap` untouched and never normalizes percent-encoding.
726
+ *
727
+ * @returns `undefined` when the value does not parse as an absolute URI.
728
+ */
729
+ function normalizeUriForComparison(e) {
730
+ let t;
731
+ try {
732
+ t = new URL(e);
733
+ } catch {
734
+ return;
735
+ }
736
+ if (t.hostname !== "") {
737
+ let e = normalizeUriHost(t.hostname);
738
+ if (e === void 0) return;
739
+ t.hostname = e;
740
+ }
741
+ return t.port === ue.get(t.protocol.slice(0, -1)) && (t.port = ""), normalizePercentEncoding(t.href);
742
+ }
743
+ /**
744
+ * Reparses a host under a special scheme so the URL parser applies IDNA and
745
+ * lowercasing to it, which it skips for opaque hosts.
746
+ *
747
+ * @returns `undefined` when the host does not survive the round trip intact.
748
+ */
749
+ function normalizeUriHost(e) {
750
+ try {
751
+ let t = new URL(`https://${decodeHostPercentEncoding(e)}`);
752
+ return t.href === `https://${t.hostname}/` ? t.hostname : void 0;
753
+ } catch {
754
+ return;
755
+ }
756
+ }
757
+ /** Recovers the Unicode host an opaque-host URI carries as percent-encoded UTF-8. */
758
+ function decodeHostPercentEncoding(e) {
759
+ try {
760
+ return decodeURIComponent(e);
761
+ } catch {
762
+ return e;
763
+ }
764
+ }
765
+ const de = /%[0-9A-Fa-f]{2}/g;
766
+ /** RFC 3986 §6.2.2.2: unreserved triplets decode, every other triplet uppercases. */
767
+ function normalizePercentEncoding(e) {
768
+ return e.replace(de, (e) => {
769
+ let t = Number.parseInt(e.slice(1), 16);
770
+ return isUnreservedUriCharacter(t) ? String.fromCharCode(t) : e.toUpperCase();
771
+ });
772
+ }
773
+ /** RFC 3986 §2.3 unreserved set: `ALPHA / DIGIT / "-" / "." / "_" / "~"`. */
774
+ function isUnreservedUriCharacter(e) {
775
+ return e >= 65 && e <= 90 || e >= 97 && e <= 122 || e >= 48 && e <= 57 || e === 45 || e === 46 || e === 95 || e === 126;
498
776
  }
499
777
  /** Constant-length byte-array equality check. */
500
778
  function bytesEqual(e, t) {
@@ -502,51 +780,30 @@ function bytesEqual(e, t) {
502
780
  for (let n = 0; n < e.length; n += 1) if (e[n] !== t[n]) return !1;
503
781
  return !0;
504
782
  }
505
- /** Set-equality comparison for RDN attribute sets (order-independent, RFC 4518 string prep). */
506
- function compareRelativeDistinguishedNames(e, t) {
507
- if (e.attributes.length !== t.attributes.length) return !1;
508
- let n = Array.from({ length: t.attributes.length }, () => !1);
509
- for (let r of e.attributes) {
510
- let e = !1;
511
- for (let i = 0; i < t.attributes.length; i += 1) {
512
- let a = t.attributes[i];
513
- if (!(a === void 0 || n[i]) && X(r, a)) {
514
- n[i] = !0, e = !0;
515
- break;
516
- }
517
- }
518
- if (!e) return !1;
519
- }
520
- return !0;
521
- }
522
783
  /** Assembles the CRL-level v2 extensions (AKI, CRLNumber, deltaCRLIndicator, IDP, freshestCRL). */
523
- async function buildCrlExtensions(e, t, n, r, i) {
524
- let o = [];
525
- if (e !== void 0) {
526
- let t = await j(e);
527
- o.push(V(w.authorityKeyIdentifier, d([a(0, z(t))])));
528
- }
529
- return t !== void 0 && o.push(V(w.cRLNumber, s(t))), n !== void 0 && o.push(V(w.deltaCRLIndicator, s(n), !0)), r !== void 0 && o.push(V(w.issuingDistributionPoint, encodeIssuingDistributionPoint(r), !0)), i !== void 0 && i.length > 0 && o.push(V(w.freshestCRL, B(i))), o;
784
+ function buildCrlExtensions(e, t, n, r, i) {
785
+ let a = [X(N.authorityKeyIdentifier, y([p(0, se(e))])), X(N.cRLNumber, t)];
786
+ return n !== void 0 && a.push(X(N.deltaCRLIndicator, n, !0)), r !== void 0 && a.push(X(N.issuingDistributionPoint, encodeIssuingDistributionPoint(r), !0)), i !== void 0 && i.length > 0 && a.push(X(N.freshestCRL, ae(i))), a;
530
787
  }
531
788
  /** DER-encodes a single revokedCertificate SEQUENCE (serial, date, optional extensions). */
532
789
  function createRevokedCertificate(e, t) {
533
790
  let n = buildRevokedCertificateExtensions(e);
534
- return d([
535
- o(e.serialNumber),
536
- f(e.revocationDate ?? t),
537
- ...n.length === 0 ? [] : [d(n)]
791
+ return y([
792
+ m(e.serialNumber),
793
+ b(e.revocationDate ?? t),
794
+ ...n.length === 0 ? [] : [y(n)]
538
795
  ]);
539
796
  }
540
797
  /** Encodes CRL entry extensions (reasonCode, invalidityDate). */
541
798
  function buildRevokedCertificateExtensions(e) {
542
799
  let t = [];
543
- return e.reasonCode !== void 0 && t.push(V(w.cRLReason, p(10, Uint8Array.of(Z[e.reasonCode])))), e.invalidityDate !== void 0 && t.push(V(w.invalidityDate, r(e.invalidityDate))), t;
800
+ return e.reasonCode !== void 0 && t.push(X(N.cRLReason, x(10, Uint8Array.of(le[e.reasonCode])))), e.invalidityDate !== void 0 && t.push(X(N.invalidityDate, d(e.invalidityDate))), t;
544
801
  }
545
802
  /** Decodes per-entry CRL extensions (reasonCode, invalidityDate, certificateIssuer). */
546
803
  function parseRevokedCertificateExtensions(e, t) {
547
804
  if (e === void 0 || t === void 0) return {};
548
805
  let n = {}, r = /* @__PURE__ */ new Set();
549
- for (let i of m(e, t)) parseRevokedCertificateExtension(e, i, r, n);
806
+ for (let i of S(e, t)) parseRevokedCertificateExtension(e, i, r, n);
550
807
  return {
551
808
  ...n.reasonCode === void 0 ? {} : { reasonCode: n.reasonCode },
552
809
  ...n.invalidityDate === void 0 ? {} : { invalidityDate: n.invalidityDate },
@@ -554,44 +811,88 @@ function parseRevokedCertificateExtensions(e, t) {
554
811
  };
555
812
  }
556
813
  function parseRevokedCertificateExtension(e, t, n, r) {
557
- let i = m(e, t);
814
+ let i = S(e, t);
558
815
  if (i.length < 2 || i.length > 3 || i.length === 3 && i[1]?.tag !== 1) throw Error("Malformed revoked certificate extension");
559
- let a = _(S(i[0], "revoked certificate extension OID").value);
816
+ let a = E(j(i[0], "revoked certificate extension OID").value);
560
817
  if (n.has(a)) throw Error(`Duplicate revoked certificate extension OID: ${a}`);
561
818
  n.add(a);
562
- let o = S(i[i.length - 1], "revoked certificate extension value");
563
- if (o.tag !== 4) throw Error("Revoked certificate extension value must use OCTET STRING");
564
- applyRevokedCertificateExtensionValue(a, o.value, r);
565
- }
566
- function applyRevokedCertificateExtensionValue(e, t, n) {
567
- if (e === w.cRLReason) {
568
- let e = revocationReasonFromCode(c(t).value[0]);
569
- e !== void 0 && (n.reasonCode = e);
819
+ let o = i.length === 3 && C(j(i[1], "revoked certificate extension critical").value), s = j(i[i.length - 1], "revoked certificate extension value");
820
+ if (s.tag !== 4) throw Error("Revoked certificate extension value must use OCTET STRING");
821
+ if (o && !isSupportedRevokedCertificateExtensionOid(a)) throw Error(`Unsupported critical revoked certificate extension OID: ${a}`);
822
+ applyRevokedCertificateExtensionValue(a, s.value, o, r);
823
+ }
824
+ function isSupportedRevokedCertificateExtensionOid(e) {
825
+ return e === N.cRLReason || e === N.invalidityDate || e === N.certificateIssuer;
826
+ }
827
+ function applyRevokedCertificateExtensionValue(e, t, n, r) {
828
+ if (e === N.cRLReason) {
829
+ let e = _(t, { maxDepth: 64 });
830
+ if (e.tag !== 10) throw Error("cRLReason must use ENUMERATED");
831
+ let i = parsedRevocationReason(te(e.value, "cRLReason"));
832
+ if (n && typeof i != "string") throw Error(`Critical cRLReason holds unrecognized reason code ${String(i.code)}`);
833
+ r.reasonCode = i;
570
834
  }
571
- if (e === w.invalidityDate && (n.invalidityDate = x(c(t))), e === w.certificateIssuer) {
572
- let e = l(t, { maxDepth: 64 });
835
+ if (e === N.invalidityDate && (r.invalidityDate = A(_(t, { maxDepth: 64 }))), e === N.certificateIssuer) {
836
+ let e = _(t, { maxDepth: 64 });
573
837
  if (e.tag !== 48) throw Error("certificateIssuer must use SEQUENCE");
574
- n.certificateIssuer = parseGeneralNames(t, e);
838
+ r.certificateIssuer = U(t, e);
575
839
  }
576
840
  }
577
841
  /** Decodes the IssuingDistributionPoint extension from its OCTET STRING content. */
578
842
  function parseIssuingDistributionPoint(e) {
579
- let t = l(e, { maxDepth: 64 }), n = {};
580
- for (let r of m(e, t)) parseIssuingDistributionPointField(e, r, n);
581
- if ([
582
- n.onlyContainsUserCerts,
583
- n.onlyContainsCACerts,
584
- n.onlyContainsAttributeCerts
585
- ].filter((e) => e === !0).length > 1) throw Error("IssuingDistributionPoint scope booleans are mutually exclusive");
843
+ let t = _(e, { maxDepth: 64 }), n = {};
844
+ for (let r of S(e, t)) parseIssuingDistributionPointField(e, r, n);
586
845
  return {
587
846
  ...n.distributionPoint === void 0 ? {} : { distributionPoint: n.distributionPoint },
588
- ...n.onlyContainsUserCerts === void 0 ? {} : { onlyContainsUserCerts: n.onlyContainsUserCerts },
589
- ...n.onlyContainsCACerts === void 0 ? {} : { onlyContainsCACerts: n.onlyContainsCACerts },
590
847
  ...n.onlySomeReasons === void 0 ? {} : { onlySomeReasons: n.onlySomeReasons },
591
848
  ...n.indirectCrl === void 0 ? {} : { indirectCrl: n.indirectCrl },
592
- ...n.onlyContainsAttributeCerts === void 0 ? {} : { onlyContainsAttributeCerts: n.onlyContainsAttributeCerts }
849
+ ...parseIssuingDistributionPointScope(n)
593
850
  };
594
851
  }
852
+ /** RFC 5280 §5.2.5: at most one `onlyContains*` flag may be TRUE. */
853
+ function parseIssuingDistributionPointScope(e) {
854
+ let t = e.onlyContainsUserCerts, n = e.onlyContainsCACerts, r = e.onlyContainsAttributeCerts;
855
+ if (t === !0) {
856
+ if (n === !0 || r === !0) throw Error($);
857
+ return {
858
+ onlyContainsUserCerts: !0,
859
+ ...unselectedScopeFlags({
860
+ caCerts: n,
861
+ attributeCerts: r
862
+ })
863
+ };
864
+ }
865
+ if (n === !0) {
866
+ if (r === !0) throw Error($);
867
+ return {
868
+ onlyContainsCACerts: !0,
869
+ ...unselectedScopeFlags({
870
+ userCerts: t,
871
+ attributeCerts: r
872
+ })
873
+ };
874
+ }
875
+ return r === !0 ? {
876
+ onlyContainsAttributeCerts: !0,
877
+ ...unselectedScopeFlags({
878
+ userCerts: t,
879
+ caCerts: n
880
+ })
881
+ } : unselectedScopeFlags({
882
+ userCerts: t,
883
+ caCerts: n,
884
+ attributeCerts: r
885
+ });
886
+ }
887
+ /** Keeps the explicit-FALSE flags the encoding carried, omitting the ones it left out. */
888
+ function unselectedScopeFlags(e) {
889
+ return {
890
+ ...e.userCerts === void 0 ? {} : { onlyContainsUserCerts: e.userCerts },
891
+ ...e.caCerts === void 0 ? {} : { onlyContainsCACerts: e.caCerts },
892
+ ...e.attributeCerts === void 0 ? {} : { onlyContainsAttributeCerts: e.attributeCerts }
893
+ };
894
+ }
895
+ const $ = "IssuingDistributionPoint scope booleans are mutually exclusive";
595
896
  function parseIssuingDistributionPointField(e, t, n) {
596
897
  switch (t.tag) {
597
898
  case 160: {
@@ -608,7 +909,7 @@ function parseIssuingDistributionPointField(e, t, n) {
608
909
  return;
609
910
  case 131:
610
911
  if (n.onlySomeReasons !== void 0) throw Error("IssuingDistributionPoint onlySomeReasons must not repeat");
611
- n.onlySomeReasons = F(t.value);
912
+ n.onlySomeReasons = V(t.value);
612
913
  return;
613
914
  case 132:
614
915
  n.indirectCrl = parseUniqueIssuingDistributionPointBoolean(n.indirectCrl, t, "indirectCrl");
@@ -621,35 +922,41 @@ function parseIssuingDistributionPointField(e, t, n) {
621
922
  }
622
923
  function parseUniqueIssuingDistributionPointBoolean(e, t, n) {
623
924
  if (e !== void 0) throw Error(`IssuingDistributionPoint ${n} must not repeat`);
624
- return parseImplicitBoolean(t);
925
+ return C(t.value);
625
926
  }
626
927
  /** Decodes a SEQUENCE OF DistributionPoint from DER. */
627
928
  function parseDistributionPoints(e) {
628
- let t = l(e, { maxDepth: 64 });
929
+ let t = _(e, { maxDepth: 64 });
629
930
  if (t.tag !== 48) throw Error("DistributionPoints must use SEQUENCE");
630
- let n = m(e, t);
931
+ let n = S(e, t);
631
932
  if (n.length === 0) throw Error("DistributionPoints must not be empty");
632
933
  return n.map((t) => parseDistributionPoint(e, t));
633
934
  }
634
935
  /** Decodes a DistributionPointName (fullName or relativeName). */
635
936
  function parseDistributionPointName(e, t) {
636
- let n = m(e, t);
937
+ let n = S(e, t);
637
938
  if (n.length !== 1) throw Error("distributionPointName must contain exactly one choice");
638
- let r = S(n[0], "distributionPointName");
939
+ let r = j(n[0], "distributionPointName");
639
940
  if (r.tag === 160) {
640
- let t = m(e, r);
941
+ let t = S(e, r);
641
942
  if (t.length === 0) throw Error("distributionPointName fullName must not be empty");
642
943
  for (let e of t) if ((e.tag & 192) != 128) throw Error("distributionPointName fullName must contain GeneralName entries");
643
- return { fullName: t.map((e) => parseGeneralName(e)) };
944
+ return {
945
+ type: "fullName",
946
+ fullName: t.map((t) => H(e, t))
947
+ };
644
948
  }
645
- if (r.tag === 161) return { relativeName: parseRelativeName(e, r) };
949
+ if (r.tag === 161) return {
950
+ type: "relativeName",
951
+ relativeName: parseRelativeName(e, r)
952
+ };
646
953
  throw Error(`Unsupported distributionPointName tag: ${String(r.tag)}`);
647
954
  }
648
955
  /** Decodes a single DistributionPoint SEQUENCE. */
649
956
  function parseDistributionPoint(e, t) {
650
957
  if (t.tag !== 48) throw Error("DistributionPoint must use SEQUENCE");
651
958
  let n = {};
652
- for (let r of m(e, t)) parseDistributionPointField(e, r, n);
959
+ for (let r of S(e, t)) parseDistributionPointField(e, r, n);
653
960
  if (n.distributionPoint === void 0 && n.crlIssuer === void 0) throw Error("DistributionPoint must include distributionPoint or crlIssuer");
654
961
  return {
655
962
  ...n.distributionPoint === void 0 ? {} : { distributionPoint: n.distributionPoint },
@@ -667,56 +974,20 @@ function parseDistributionPointField(e, t, n) {
667
974
  }
668
975
  case 129:
669
976
  if (n.reasons !== void 0) throw Error("DistributionPoint reasons must not repeat");
670
- n.reasons = F(t.value);
977
+ n.reasons = V(t.value);
671
978
  return;
672
979
  case 162:
673
980
  if (n.crlIssuer !== void 0) throw Error("DistributionPoint crlIssuer must not repeat");
674
- n.crlIssuer = parseGeneralNames(e, t);
981
+ n.crlIssuer = U(e, t);
675
982
  return;
676
983
  default: throw Error(`Unsupported DistributionPoint field tag: ${String(t.tag)}`);
677
984
  }
678
985
  }
679
- /** Decodes a GeneralName from its context-tagged ASN.1 element. */
680
- function parseGeneralName(e) {
681
- switch (e.tag) {
682
- case 129: return {
683
- type: "email",
684
- value: Q.decode(e.value)
685
- };
686
- case 130: return {
687
- type: "dns",
688
- value: Q.decode(e.value)
689
- };
690
- case 134: return {
691
- type: "uri",
692
- value: Q.decode(e.value)
693
- };
694
- case 135: return {
695
- type: "ip",
696
- value: N(e.value)
697
- };
698
- case 164: return {
699
- type: "directoryName",
700
- derHex: C(rebuildDirectoryNameFromImplicit(e))
701
- };
702
- default: return {
703
- type: "unknown",
704
- tag: e.tag,
705
- value: new Uint8Array(e.value)
706
- };
707
- }
708
- }
709
- function parseGeneralNames(e, t) {
710
- let n = m(e, t);
711
- if (n.length === 0) throw Error("GeneralNames must not be empty");
712
- for (let e of n) if ((e.tag & 192) != 128) throw Error("GeneralNames must contain GeneralName entries");
713
- return n.map((e) => parseGeneralName(e));
714
- }
715
986
  /** Decodes a RelativeDistinguishedName SET from an implicitly-tagged context element. */
716
987
  function parseRelativeName(e, t) {
717
988
  let n = [], r = {};
718
- for (let i of m(e, t)) {
719
- let t = m(e, i), a = _(S(t[0], "name OID").value), o = S(t[1], "name value"), s = I(a), c = decodeNameValue(o), l = s === void 0 ? {
989
+ for (let i of S(e, t)) {
990
+ let t = S(e, i), a = E(j(t[0], "name OID").value), o = j(t[1], "name value"), s = G(a), c = decodeNameValue(o), l = s === void 0 ? {
720
991
  oid: a,
721
992
  valueTag: o.tag,
722
993
  value: c
@@ -729,18 +1000,40 @@ function parseRelativeName(e, t) {
729
1000
  n.push(l), s !== void 0 && r[s] === void 0 && (r[s] = c);
730
1001
  }
731
1002
  return {
732
- derHex: C(e.slice(t.start - t.headerLength, t.end)),
1003
+ derHex: M(e.slice(t.start - t.headerLength, t.end)),
733
1004
  attributes: n,
734
1005
  values: r
735
1006
  };
736
1007
  }
737
1008
  /** Decodes an ASN.1 string element (UTF8String, PrintableString, etc.) to a JS string. */
738
1009
  function decodeNameValue(e) {
739
- return v(e.tag, e.value);
1010
+ return D(e.tag, e.value);
1011
+ }
1012
+ /** Throws a {@link ResultError} for a CRL encoder input-validation failure. */
1013
+ function throwCrlEncoderError(e, t) {
1014
+ i(e, t);
1015
+ }
1016
+ /** The parsed issuer certificate of a CRL being built. */
1017
+ function issuerCertificateOf(t) {
1018
+ try {
1019
+ return normalizeCrlCertificate(t);
1020
+ } catch (t) {
1021
+ return s(t, e), throwCrlEncoderError("issuer_certificate_invalid", "issuerCertificate must be a PEM, DER or parsed certificate");
1022
+ }
1023
+ }
1024
+ /** RFC 5280 §5.2.3 `CRLNumber ::= INTEGER (0..MAX)` as a DER INTEGER of at most 20 content octets. */
1025
+ function encodeCrlNumber(e, t) {
1026
+ let n = typeof e == "bigint" ? e : Number.isSafeInteger(e) ? BigInt(e) : -1n, r = n.toString(16), i = n < 0n ? void 0 : k(r.length % 2 == 0 ? r : `0${r}`), a = i?.[0];
1027
+ return (i === void 0 || a === void 0 || i.length + +(a >= 128) > 20) && throwCrlEncoderError("crl_number_invalid", `${t} must be a non-negative integer of at most 20 octets (RFC 5280 §5.2.3)`), m(i);
740
1028
  }
741
- /** Reads an implicitly-tagged BOOLEAN from a context element. Absent content → `false`. */
742
- function parseImplicitBoolean(e) {
743
- return (e.value[0] ?? 0) !== 0;
1029
+ /** RFC 5280 §5.2.3: a received CRLNumber of any length, since verifiers MUST handle up to 20 octets. */
1030
+ function decodeCrlNumber(e) {
1031
+ let t = _(e, { maxDepth: 64 });
1032
+ if (t.tag !== 2) throw Error("CRLNumber must be an INTEGER");
1033
+ return w(t.value, "CRLNumber"), BigInt(`0x${M(t.value)}`);
1034
+ }
1035
+ function assertCrlDate(e, t) {
1036
+ e !== void 0 && Number.isNaN(e.getTime()) && throwCrlEncoderError("invalid_date", `${t} must be a valid date`);
744
1037
  }
745
1038
  /** DER-encodes an IssuingDistributionPoint extension value. Throws on mutually-exclusive scope flags. */
746
1039
  function encodeIssuingDistributionPoint(e) {
@@ -750,50 +1043,31 @@ function encodeIssuingDistributionPoint(e) {
750
1043
  e.onlyContainsAttributeCerts === !0
751
1044
  ].filter(Boolean).length > 1) throw Error("IssuingDistributionPoint can assert at most one of user, CA, or attribute cert scope");
752
1045
  let t = [];
753
- return e.distributionPoint !== void 0 && t.push(i(0, encodeDistributionPointName(e.distributionPoint))), e.onlyContainsUserCerts && t.push(a(1, Uint8Array.of(255))), e.onlyContainsCACerts && t.push(a(2, Uint8Array.of(255))), e.onlySomeReasons !== void 0 && e.onlySomeReasons.length > 0 && t.push(a(3, P(e.onlySomeReasons))), e.indirectCrl && t.push(a(4, Uint8Array.of(255))), e.onlyContainsAttributeCerts && t.push(a(5, Uint8Array.of(255))), d(t);
1046
+ return e.distributionPoint !== void 0 && t.push(f(0, encodeDistributionPointName(e.distributionPoint))), e.onlyContainsUserCerts && t.push(p(1, Uint8Array.of(255))), e.onlyContainsCACerts && t.push(p(2, Uint8Array.of(255))), e.onlySomeReasons !== void 0 && e.onlySomeReasons.length > 0 && t.push(p(3, B(e.onlySomeReasons))), e.indirectCrl && t.push(p(4, Uint8Array.of(255))), e.onlyContainsAttributeCerts && t.push(p(5, Uint8Array.of(255))), y(t);
754
1047
  }
755
1048
  /** DER-encodes a DistributionPointName (fullName or relativeName). */
756
1049
  function encodeDistributionPointName(e) {
757
1050
  if (e === void 0) throw Error("IssuingDistributionPoint distributionPoint is required");
758
- if (e.fullName !== void 0 && e.relativeName !== void 0) throw Error("DistributionPointName cannot contain both fullName and relativeName");
759
- if (e.fullName !== void 0) {
760
- if (e.fullName.length === 0) throw Error("DistributionPointName fullName must not be empty");
761
- return i(0, concatGeneralNames(e.fullName));
762
- }
763
- if (e.relativeName !== void 0) {
764
- let t = R(e.relativeName), n = c(t);
765
- return i(1, t.slice(n.start, n.end));
1051
+ switch (e.type) {
1052
+ case "fullName": return e.fullName.length === 0 && throwCrlEncoderError("distribution_point_full_name_empty", "DistributionPointName fullName must not be empty"), f(0, concatGeneralNames(e.fullName));
1053
+ case "relativeName": {
1054
+ let t = Y(e.relativeName), n = g(t);
1055
+ return f(1, t.slice(n.start, n.end));
1056
+ }
1057
+ default: throw Error(`Unhandled DistributionPointName type: ${String(e)}`);
766
1058
  }
767
- throw Error("DistributionPointName must contain fullName or relativeName");
768
1059
  }
769
1060
  /** DER-encodes and concatenates a list of GeneralName values. */
770
1061
  function concatGeneralNames(e) {
771
- return t(e.map((e) => H(e)));
772
- }
773
- /** Re-wraps an implicitly-tagged directoryName as an explicit SEQUENCE (tag 0x30). */
774
- /**
775
- * Extracts the Name SEQUENCE from an implicitly-tagged directoryName [4].
776
- *
777
- * Handles two encoding styles found in the wild:
778
- * - Proper implicit: [4] replaces SEQUENCE tag, content is RDN SETs directly → wrap with 0x30
779
- * - Explicit-like: [4] wraps entire SEQUENCE, content starts with 0x30 → return content as-is
780
- */
781
- function rebuildDirectoryNameFromImplicit(e) {
782
- return e.value.length > 0 && e.value[0] === 48 ? new Uint8Array(e.value) : p(48, e.value);
1062
+ return l(e.map((e) => oe(e)));
783
1063
  }
784
1064
  /** Parses a Name SEQUENCE element into a full {@linkcode ParsedName}. */
785
1065
  function parseIssuer(e, t) {
786
- let n = C(e.slice(t.start - t.headerLength, t.end)), r = [], i = [], a = {};
787
- for (let n of m(e, t)) {
1066
+ let n = M(e.slice(t.start - t.headerLength, t.end)), r = [], i = [], a = {};
1067
+ for (let n of S(e, t)) {
788
1068
  let t = [], o = {};
789
- for (let r of m(e, n)) {
790
- let n = m(e, r), s = S(n[0], "issuer attribute OID"), c = S(n[1], "issuer attribute value"), l = _(s.value), u;
791
- try {
792
- u = v(c.tag, c.value);
793
- } catch {
794
- u = Q.decode(c.value);
795
- }
796
- let d = I(l), f = d === void 0 ? {
1069
+ for (let r of S(e, n)) {
1070
+ let n = S(e, r), s = j(n[0], "issuer attribute OID"), c = j(n[1], "issuer attribute value"), l = E(s.value), u = decodeNameValue(c), d = G(l), f = d === void 0 ? {
797
1071
  oid: l,
798
1072
  valueTag: c.tag,
799
1073
  value: u
@@ -806,7 +1080,7 @@ function parseIssuer(e, t) {
806
1080
  t.push(f), i.push(f), d !== void 0 && (o[d] === void 0 && (o[d] = u), a[d] === void 0 && (a[d] = u));
807
1081
  }
808
1082
  r.push({
809
- derHex: C(e.slice(n.start - n.headerLength, n.end)),
1083
+ derHex: M(e.slice(n.start - n.headerLength, n.end)),
810
1084
  attributes: t,
811
1085
  values: o
812
1086
  });
@@ -818,28 +1092,38 @@ function parseIssuer(e, t) {
818
1092
  values: a
819
1093
  };
820
1094
  }
821
- /** Re-parses a hex-encoded DER Name into a {@linkcode ParsedName}. Returns `undefined` on malformed input. */
822
- function parseDerHexName(e) {
1095
+ /**
1096
+ * Re-parses a hex-encoded DER Name into a {@linkcode ParsedName}. Returns
1097
+ * `undefined` on malformed input and throws a decode refusal.
1098
+ */
1099
+ function parseDerHexName(t) {
823
1100
  try {
824
- let t = b(e), n = unwrapNameElement(t, l(t, { maxDepth: 64 }));
825
- return n.tag === 48 ? parseIssuer(t, n) : void 0;
826
- } catch {
1101
+ let e = k(t), n = unwrapNameElement(e, _(e, { maxDepth: 64 }));
1102
+ return n.tag === 48 ? parseIssuer(e, n) : void 0;
1103
+ } catch (t) {
1104
+ s(t, e);
827
1105
  return;
828
1106
  }
829
1107
  }
1108
+ /** The failure for a decode refusal a directoryName comparison threw. */
1109
+ function crlNameRefusalFailure(t) {
1110
+ let n = o(t, e);
1111
+ if (n === void 0) throw t;
1112
+ return checkCertificateRevocationAgainstCrlFailureResult(n.code, n.message);
1113
+ }
830
1114
  function unwrapNameElement(e, t) {
831
1115
  if (t.tag !== 48) return t;
832
- let n = m(e, t), r = n[0];
1116
+ let n = S(e, t), r = n[0];
833
1117
  return n.length === 1 && r?.tag === 48 ? r : t;
834
1118
  }
835
1119
  /** Semantic comparison of a GeneralName directoryName `derHex` against a {@linkcode ParsedName}. */
836
1120
  function directoryNameDerHexMatchesParsedName(e, t) {
837
1121
  let n = parseDerHexName(e);
838
- return n !== void 0 && Y(n, t);
1122
+ return n !== void 0 && K(n, t);
839
1123
  }
840
1124
  /** Extracts the keyIdentifier field from an AuthorityKeyIdentifier extension value. */
841
1125
  function parseAuthorityKeyIdentifier(e) {
842
- let t = l(e, {
1126
+ let t = _(e, {
843
1127
  maxDepth: 64,
844
1128
  allowOpaqueConstructedTags: [161, 162]
845
1129
  });
@@ -849,7 +1133,7 @@ function parseAuthorityKeyIdentifier(e) {
849
1133
  sawAuthorityCertSerialNumber: !1,
850
1134
  lastFieldOrder: -1
851
1135
  };
852
- for (let r of m(e, t)) parseAuthorityKeyIdentifierField(e, r, n);
1136
+ for (let r of S(e, t)) parseAuthorityKeyIdentifierField(e, r, n);
853
1137
  return n.keyIdentifier;
854
1138
  }
855
1139
  function parseAuthorityKeyIdentifierField(e, t, n) {
@@ -869,12 +1153,12 @@ function parseAuthorityKeyIdentifierField(e, t, n) {
869
1153
  function parseAuthorityKeyIdentifierKeyId(e, t) {
870
1154
  if (t.keyIdentifier !== void 0) throw Error("authorityKeyIdentifier keyIdentifier must not repeat");
871
1155
  if (t.lastFieldOrder >= 0) throw Error("authorityKeyIdentifier fields must preserve DER order");
872
- t.keyIdentifier = C(e.value), t.lastFieldOrder = 0;
1156
+ t.keyIdentifier = M(e.value), t.lastFieldOrder = 0;
873
1157
  }
874
1158
  function parseAuthorityKeyIdentifierIssuer(e, t, n) {
875
1159
  if (n.sawAuthorityCertIssuer) throw Error("authorityKeyIdentifier authorityCertIssuer must not repeat");
876
1160
  if (n.lastFieldOrder >= 1) throw Error("authorityKeyIdentifier fields must preserve DER order");
877
- parseGeneralNames(e, t), n.sawAuthorityCertIssuer = !0, n.lastFieldOrder = 1;
1161
+ U(e, t), n.sawAuthorityCertIssuer = !0, n.lastFieldOrder = 1;
878
1162
  }
879
1163
  function parseAuthorityKeyIdentifierSerial(e, t) {
880
1164
  if (t.sawAuthorityCertSerialNumber) throw Error("authorityKeyIdentifier authorityCertSerialNumber must not repeat");
@@ -887,11 +1171,15 @@ function validateImplicitSerialNumberEncoding(e, t) {
887
1171
  if (n & 128) throw Error(`${t} must be non-negative`);
888
1172
  if (e.length > 1 && n === 0 && !((e[1] ?? 0) & 128)) throw Error(`${t} must use minimal encoding`);
889
1173
  }
1174
+ /** RFC 5280 §5.1.1.2: signatureAlgorithm MUST equal the tbsCertList signature field. */
1175
+ function assertMatchingCrlSignatureAlgorithms(e, t) {
1176
+ if (e.oid !== t.oid || !ee(e.parametersDer, t.parametersDer)) throw Error("CRL signatureAlgorithm must match TBSCertList signature");
1177
+ }
890
1178
  /** Extracts the algorithm OID from an AlgorithmIdentifier SEQUENCE. */
891
1179
  function parseAlgorithmIdentifier(e, t) {
892
- let n = m(e, t), r = S(n[0], "algorithm OID"), i = n[1];
893
- return i === void 0 ? { oid: _(r.value) } : {
894
- oid: _(r.value),
1180
+ let n = S(e, t), r = j(n[0], "algorithm OID"), i = n[1];
1181
+ return i === void 0 ? { oid: E(r.value) } : {
1182
+ oid: E(r.value),
895
1183
  parametersDer: e.slice(i.start - i.headerLength, i.end)
896
1184
  };
897
1185
  }
@@ -899,30 +1187,46 @@ function parseAlgorithmIdentifier(e, t) {
899
1187
  function normalizeHex(e) {
900
1188
  return e.toLowerCase();
901
1189
  }
902
- /** Maps an integer CRLReason code back to its {@linkcode RevocationReason} string, or `undefined` for unknown codes. */
1190
+ /**
1191
+ * Maps an integer CRLReason code to its {@linkcode RevocationReason} name, or to
1192
+ * an {@linkcode UnrecognizedRevocationReason} carrying a code outside RFC 5280
1193
+ * §5.3.1. Returns `undefined` only when `code` is `undefined`.
1194
+ */
903
1195
  function revocationReasonFromCode(e) {
1196
+ return e === void 0 ? void 0 : parsedRevocationReason(e);
1197
+ }
1198
+ function parsedRevocationReason(e) {
904
1199
  switch (e) {
905
- case 0: return "unspecified";
906
- case 1: return "keyCompromise";
907
- case 2: return "cACompromise";
908
- case 3: return "affiliationChanged";
909
- case 4: return "superseded";
910
- case 5: return "cessationOfOperation";
911
- case 6: return "certificateHold";
912
- case 8: return "removeFromCRL";
913
- case 9: return "privilegeWithdrawn";
914
- case 10: return "aACompromise";
1200
+ case 0n: return "unspecified";
1201
+ case 1n: return "keyCompromise";
1202
+ case 2n: return "cACompromise";
1203
+ case 3n: return "affiliationChanged";
1204
+ case 4n: return "superseded";
1205
+ case 5n: return "cessationOfOperation";
1206
+ case 6n: return "certificateHold";
1207
+ case 8n: return "removeFromCRL";
1208
+ case 9n: return "privilegeWithdrawn";
1209
+ case 10n: return "aACompromise";
1210
+ default: return {
1211
+ type: "unrecognized",
1212
+ code: e
1213
+ };
915
1214
  }
916
1215
  }
917
1216
  /** Thin wrapper — parses a DER-encoded certificate for use as a CRL issuer. */
918
1217
  function parseIssuerCertificateDer(e) {
919
- return W(e);
1218
+ return Z(e);
920
1219
  }
921
1220
  /** Thin wrapper — parses a PEM-encoded certificate for use as a CRL issuer. */
922
1221
  function parseIssuerCertificatePem(e) {
923
- return W(e);
1222
+ return Z(e);
924
1223
  }
925
- /** Accepts PEM, DER, or already-parsed CRL and returns a parsed CRL. */
1224
+ /**
1225
+ * Parses PEM, DER, or an already-parsed CRL's `der`, so every decoded field
1226
+ * comes from the signed bytes.
1227
+ *
1228
+ * @internal
1229
+ */
926
1230
  function normalizeCrl(e) {
927
1231
  if (typeof e == "string") return parseCertificateRevocationListPemOrThrow(e);
928
1232
  if (e instanceof Uint8Array) return parseCertificateRevocationListDerOrThrow(new Uint8Array(e));
@@ -930,24 +1234,23 @@ function normalizeCrl(e) {
930
1234
  throw Error("certificate revocation list input is malformed");
931
1235
  }
932
1236
  function parseSignedCrlFields(e) {
933
- let t = m(e, l(e, { maxDepth: 64 })), n = parseCrlVersionField(t), r = n.version, i = n.nextIndex;
934
- i += 1;
935
- let a = S(t[i], "issuer"), o = S(t[i + 1], "thisUpdate"), s = i + 2, c = t[s], u = c !== void 0 && (c.tag === 23 || c.tag === 24) ? x(c) : void 0;
936
- u !== void 0 && (s += 1);
937
- let d = t[s], f = d?.tag === 48 ? parseRevokedCertificates(e, d, r) : [];
938
- d?.tag === 48 && (s += 1);
939
- let p = t[s], h = parseCrlExtensionFields(e, p, r);
1237
+ let t = _(e, { maxDepth: 64 }), n = S(e, t), r = parseCrlVersionField(n), i = r.version, a = j(n[r.nextIndex], "signature"), o = r.nextIndex + 1, s = j(n[o], "issuer"), c = j(n[o + 1], "thisUpdate"), l = o + 2, u = n[l], d = u !== void 0 && (u.tag === 23 || u.tag === 24) ? A(u) : void 0;
1238
+ d !== void 0 && (l += 1);
1239
+ let f = n[l], p = f?.tag === 48 ? parseRevokedCertificates(e, f, i) : [];
1240
+ f?.tag === 48 && (l += 1);
1241
+ let m = n[l], h = parseCrlExtensionFields(e, m, i);
940
1242
  return {
941
- version: r,
942
- issuer: parseIssuer(e, a),
943
- thisUpdate: x(o),
944
- ...u === void 0 ? {} : { nextUpdate: u },
1243
+ version: i,
1244
+ signature: parseAlgorithmIdentifier(e, a),
1245
+ issuer: parseIssuer(e, s),
1246
+ thisUpdate: A(c),
1247
+ ...d === void 0 ? {} : { nextUpdate: d },
945
1248
  ...h.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: h.authorityKeyIdentifier },
946
1249
  ...h.crlNumber === void 0 ? {} : { crlNumber: h.crlNumber },
947
1250
  ...h.baseCrlNumber === void 0 ? {} : { baseCrlNumber: h.baseCrlNumber },
948
1251
  ...h.issuingDistributionPoint === void 0 ? {} : { issuingDistributionPoint: h.issuingDistributionPoint },
949
1252
  ...h.freshestCrlDistributionPoints === void 0 ? {} : { freshestCrlDistributionPoints: h.freshestCrlDistributionPoints },
950
- revokedCertificates: f
1253
+ revokedCertificates: p
951
1254
  };
952
1255
  }
953
1256
  function parseCrlVersionField(e) {
@@ -957,7 +1260,7 @@ function parseCrlVersionField(e) {
957
1260
  version: 1,
958
1261
  nextIndex: 0
959
1262
  };
960
- let n = g(t.value) + 1;
1263
+ let n = T(t.value) + 1;
961
1264
  if (n !== 2) throw Error(`Unsupported CRL version: ${String(n)}`);
962
1265
  return {
963
1266
  version: n,
@@ -965,17 +1268,17 @@ function parseCrlVersionField(e) {
965
1268
  };
966
1269
  }
967
1270
  function parseRevokedCertificates(e, t, n) {
968
- return m(e, t).map((t) => parseRevokedCertificateEntry(e, t, n));
1271
+ return S(e, t).map((t) => parseRevokedCertificateEntry(e, t, n));
969
1272
  }
970
1273
  function parseRevokedCertificateEntry(e, t, n) {
971
- let r = e.slice(t.start - t.headerLength, t.end), i = u(r), a = S(i[0], "revoked serialNumber");
1274
+ let r = e.slice(t.start - t.headerLength, t.end), i = v(r), a = j(i[0], "revoked serialNumber");
972
1275
  if (a.tag !== 2) throw Error("revoked serialNumber must use INTEGER");
973
1276
  let o = i[2];
974
1277
  if (o !== void 0 && n !== 2) throw Error("revoked certificate extensions require CRL version 2");
975
1278
  let s = parseRevokedCertificateExtensions(r, o);
976
1279
  return {
977
- serialNumberHex: C(a.value),
978
- revocationDate: x(S(i[1], "revocationDate")),
1280
+ serialNumberHex: M(a.value),
1281
+ revocationDate: A(j(i[1], "revocationDate")),
979
1282
  ...s.reasonCode === void 0 ? {} : { reasonCode: s.reasonCode },
980
1283
  ...s.invalidityDate === void 0 ? {} : { invalidityDate: s.invalidityDate },
981
1284
  ...s.certificateIssuer === void 0 ? {} : { certificateIssuer: s.certificateIssuer }
@@ -984,34 +1287,34 @@ function parseRevokedCertificateEntry(e, t, n) {
984
1287
  function parseCrlExtensionFields(e, t, n) {
985
1288
  if (t?.tag !== 160) return {};
986
1289
  if (n !== 2) throw Error("CRL extensions require version 2");
987
- let r = {}, i = /* @__PURE__ */ new Set(), a = S(m(e, t)[0], "crl extensions");
988
- for (let t of m(e, a)) parseCrlExtensionField(e, t, i, r);
1290
+ let r = {}, i = /* @__PURE__ */ new Set(), a = j(S(e, t)[0], "crl extensions");
1291
+ for (let t of S(e, a)) parseCrlExtensionField(e, t, i, r);
989
1292
  return r;
990
1293
  }
991
1294
  function parseCrlExtensionField(e, t, n, r) {
992
- let i = m(e, t);
1295
+ let i = S(e, t);
993
1296
  if (i.length < 2 || i.length > 3 || i.length === 3 && i[1]?.tag !== 1) throw Error("Malformed CRL extension");
994
- let a = _(S(i[0], "extension OID").value);
1297
+ let a = E(j(i[0], "extension OID").value);
995
1298
  if (n.has(a)) throw Error(`Duplicate CRL extension OID: ${a}`);
996
1299
  n.add(a);
997
- let o = i.length === 3 && h(S(i[1], "extension critical").value), s = S(i[i.length - 1], "extension value");
1300
+ let o = i.length === 3 && C(j(i[1], "extension critical").value), s = j(i[i.length - 1], "extension value");
998
1301
  if (s.tag !== 4) throw Error("CRL extension value must use OCTET STRING");
999
1302
  if (!isSupportedCrlExtensionOid(a) && o) throw Error(`Unsupported critical CRL extension OID: ${a}`);
1000
1303
  applyParsedCrlExtensionField(a, s.value, r);
1001
1304
  }
1002
1305
  function isSupportedCrlExtensionOid(e) {
1003
- return e === w.authorityKeyIdentifier || e === w.cRLNumber || e === w.deltaCRLIndicator || e === w.issuingDistributionPoint || e === w.freshestCRL;
1306
+ return e === N.authorityKeyIdentifier || e === N.cRLNumber || e === N.deltaCRLIndicator || e === N.issuingDistributionPoint || e === N.freshestCRL;
1004
1307
  }
1005
1308
  function applyParsedCrlExtensionField(e, t, n) {
1006
- if (e === w.authorityKeyIdentifier) {
1309
+ if (e === N.authorityKeyIdentifier) {
1007
1310
  let e = parseAuthorityKeyIdentifier(t);
1008
1311
  e !== void 0 && (n.authorityKeyIdentifier = e);
1009
1312
  }
1010
- e === w.cRLNumber && (n.crlNumber = g(c(t).value)), e === w.deltaCRLIndicator && (n.baseCrlNumber = g(c(t).value)), e === w.issuingDistributionPoint && (n.issuingDistributionPoint = parseIssuingDistributionPoint(t)), e === w.freshestCRL && (n.freshestCrlDistributionPoints = parseDistributionPoints(t));
1313
+ e === N.cRLNumber && (n.crlNumber = decodeCrlNumber(t)), e === N.deltaCRLIndicator && (n.baseCrlNumber = decodeCrlNumber(t)), e === N.issuingDistributionPoint && (n.issuingDistributionPoint = parseIssuingDistributionPoint(t)), e === N.freshestCRL && (n.freshestCrlDistributionPoints = parseDistributionPoints(t));
1011
1314
  }
1012
1315
  /** Accepts PEM, DER, or already-parsed certificate and returns a parsed certificate. */
1013
1316
  function normalizeCrlCertificate(e) {
1014
- return hasParsedCertificateShape(e) ? U(new Uint8Array(e.der)) : W(e);
1317
+ return hasParsedCertificateShape(e) ? ce(new Uint8Array(e.der)) : Z(e);
1015
1318
  }
1016
1319
  function hasParsedCertificateShape(e) {
1017
1320
  return typeof e != "string" && "subjectPublicKeyInfoDer" in e;
@@ -1019,9 +1322,6 @@ function hasParsedCertificateShape(e) {
1019
1322
  function hasReparseableCrlShape(e) {
1020
1323
  return "der" in e && e.der instanceof Uint8Array;
1021
1324
  }
1022
- /** Shared UTF-8 decoder instance. */
1023
- const Q = new TextDecoder();
1024
- //#endregion
1025
- export { checkCertificateRevocationAgainstCrl, createCertificateRevocationList, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, revocationReasonFromCode, validateCertificateRevocationList, verifyCertificateRevocationListSignature };
1325
+ export { Q as ALL_DISTRIBUTION_POINT_REASONS, assertCrlMaxAge, authenticateCrl, checkCertificateRevocationAgainstCrl, checkRevocationAgainstAuthenticatedCrl, coversAllDistributionPointReasons, createCertificateRevocationList, isCertificateRevoked, isCrlApplicableTo, isCurrentDeltaCrl, normalizeCrl, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, revocationReasonFromCode, validateCertificateRevocationList, verifyCertificateRevocationListSignature };
1026
1326
 
1027
1327
  //# sourceMappingURL=crl.js.map