micro509 0.9.0 → 0.10.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 (107) hide show
  1. package/dist/index.d.ts +3 -3
  2. package/dist/index.js +15 -15
  3. package/dist/internal/asn1/asn1.js +145 -186
  4. package/dist/internal/asn1/asn1.js.map +1 -0
  5. package/dist/internal/asn1/der.js +210 -227
  6. package/dist/internal/asn1/der.js.map +1 -0
  7. package/dist/internal/asn1/oids.js +297 -101
  8. package/dist/internal/asn1/oids.js.map +1 -0
  9. package/dist/internal/asn1/oids2.js +69 -0
  10. package/dist/internal/asn1/oids2.js.map +1 -0
  11. package/dist/internal/crypto/algorithm-names.js +37 -35
  12. package/dist/internal/crypto/algorithm-names.js.map +1 -0
  13. package/dist/internal/crypto/ecdsa.js +25 -28
  14. package/dist/internal/crypto/ecdsa.js.map +1 -0
  15. package/dist/internal/crypto/hash.js +56 -117
  16. package/dist/internal/crypto/hash.js.map +1 -0
  17. package/dist/internal/crypto/pbes2.js +122 -133
  18. package/dist/internal/crypto/pbes2.js.map +1 -0
  19. package/dist/internal/crypto/rsa-pss.js +118 -124
  20. package/dist/internal/crypto/rsa-pss.js.map +1 -0
  21. package/dist/internal/crypto/sig-verify.js +87 -99
  22. package/dist/internal/crypto/sig-verify.js.map +1 -0
  23. package/dist/internal/crypto/signing.d.ts +12 -8
  24. package/dist/internal/crypto/signing.js +53 -55
  25. package/dist/internal/crypto/signing.js.map +1 -0
  26. package/dist/internal/crypto/webcrypto.js +5 -3
  27. package/dist/internal/crypto/webcrypto.js.map +1 -0
  28. package/dist/internal/shared/base64.js +10 -9
  29. package/dist/internal/shared/base64.js.map +1 -0
  30. package/dist/internal/shared/dn.js +50 -57
  31. package/dist/internal/shared/dn.js.map +1 -0
  32. package/dist/internal/shared/ip.js +43 -53
  33. package/dist/internal/shared/ip.js.map +1 -0
  34. package/dist/internal/verify/name-constraints-engine.js +211 -239
  35. package/dist/internal/verify/name-constraints-engine.js.map +1 -0
  36. package/dist/internal/verify/policy-engine.js +228 -247
  37. package/dist/internal/verify/policy-engine.js.map +1 -0
  38. package/dist/internal/verify/verify-path.js +213 -228
  39. package/dist/internal/verify/verify-path.js.map +1 -0
  40. package/dist/internal/x509/extension-bits.js +62 -59
  41. package/dist/internal/x509/extension-bits.js.map +1 -0
  42. package/dist/internal/x509/extension-registry.js +133 -164
  43. package/dist/internal/x509/extension-registry.js.map +1 -0
  44. package/dist/internal/x509/name-fields.js +35 -41
  45. package/dist/internal/x509/name-fields.js.map +1 -0
  46. package/dist/keys/keys.d.ts +583 -547
  47. package/dist/keys/keys.js +519 -431
  48. package/dist/keys/keys.js.map +1 -0
  49. package/dist/keys.js +2 -2
  50. package/dist/pem/pem.d.ts +46 -46
  51. package/dist/pem/pem.js +62 -81
  52. package/dist/pem/pem.js.map +1 -0
  53. package/dist/pem.js +2 -2
  54. package/dist/pkcs/pfx.d.ts +96 -80
  55. package/dist/pkcs/pfx.js +191 -231
  56. package/dist/pkcs/pfx.js.map +1 -0
  57. package/dist/pkcs/pkcs12-mac.d.ts +20 -18
  58. package/dist/pkcs/pkcs12-mac.js +90 -111
  59. package/dist/pkcs/pkcs12-mac.js.map +1 -0
  60. package/dist/pkcs/pkcs7.d.ts +118 -69
  61. package/dist/pkcs/pkcs7.js +401 -443
  62. package/dist/pkcs/pkcs7.js.map +1 -0
  63. package/dist/pkcs.d.ts +2 -2
  64. package/dist/pkcs.js +4 -4
  65. package/dist/result/result.d.ts +37 -32
  66. package/dist/result/result.js +46 -44
  67. package/dist/result/result.js.map +1 -0
  68. package/dist/result.js +2 -2
  69. package/dist/revocation/chain.d.ts +138 -119
  70. package/dist/revocation/chain.js +248 -281
  71. package/dist/revocation/chain.js.map +1 -0
  72. package/dist/revocation/crl.d.ts +125 -123
  73. package/dist/revocation/crl.js +653 -745
  74. package/dist/revocation/crl.js.map +1 -0
  75. package/dist/revocation/ocsp.d.ts +183 -177
  76. package/dist/revocation/ocsp.js +579 -636
  77. package/dist/revocation/ocsp.js.map +1 -0
  78. package/dist/revocation/revocation.d.ts +26 -26
  79. package/dist/revocation/revocation.js +104 -125
  80. package/dist/revocation/revocation.js.map +1 -0
  81. package/dist/revocation.js +5 -5
  82. package/dist/verify/identity.d.ts +42 -42
  83. package/dist/verify/identity.js +158 -167
  84. package/dist/verify/identity.js.map +1 -0
  85. package/dist/verify/name-constraints.d.ts +7 -7
  86. package/dist/verify/policy.d.ts +10 -10
  87. package/dist/verify/verify.d.ts +163 -163
  88. package/dist/verify/verify.js +396 -392
  89. package/dist/verify/verify.js.map +1 -0
  90. package/dist/verify.js +3 -3
  91. package/dist/x509/certificate.d.ts +117 -117
  92. package/dist/x509/certificate.js +51 -60
  93. package/dist/x509/certificate.js.map +1 -0
  94. package/dist/x509/csr.d.ts +25 -25
  95. package/dist/x509/csr.js +26 -30
  96. package/dist/x509/csr.js.map +1 -0
  97. package/dist/x509/extensions.d.ts +228 -184
  98. package/dist/x509/extensions.js +175 -200
  99. package/dist/x509/extensions.js.map +1 -0
  100. package/dist/x509/name.d.ts +94 -93
  101. package/dist/x509/name.js +30 -29
  102. package/dist/x509/name.js.map +1 -0
  103. package/dist/x509/parse.d.ts +185 -185
  104. package/dist/x509/parse.js +638 -676
  105. package/dist/x509/parse.js.map +1 -0
  106. package/dist/x509.js +6 -6
  107. package/package.json +79 -41
@@ -1,20 +1,20 @@
1
- import { bitString, concatBytes, explicitContext, generalizedTime, implicitConstructedContext, implicitPrimitiveContext, integer, integerFromNumber, readElement, readRootElement, readSequenceChildren, sequence, time, tlv } from "../internal/asn1/der.js";
2
- import { childrenOf, decodeBoolean, decodeIntegerNumber, decodeObjectIdentifier, decodeString, extractBitStringValue, hexToBytes, parseTime, requireElement, toHex } from "../internal/asn1/asn1.js";
3
- import { OIDS } from "../internal/asn1/oids.js";
4
- import { base64Encode } from "../internal/shared/base64.js";
5
- import { failureResult, rethrowIfInvariant, successResult } from "../result/result.js";
6
- import { pemDecodeOrThrow, pemEncode } from "../pem/pem.js";
7
- import { exportSpkiDer } from "../keys/keys.js";
8
- import { describeSignatureAlgorithm } from "../internal/crypto/algorithm-names.js";
9
- import { decodeIpAddress } from "../internal/shared/ip.js";
10
- import { encodeDistributionPointReasonFlagsContent, parseDistributionPointReasonFlagsContent } from "../internal/x509/extension-bits.js";
11
- import { nameFieldKeyFromOid } from "../internal/x509/name-fields.js";
12
- import { encodeName, encodeRelativeDistinguishedName } from "../x509/name.js";
13
- import { buildSubjectKeyIdentifier, encodeCrlDistributionPoints, encodeExtension, encodeSubjectAltName } from "../x509/extensions.js";
14
- import { parseCertificateDerOrThrow, parseCertificateFromSource } from "../x509/parse.js";
15
- import { verifySignedDataDetailed } from "../internal/crypto/sig-verify.js";
16
- import { encodeAlgorithmIdentifier, getSignatureAlgorithm, signBytes } from "../internal/crypto/signing.js";
17
- import { compareDistinguishedNames, compareNameAttributeValue } from "../internal/shared/dn.js";
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
18
  //#region src/revocation/crl.ts
19
19
  /**
20
20
  * Full CRL lifecycle: create, parse, verify, validate, and revocation check.
@@ -25,7 +25,7 @@ import { compareDistinguishedNames, compareNameAttributeValue } from "../interna
25
25
  * @module
26
26
  */
27
27
  /** RFC 5280 §5.3.1 CRLReason integer codes, keyed by reason name. */
28
- const REVOCATION_REASON_CODES = {
28
+ const Z = {
29
29
  unspecified: 0,
30
30
  keyCompromise: 1,
31
31
  cACompromise: 2,
@@ -61,32 +61,24 @@ const REVOCATION_REASON_CODES = {
61
61
  * // crl.pem, crl.der, crl.base64
62
62
  * ```
63
63
  */
64
- async function createCertificateRevocationList(input) {
65
- const signatureAlgorithm = getSignatureAlgorithm(input.signerPrivateKey);
66
- const thisUpdate = input.thisUpdate ?? /* @__PURE__ */ new Date();
67
- const nextUpdate = input.nextUpdate;
68
- const extensions = await buildCrlExtensions(input.issuerPublicKey, input.crlNumber, input.baseCrlNumber, input.issuingDistributionPoint, input.freshestCrlDistributionPoints);
69
- const revoked = input.revokedCertificates ?? [];
70
- const revokedSequence = revoked.length === 0 ? [] : [sequence(revoked.map((entry) => createRevokedCertificate(entry, thisUpdate)))];
71
- const tbsCertList = sequence([
72
- integerFromNumber(1),
73
- encodeAlgorithmIdentifier(signatureAlgorithm),
74
- encodeName(input.issuer),
75
- time(thisUpdate),
76
- ...nextUpdate === void 0 ? [] : [time(nextUpdate)],
77
- ...revokedSequence,
78
- ...extensions.length === 0 ? [] : [explicitContext(0, sequence(extensions))]
79
- ]);
80
- const signatureValue = await signBytes(input.signerPrivateKey, signatureAlgorithm, tbsCertList);
81
- const der = sequence([
82
- tbsCertList,
83
- encodeAlgorithmIdentifier(signatureAlgorithm),
84
- bitString(signatureValue)
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)
85
77
  ]);
86
78
  return {
87
- der,
88
- pem: pemEncode("X509 CRL", der),
89
- base64: base64Encode(der)
79
+ der: m,
80
+ pem: A("X509 CRL", m),
81
+ base64: T(m)
90
82
  };
91
83
  }
92
84
  /**
@@ -95,31 +87,27 @@ async function createCertificateRevocationList(input) {
95
87
  * Does not verify the signature — call {@linkcode verifyCertificateRevocationListSignature} or
96
88
  * {@linkcode validateCertificateRevocationList} for that.
97
89
  */
98
- function parseCertificateRevocationListDerOrThrow(der) {
99
- const top = readSequenceChildren(der, { maxDepth: 64 });
100
- if (top.length !== 3) throw new Error("Malformed CRL");
101
- const tbsCertList = requireElement(top[0], "TBSCertList");
102
- const signatureAlgorithm = requireElement(top[1], "signatureAlgorithm");
103
- const signatureValue = requireElement(top[2], "signatureValue");
104
- const signedFields = parseSignedCrlFields(der.slice(tbsCertList.start - tbsCertList.headerLength, tbsCertList.end));
105
- const parsedSignatureAlgorithm = parseAlgorithmIdentifier(der, signatureAlgorithm);
90
+ function parseCertificateRevocationListDerOrThrow(e) {
91
+ let t = u(e, { maxDepth: 64 });
92
+ 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);
106
94
  return {
107
- der: new Uint8Array(der),
108
- version: signedFields.version,
109
- tbsCertListDer: der.slice(tbsCertList.start - tbsCertList.headerLength, tbsCertList.end),
110
- signatureValue: extractBitStringValue(signatureValue),
111
- issuer: signedFields.issuer,
112
- thisUpdate: signedFields.thisUpdate,
113
- ...signedFields.nextUpdate === void 0 ? {} : { nextUpdate: signedFields.nextUpdate },
114
- signatureAlgorithmOid: parsedSignatureAlgorithm.oid,
115
- signatureAlgorithmName: describeSignatureAlgorithm(parsedSignatureAlgorithm.oid, parsedSignatureAlgorithm.parametersDer),
116
- ...parsedSignatureAlgorithm.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: parsedSignatureAlgorithm.parametersDer },
117
- ...signedFields.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: signedFields.authorityKeyIdentifier },
118
- ...signedFields.crlNumber === void 0 ? {} : { crlNumber: signedFields.crlNumber },
119
- ...signedFields.baseCrlNumber === void 0 ? {} : { baseCrlNumber: signedFields.baseCrlNumber },
120
- ...signedFields.issuingDistributionPoint === void 0 ? {} : { issuingDistributionPoint: signedFields.issuingDistributionPoint },
121
- ...signedFields.freshestCrlDistributionPoints === void 0 ? {} : { freshestCrlDistributionPoints: signedFields.freshestCrlDistributionPoints },
122
- revokedCertificates: signedFields.revokedCertificates
95
+ der: new Uint8Array(e),
96
+ version: a.version,
97
+ tbsCertListDer: e.slice(n.start - n.headerLength, n.end),
98
+ signatureValue: y(i),
99
+ issuer: a.issuer,
100
+ thisUpdate: a.thisUpdate,
101
+ ...a.nextUpdate === void 0 ? {} : { nextUpdate: a.nextUpdate },
102
+ signatureAlgorithmOid: o.oid,
103
+ signatureAlgorithmName: M(o.oid, o.parametersDer),
104
+ ...o.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: o.parametersDer },
105
+ ...a.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: a.authorityKeyIdentifier },
106
+ ...a.crlNumber === void 0 ? {} : { crlNumber: a.crlNumber },
107
+ ...a.baseCrlNumber === void 0 ? {} : { baseCrlNumber: a.baseCrlNumber },
108
+ ...a.issuingDistributionPoint === void 0 ? {} : { issuingDistributionPoint: a.issuingDistributionPoint },
109
+ ...a.freshestCrlDistributionPoints === void 0 ? {} : { freshestCrlDistributionPoints: a.freshestCrlDistributionPoints },
110
+ revokedCertificates: a.revokedCertificates
123
111
  };
124
112
  }
125
113
  /**
@@ -133,8 +121,8 @@ function parseCertificateRevocationListDerOrThrow(der) {
133
121
  * console.log(crl.issuer.values.commonName, crl.revokedCertificates.length);
134
122
  * ```
135
123
  */
136
- function parseCertificateRevocationListPemOrThrow(pem) {
137
- return parseCertificateRevocationListDerOrThrow(pemDecodeOrThrow("X509 CRL", pem));
124
+ function parseCertificateRevocationListPemOrThrow(e) {
125
+ return parseCertificateRevocationListDerOrThrow(k("X509 CRL", e));
138
126
  }
139
127
  /**
140
128
  * Decodes a DER-encoded X.509 CRL into a structured {@linkcode ParsedCertificateRevocationList}.
@@ -144,12 +132,11 @@ function parseCertificateRevocationListPemOrThrow(pem) {
144
132
  * Does not verify the signature — call {@linkcode verifyCertificateRevocationListSignature} or
145
133
  * {@linkcode validateCertificateRevocationList} for that.
146
134
  */
147
- function parseCertificateRevocationListDer(der) {
135
+ function parseCertificateRevocationListDer(e) {
148
136
  try {
149
- return successResult(parseCertificateRevocationListDerOrThrow(der));
150
- } catch (error) {
151
- rethrowIfInvariant(error);
152
- return failureResult("malformed", error instanceof Error ? error.message : "Malformed CRL");
137
+ return O(parseCertificateRevocationListDerOrThrow(e));
138
+ } catch (e) {
139
+ return D(e), E("malformed", e instanceof Error ? e.message : "Malformed CRL");
153
140
  }
154
141
  }
155
142
  /**
@@ -158,12 +145,11 @@ function parseCertificateRevocationListDer(der) {
158
145
  * Returns a typed failure (`code: 'malformed'`) on malformed input. For the
159
146
  * throwing form use {@linkcode parseCertificateRevocationListPemOrThrow}.
160
147
  */
161
- function parseCertificateRevocationListPem(pem) {
148
+ function parseCertificateRevocationListPem(e) {
162
149
  try {
163
- return successResult(parseCertificateRevocationListPemOrThrow(pem));
164
- } catch (error) {
165
- rethrowIfInvariant(error);
166
- return failureResult("malformed", error instanceof Error ? error.message : "Malformed CRL");
150
+ return O(parseCertificateRevocationListPemOrThrow(e));
151
+ } catch (e) {
152
+ return D(e), E("malformed", e instanceof Error ? e.message : "Malformed CRL");
167
153
  }
168
154
  }
169
155
  /**
@@ -172,68 +158,57 @@ function parseCertificateRevocationListPem(pem) {
172
158
  * Does **not** check issuer name match, key-usage, or freshness — use
173
159
  * {@linkcode validateCertificateRevocationList} for full validation.
174
160
  */
175
- async function verifyCertificateRevocationListSignature(crl, issuerCertificate) {
176
- let parsedCrl;
177
- let issuer;
161
+ async function verifyCertificateRevocationListSignature(e, t) {
162
+ let n, r;
178
163
  try {
179
- parsedCrl = typeof crl === "string" ? parseCertificateRevocationListPemOrThrow(crl) : parseCertificateRevocationListDerOrThrow(new Uint8Array(crl));
180
- issuer = typeof issuerCertificate === "string" ? parseIssuerCertificatePem(issuerCertificate) : parseIssuerCertificateDer(new Uint8Array(issuerCertificate));
164
+ n = typeof e == "string" ? parseCertificateRevocationListPemOrThrow(e) : parseCertificateRevocationListDerOrThrow(new Uint8Array(e)), r = typeof t == "string" ? parseIssuerCertificatePem(t) : parseIssuerCertificateDer(new Uint8Array(t));
181
165
  } catch {
182
166
  return verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list or issuer certificate input is malformed");
183
167
  }
184
- let verifiedResult;
168
+ let i;
185
169
  try {
186
- verifiedResult = await verifySignedDataDetailed(parsedCrl.signatureAlgorithmOid, parsedCrl.signatureAlgorithmParametersDer, issuer.publicKeyAlgorithmOid, issuer.publicKeyParametersOid, issuer.subjectPublicKeyInfoDer, parsedCrl.signatureValue, parsedCrl.tbsCertListDer);
170
+ i = await G(n.signatureAlgorithmOid, n.signatureAlgorithmParametersDer, r.publicKeyAlgorithmOid, r.publicKeyParametersOid, r.subjectPublicKeyInfoDer, n.signatureValue, n.tbsCertListDer);
187
171
  } catch {
188
172
  return verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed");
189
173
  }
190
- if (!verifiedResult.ok) {
191
- if (verifiedResult.code === "verification_error") return verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed");
192
- return verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature uses unsupported algorithm parameters");
193
- }
194
- return verifiedResult.valid ? {
195
- ok: true,
196
- value: parsedCrl
197
- } : verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify");
174
+ return i.ok ? i.valid ? {
175
+ 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");
198
178
  }
199
179
  /**
200
180
  * Full CRL validation: issuer name match, authority key identifier match,
201
181
  * cRLSign key-usage check, signature verification, and `thisUpdate`/`nextUpdate`
202
182
  * freshness check (with optional clock-skew tolerance).
203
183
  */
204
- async function validateCertificateRevocationList(input) {
205
- let parsedCrl;
184
+ async function validateCertificateRevocationList(e) {
185
+ let t;
206
186
  try {
207
- parsedCrl = normalizeCrl(input.crl);
187
+ t = normalizeCrl(e.crl);
208
188
  } catch {
209
189
  return validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signed content is malformed");
210
190
  }
211
- let issuer;
191
+ let n;
212
192
  try {
213
- issuer = normalizeCrlCertificate(input.issuerCertificate);
193
+ n = normalizeCrlCertificate(e.issuerCertificate);
214
194
  } catch {
215
195
  return validateCertificateRevocationListFailureResult("signature_invalid", "issuer certificate input is malformed");
216
196
  }
217
- if (!compareDistinguishedNames(parsedCrl.issuer, issuer.subject)) return validateCertificateRevocationListFailureResult("issuer_mismatch", "CRL issuer name does not match certificate subject");
218
- if (parsedCrl.authorityKeyIdentifier !== void 0 && issuer.subjectKeyIdentifier !== void 0 && parsedCrl.authorityKeyIdentifier !== issuer.subjectKeyIdentifier) return validateCertificateRevocationListFailureResult("issuer_mismatch", "CRL authority key identifier does not match issuer subject key identifier");
219
- if (issuer.keyUsage !== void 0 && !issuer.keyUsage.flags.includes("cRLSign")) return validateCertificateRevocationListFailureResult("crl_sign_not_permitted", "issuer certificate key usage does not permit CRL signing");
220
- let verifiedResult;
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;
221
201
  try {
222
- verifiedResult = await verifySignedDataDetailed(parsedCrl.signatureAlgorithmOid, parsedCrl.signatureAlgorithmParametersDer, issuer.publicKeyAlgorithmOid, issuer.publicKeyParametersOid, issuer.subjectPublicKeyInfoDer, parsedCrl.signatureValue, parsedCrl.tbsCertListDer);
202
+ r = await G(t.signatureAlgorithmOid, t.signatureAlgorithmParametersDer, n.publicKeyAlgorithmOid, n.publicKeyParametersOid, n.subjectPublicKeyInfoDer, t.signatureValue, t.tbsCertListDer);
223
203
  } catch {
224
204
  return validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed");
225
205
  }
226
- if (!verifiedResult.ok) {
227
- if (verifiedResult.code === "verification_error") return validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed");
228
- return validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature uses unsupported algorithm parameters");
229
- }
230
- if (!verifiedResult.valid) return validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify");
231
- const at = input.at ?? /* @__PURE__ */ new Date();
232
- const skew = input.clockSkewMs ?? 0;
233
- if (parsedCrl.thisUpdate.getTime() - skew > at.getTime() || parsedCrl.nextUpdate !== void 0 && parsedCrl.nextUpdate.getTime() + skew < at.getTime()) return validateCertificateRevocationListFailureResult("stale_crl", "CRL is not valid at requested time");
234
- return {
235
- ok: true,
236
- value: parsedCrl
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") : {
210
+ ok: !0,
211
+ value: t
237
212
  };
238
213
  }
239
214
  /**
@@ -258,219 +233,194 @@ async function validateCertificateRevocationList(input) {
258
233
  * }
259
234
  * ```
260
235
  */
261
- async function checkCertificateRevocationAgainstCrl(input) {
262
- let certificate;
236
+ async function checkCertificateRevocationAgainstCrl(e) {
237
+ let t;
263
238
  try {
264
- certificate = normalizeCrlCertificate(input.certificate);
239
+ t = normalizeCrlCertificate(e.certificate);
265
240
  } catch {
266
241
  return checkCertificateRevocationAgainstCrlFailureResult("non_applicable", "certificate input is malformed");
267
242
  }
268
- const validated = await validateCertificateRevocationList({
269
- crl: input.crl,
270
- issuerCertificate: input.issuerCertificate,
271
- ...input.at === void 0 ? {} : { at: input.at },
272
- ...input.clockSkewMs === void 0 ? {} : { clockSkewMs: input.clockSkewMs }
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 }
273
248
  });
274
- if (!validated.ok) return checkCertificateRevocationAgainstCrlFailureResult(validated.code, validated.message);
275
- let validatedDelta;
276
- if (input.deltaCrl !== void 0) {
277
- const deltaValidation = await validateCertificateRevocationList({
278
- crl: input.deltaCrl,
279
- issuerCertificate: input.issuerCertificate,
280
- ...input.at === void 0 ? {} : { at: input.at },
281
- ...input.clockSkewMs === void 0 ? {} : { clockSkewMs: input.clockSkewMs }
282
- });
283
- if (!deltaValidation.ok) return checkCertificateRevocationAgainstCrlFailureResult(deltaValidation.code, deltaValidation.message);
284
- const compatibilityFailure = checkDeltaCrlCompatibility(validated.value, deltaValidation.value);
285
- if (compatibilityFailure !== void 0) return compatibilityFailure;
286
- validatedDelta = deltaValidation.value;
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;
287
261
  }
288
- const applicabilityFailure = checkCrlApplicability(certificate, validated.value);
289
- if (applicabilityFailure !== void 0) return applicabilityFailure;
290
- if (validatedDelta !== void 0) {
291
- const deltaApplicabilityFailure = checkCrlApplicability(certificate, validatedDelta, true);
292
- if (deltaApplicabilityFailure !== void 0) return deltaApplicabilityFailure;
293
- }
294
- const completeRevoked = findRevokedCertificateEntry(certificate, validated.value);
295
- if (!completeRevoked.ok) return completeRevoked;
296
- let deltaRevoked;
297
- if (validatedDelta !== void 0) {
298
- const deltaLookup = findRevokedCertificateEntry(certificate, validatedDelta);
299
- if (!deltaLookup.ok) return deltaLookup;
300
- deltaRevoked = deltaLookup.entry;
301
- }
302
- return resolveCertificateRevocationStatus(certificate, input.at ?? /* @__PURE__ */ new Date(), validated.value, completeRevoked.entry, deltaRevoked);
262
+ return resolveCertificateRevocationStatus(t, e.at ?? /* @__PURE__ */ new Date(), n.value, a.entry, o);
263
+ }
264
+ /** Validates an optional delta CRL and checks compatibility with its complete CRL. */
265
+ async function validateOptionalDeltaCrl(e, t) {
266
+ if (e.deltaCrl === void 0) return { ok: !0 };
267
+ let n = await validateCertificateRevocationList({
268
+ crl: e.deltaCrl,
269
+ issuerCertificate: e.issuerCertificate,
270
+ ...e.at === void 0 ? {} : { at: e.at },
271
+ ...e.clockSkewMs === void 0 ? {} : { clockSkewMs: e.clockSkewMs }
272
+ });
273
+ return n.ok ? checkDeltaCrlCompatibility(t, n.value) ?? {
274
+ ok: !0,
275
+ 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;
303
281
  }
304
282
  /** Builds a `VerifyCertificateRevocationListSignatureFailureResult`. */
305
- function verifyCertificateRevocationListFailureResult(code, message) {
306
- return failureResult(code, message);
283
+ function verifyCertificateRevocationListFailureResult(e, t) {
284
+ return E(e, t);
307
285
  }
308
286
  /** Builds a `ValidateCertificateRevocationListFailureResult`. */
309
- function validateCertificateRevocationListFailureResult(code, message) {
310
- return failureResult(code, message);
287
+ function validateCertificateRevocationListFailureResult(e, t) {
288
+ return E(e, t);
311
289
  }
312
290
  /** Builds a `CheckCertificateRevocationAgainstCrlFailureResult`. */
313
- function checkCertificateRevocationAgainstCrlFailureResult(code, message, details) {
314
- return failureResult(code, message, details);
291
+ function checkCertificateRevocationAgainstCrlFailureResult(e, t, n) {
292
+ return E(e, t, n);
315
293
  }
316
294
  /** Wraps a success value into a `CheckCertificateRevocationAgainstCrlResult`. */
317
- function checkCertificateRevocationAgainstCrlSuccess(value) {
295
+ function checkCertificateRevocationAgainstCrlSuccess(e) {
318
296
  return {
319
- ok: true,
320
- value
297
+ ok: !0,
298
+ value: e
321
299
  };
322
300
  }
323
301
  /**
324
302
  * Quick serial-number lookup — returns `true` if the serial appears in the
325
303
  * CRL's revoked entries. Does **not** validate the CRL or check applicability.
326
304
  */
327
- function isCertificateRevoked(certificateSerialNumber, crl) {
328
- const serialNumberHex = typeof certificateSerialNumber === "string" ? normalizeHex(certificateSerialNumber) : toHex(certificateSerialNumber);
329
- return crl.revokedCertificates.some((entry) => normalizeHex(entry.serialNumberHex) === serialNumberHex);
305
+ function isCertificateRevoked(e, t) {
306
+ let n = typeof e == "string" ? normalizeHex(e) : C(e);
307
+ return t.revokedCertificates.some((e) => normalizeHex(e.serialNumberHex) === n);
330
308
  }
331
309
  /** Searches CRL entries for the certificate's serial, respecting indirect-CRL issuer overrides. */
332
- function findRevokedCertificateEntry(certificate, crl) {
333
- const serialNumberHex = normalizeHex(certificate.serialNumberHex);
334
- let effectiveIssuer;
335
- let sawUnsupportedIssuer = false;
336
- let matchedEntry;
337
- for (const entry of crl.revokedCertificates) {
338
- if (entry.certificateIssuer !== void 0) effectiveIssuer = entry.certificateIssuer;
339
- if (normalizeHex(entry.serialNumberHex) !== serialNumberHex) continue;
340
- const issuerMatch = matchesRevokedEntryIssuer(certificate, crl, effectiveIssuer);
341
- if (issuerMatch === "match") {
342
- if (matchedEntry !== void 0) return checkCertificateRevocationAgainstCrlFailureResult("signature_invalid", "CRL contains multiple revoked entries for certificate");
343
- matchedEntry = entry;
310
+ function findRevokedCertificateEntry(e, t) {
311
+ let n = normalizeHex(e.serialNumberHex), r, i = !1, a;
312
+ for (let o of t.revokedCertificates) {
313
+ if (o.certificateIssuer !== void 0 && (r = o.certificateIssuer), normalizeHex(o.serialNumberHex) !== n) continue;
314
+ let s = matchesRevokedEntryIssuer(e, t, r);
315
+ if (s === "match") {
316
+ if (a !== void 0) return checkCertificateRevocationAgainstCrlFailureResult("signature_invalid", "CRL contains multiple revoked entries for certificate");
317
+ a = o;
344
318
  continue;
345
319
  }
346
- if (issuerMatch === "unsupported") sawUnsupportedIssuer = true;
320
+ s === "unsupported" && (i = !0);
347
321
  }
348
- if (matchedEntry !== void 0) return {
349
- ok: true,
350
- entry: matchedEntry
322
+ return a === void 0 ? i ? nonApplicable("unsupported_indirect_crl", "indirect CRL entry certificateIssuer must include a directoryName") : { ok: !0 } : {
323
+ ok: !0,
324
+ entry: a
351
325
  };
352
- if (sawUnsupportedIssuer) return nonApplicable("unsupported_indirect_crl", "indirect CRL entry certificateIssuer must include a directoryName");
353
- return { ok: true };
354
326
  }
355
327
  /** RFC 5280 §6.3 CRL applicability: scope, distribution-point, reason, and indirect-CRL checks. */
356
- function checkCrlApplicability(certificate, crl, allowDeltaCrl = false) {
357
- if (!allowDeltaCrl && crl.baseCrlNumber !== void 0) return nonApplicable("unsupported_delta_crl", "a delta CRL cannot be used as the primary complete CRL input");
358
- const issuingDistributionPoint = crl.issuingDistributionPoint;
359
- const isIndirectCrl = issuingDistributionPoint?.indirectCrl === true;
360
- if (!isIndirectCrl && !compareDistinguishedNames(certificate.issuer, crl.issuer)) return nonApplicable("issuer_mismatch", "CRL issuer does not match certificate issuer for direct CRL processing");
361
- if (issuingDistributionPoint?.onlyContainsAttributeCerts === true) return nonApplicable("certificate_scope_mismatch", "attribute-certificate-only CRLs are not applicable to public-key certificates");
362
- const isCaCertificate = certificate.basicConstraints?.ca === true;
363
- if (issuingDistributionPoint?.onlyContainsUserCerts === true && isCaCertificate) return nonApplicable("certificate_scope_mismatch", "CRL only applies to end-entity certificates");
364
- if (issuingDistributionPoint?.onlyContainsCACerts === true && !isCaCertificate) return nonApplicable("certificate_scope_mismatch", "CRL only applies to CA certificates");
365
- const distributionPoints = certificate.crlDistributionPoints ?? [];
366
- if (distributionPoints.length === 0) {
367
- if (issuingDistributionPoint?.distributionPoint !== void 0) return nonApplicable("distribution_point_mismatch", "certificates without CRL distribution points only accept full-scope CRLs");
368
- if (isIndirectCrl && !compareDistinguishedNames(certificate.issuer, crl.issuer)) return nonApplicable("issuer_mismatch", "indirect CRLs for alternate certificate issuers require matching CRLIssuer distribution points");
369
- return;
328
+ 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");
330
+ 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");
333
+ 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");
336
+ 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));
338
+ }
339
+ /** Aggregates distribution-point matching outcomes across a certificate. */
340
+ 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);
370
346
  }
371
- let sawIndirectDistributionPoint = false;
372
- let sawDistributionMismatch = false;
373
- let sawIndirectIssuerMismatch = false;
374
- let sawIndirectIssuerUnsupported = false;
375
- let sawReasonsMismatch = false;
376
- for (const distributionPoint of distributionPoints) {
377
- if (!isIndirectCrl && distributionPoint.crlIssuer !== void 0) {
378
- sawIndirectDistributionPoint = true;
379
- continue;
380
- }
381
- if (isIndirectCrl) {
382
- if (!compareDistinguishedNames(certificate.issuer, crl.issuer) || distributionPoint.crlIssuer !== void 0) {
383
- const issuerMatch = matchesIndirectCrlIssuer(distributionPoint.crlIssuer, crl);
384
- if (issuerMatch === "unsupported") {
385
- sawIndirectIssuerUnsupported = true;
386
- continue;
387
- }
388
- if (!issuerMatch) {
389
- sawIndirectIssuerMismatch = true;
390
- continue;
391
- }
392
- }
393
- }
394
- if (!matchesDistributionPointName(distributionPoint.distributionPoint, issuingDistributionPoint?.distributionPoint, crl.issuer)) {
395
- sawDistributionMismatch = true;
396
- continue;
397
- }
398
- if (!hasOverlappingReasons(distributionPoint.reasons, issuingDistributionPoint?.onlySomeReasons)) {
399
- sawReasonsMismatch = true;
400
- continue;
401
- }
402
- return;
403
- }
404
- if (sawReasonsMismatch) return nonApplicable("reasons_mismatch", "certificate distribution point reasons do not overlap the CRL reason scope");
405
- if (sawIndirectIssuerUnsupported) return nonApplicable("unsupported_indirect_crl", "indirect CRL distribution points must identify the CRL issuer with directoryName");
406
- if (sawIndirectIssuerMismatch) return nonApplicable("issuer_mismatch", "certificate distribution points do not authorize this indirect CRL issuer");
407
- if (sawDistributionMismatch) return nonApplicable("distribution_point_mismatch", "certificate distribution points do not match the CRL issuing distribution point");
408
- if (sawIndirectDistributionPoint) return nonApplicable("unsupported_indirect_crl", "certificate distribution points that name alternate CRL issuers are not supported yet");
409
- return nonApplicable("distribution_point_mismatch", "certificate distribution points do not match the CRL scope");
347
+ return l ? "reasons_mismatch" : c ? "unsupported_indirect_crl_issuer" : s ? "indirect_issuer_mismatch" : o ? "distribution_point_mismatch" : a ? "indirect_distribution_point" : "scope_mismatch";
348
+ }
349
+ function scanCrlDistributionPoint(e, t, n, r, i) {
350
+ 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;
352
+ }
353
+ function scanCrlDistributionPointIssuer(e, t, n, r) {
354
+ if (!r) return e.crlIssuer === void 0 ? void 0 : "indirect_distribution_point";
355
+ if (Y(t.issuer, n.issuer) && e.crlIssuer === void 0) return;
356
+ let i = matchesIndirectCrlIssuer(e.crlIssuer, n);
357
+ return i === "unsupported" ? "unsupported_indirect_crl_issuer" : i ? void 0 : "indirect_issuer_mismatch";
358
+ }
359
+ 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");
410
361
  }
411
362
  /** Verifies that a delta CRL is compatible with the given complete CRL (same issuer, AKI, IDP, and valid numbering). */
412
- function checkDeltaCrlCompatibility(completeCrl, deltaCrl) {
413
- if (completeCrl.baseCrlNumber !== void 0) return nonApplicable("delta_crl_incompatible", "complete CRL input must not itself be a delta CRL");
414
- if (deltaCrl.baseCrlNumber === void 0) return nonApplicable("delta_crl_incompatible", "delta CRL input must include a delta CRL indicator");
415
- if (!compareDistinguishedNames(completeCrl.issuer, deltaCrl.issuer)) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same issuer");
416
- if (completeCrl.authorityKeyIdentifier !== deltaCrl.authorityKeyIdentifier) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same authority key identifier");
417
- if (!sameIssuingDistributionPoint(completeCrl.issuingDistributionPoint, deltaCrl.issuingDistributionPoint)) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same issuing distribution point scope");
418
- if (completeCrl.crlNumber === void 0 || deltaCrl.crlNumber === void 0) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must both carry CRL numbers for delta processing");
419
- if (completeCrl.crlNumber < deltaCrl.baseCrlNumber) return nonApplicable("delta_crl_incompatible", "delta CRL base number must not exceed the complete CRL number");
420
- if (completeCrl.crlNumber >= deltaCrl.crlNumber) return nonApplicable("delta_crl_incompatible", "delta CRL number must be newer than the complete CRL number");
363
+ function checkDeltaCrlCompatibility(e, t) {
364
+ if (e.baseCrlNumber !== void 0) return nonApplicable("delta_crl_incompatible", "complete CRL input must not itself be a delta CRL");
365
+ 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");
367
+ if (e.authorityKeyIdentifier !== t.authorityKeyIdentifier) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same authority key identifier");
368
+ if (!sameIssuingDistributionPoint(e.issuingDistributionPoint, t.issuingDistributionPoint)) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same issuing distribution point scope");
369
+ 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
+ if (e.crlNumber < t.baseCrlNumber) return nonApplicable("delta_crl_incompatible", "delta CRL base number must not exceed the complete CRL number");
371
+ if (e.crlNumber >= t.crlNumber) return nonApplicable("delta_crl_incompatible", "delta CRL number must be newer than the complete CRL number");
421
372
  }
422
373
  /** Checks whether any `crlIssuer` GeneralName matches the CRL's issuer via directoryName DER comparison. */
423
- function matchesIndirectCrlIssuer(crlIssuerNames, crl) {
424
- if (crlIssuerNames === void 0) return false;
425
- let sawUnsupportedName = false;
426
- for (const generalName of crlIssuerNames) {
427
- if (generalName.type === "directoryName") {
428
- if (directoryNameDerHexMatchesParsedName(generalName.derHex, crl.issuer)) return true;
374
+ function matchesIndirectCrlIssuer(e, t) {
375
+ if (e === void 0) return !1;
376
+ let n = !1;
377
+ for (let r of e) {
378
+ if (r.type === "directoryName") {
379
+ if (directoryNameDerHexMatchesParsedName(r.derHex, t.issuer)) return !0;
429
380
  continue;
430
381
  }
431
- sawUnsupportedName = true;
382
+ n = !0;
432
383
  }
433
- return sawUnsupportedName ? "unsupported" : false;
384
+ return n ? "unsupported" : !1;
434
385
  }
435
386
  /** Determines whether a revoked entry's effective issuer matches the certificate's issuer. */
436
- function matchesRevokedEntryIssuer(certificate, crl, effectiveIssuer) {
437
- if (effectiveIssuer === void 0) return compareDistinguishedNames(certificate.issuer, crl.issuer) ? "match" : "mismatch";
438
- let sawUnsupportedName = false;
439
- for (const generalName of effectiveIssuer) {
440
- if (generalName.type === "directoryName") {
441
- if (directoryNameDerHexMatchesParsedName(generalName.derHex, certificate.issuer)) return "match";
387
+ function matchesRevokedEntryIssuer(e, t, n) {
388
+ if (n === void 0) return Y(e.issuer, t.issuer) ? "match" : "mismatch";
389
+ let r = !1;
390
+ for (let t of n) {
391
+ if (t.type === "directoryName") {
392
+ if (directoryNameDerHexMatchesParsedName(t.derHex, e.issuer)) return "match";
442
393
  continue;
443
394
  }
444
- sawUnsupportedName = true;
395
+ r = !0;
445
396
  }
446
- return sawUnsupportedName ? "unsupported" : "mismatch";
397
+ return r ? "unsupported" : "mismatch";
447
398
  }
448
399
  /** Shorthand for building a `non_applicable` failure result with the given reason. */
449
- function nonApplicable(reason, message) {
450
- return checkCertificateRevocationAgainstCrlFailureResult("non_applicable", message, { reason });
400
+ function nonApplicable(e, t) {
401
+ return checkCertificateRevocationAgainstCrlFailureResult("non_applicable", t, { reason: e });
451
402
  }
452
403
  /** Merges complete and delta CRL entries per RFC 5280 §5.2.4 to produce a final `good`/`revoked` status. */
453
- function resolveCertificateRevocationStatus(certificate, at, completeCrl, completeEntry, deltaEntry) {
454
- if (deltaEntry !== void 0) if (deltaEntry.reasonCode === "removeFromCRL") {
455
- if (completeEntry?.reasonCode === "certificateHold" || certificate.notAfter.getTime() < at.getTime()) return checkCertificateRevocationAgainstCrlSuccess({
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({
456
407
  status: "good",
457
- crl: completeCrl
408
+ crl: n
458
409
  });
459
410
  } else return checkCertificateRevocationAgainstCrlSuccess({
460
411
  status: "revoked",
461
- crl: completeCrl,
462
- revocationDate: deltaEntry.revocationDate,
463
- ...deltaEntry.reasonCode === void 0 ? {} : { reasonCode: deltaEntry.reasonCode }
412
+ crl: n,
413
+ revocationDate: i.revocationDate,
414
+ ...i.reasonCode === void 0 ? {} : { reasonCode: i.reasonCode }
464
415
  });
465
- if (completeEntry === void 0) return checkCertificateRevocationAgainstCrlSuccess({
416
+ return checkCertificateRevocationAgainstCrlSuccess(r === void 0 ? {
466
417
  status: "good",
467
- crl: completeCrl
468
- });
469
- return checkCertificateRevocationAgainstCrlSuccess({
418
+ crl: n
419
+ } : {
470
420
  status: "revoked",
471
- crl: completeCrl,
472
- revocationDate: completeEntry.revocationDate,
473
- ...completeEntry.reasonCode === void 0 ? {} : { reasonCode: completeEntry.reasonCode }
421
+ crl: n,
422
+ revocationDate: r.revocationDate,
423
+ ...r.reasonCode === void 0 ? {} : { reasonCode: r.reasonCode }
474
424
  });
475
425
  }
476
426
  /**
@@ -480,370 +430,345 @@ function resolveCertificateRevocationStatus(certificate, at, completeCrl, comple
480
430
  * the full distribution point name is formed by appending that RDN to the CRL issuer's DN.
481
431
  * This resolved name is then compared against the CRL's IDP fullName directoryName entries.
482
432
  */
483
- function matchesDistributionPointName(certificatePoint, crlPoint, crlIssuer) {
484
- if (crlPoint === void 0) return true;
485
- if (certificatePoint === void 0) return false;
486
- if (certificatePoint.fullName !== void 0 && crlPoint.fullName !== void 0) return certificatePoint.fullName.some((leftName) => crlPoint.fullName?.some((rightName) => compareGeneralNames(leftName, rightName)) === true);
487
- if (certificatePoint.relativeName !== void 0 && crlPoint.fullName !== void 0) {
488
- const resolvedDnHex = resolveRelativeNameToDnHex(crlIssuer, certificatePoint.relativeName);
489
- return crlPoint.fullName.some((name) => name.type === "directoryName" && name.derHex === resolvedDnHex);
433
+ function matchesDistributionPointName(e, t, n) {
434
+ 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) {
438
+ let r = resolveRelativeNameToDnHex(n, e.relativeName);
439
+ return t.fullName.some((e) => e.type === "directoryName" && e.derHex === r);
490
440
  }
491
- if (certificatePoint.relativeName !== void 0 && crlPoint.relativeName !== void 0) return compareRelativeDistinguishedNames(certificatePoint.relativeName, crlPoint.relativeName);
492
- if (certificatePoint.fullName !== void 0 && crlPoint.relativeName !== void 0) {
493
- const resolvedDnHex = resolveRelativeNameToDnHex(crlIssuer, crlPoint.relativeName);
494
- return certificatePoint.fullName.some((name) => name.type === "directoryName" && name.derHex === resolvedDnHex);
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) {
443
+ let r = resolveRelativeNameToDnHex(n, t.relativeName);
444
+ return e.fullName.some((e) => e.type === "directoryName" && e.derHex === r);
495
445
  }
496
- return false;
446
+ return !1;
497
447
  }
498
448
  /** Constructs a full DN by appending an RDN to an existing Name, returning hex-encoded DER. */
499
- function resolveRelativeNameToDnHex(issuer, relativeName) {
500
- const rdnDerParts = issuer.rdns.map((rdn) => hexToBytes(rdn.derHex));
501
- const relativeNameRdnDer = rebuildRelativeNameAsSet(hexToBytes(relativeName.derHex));
502
- rdnDerParts.push(relativeNameRdnDer);
503
- return toHex(sequence(rdnDerParts));
449
+ 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));
504
452
  }
505
453
  /** Converts an implicit-tagged [1] relativeName to a proper SET-tagged RDN. */
506
- function rebuildRelativeNameAsSet(implicitTaggedDer) {
507
- return tlv(49, readRootElement(implicitTaggedDer, { maxDepth: 64 }).value);
454
+ function rebuildRelativeNameAsSet(e) {
455
+ return p(49, l(e, { maxDepth: 64 }).value);
508
456
  }
509
457
  /** Deep-compares two issuing distribution point extensions for delta-CRL compatibility. */
510
- function sameIssuingDistributionPoint(left, right) {
511
- if (left === void 0 || right === void 0) return left === right;
512
- return sameDistributionPointName(left.distributionPoint, right.distributionPoint) && left.onlyContainsUserCerts === true === (right.onlyContainsUserCerts === true) && left.onlyContainsCACerts === true === (right.onlyContainsCACerts === true) && left.indirectCrl === true === (right.indirectCrl === true) && left.onlyContainsAttributeCerts === true === (right.onlyContainsAttributeCerts === true) && sameReasonSet(left.onlySomeReasons, right.onlySomeReasons);
458
+ function sameIssuingDistributionPoint(e, t) {
459
+ return e === void 0 || t === void 0 ? e === t : sameDistributionPointName(e.distributionPoint, t.distributionPoint) && e.onlyContainsUserCerts === !0 == (t.onlyContainsUserCerts === !0) && e.onlyContainsCACerts === !0 == (t.onlyContainsCACerts === !0) && e.indirectCrl === !0 == (t.indirectCrl === !0) && e.onlyContainsAttributeCerts === !0 == (t.onlyContainsAttributeCerts === !0) && sameReasonSet(e.onlySomeReasons, t.onlySomeReasons);
513
460
  }
514
461
  /** Compares two DistributionPointName values (fullName set or relativeName). */
515
- function sameDistributionPointName(left, right) {
516
- if (left === void 0 || right === void 0) return left === right;
517
- if (left.fullName !== void 0 || right.fullName !== void 0) {
518
- if (left.fullName === void 0 || right.fullName === void 0) return false;
519
- return sameGeneralNameSet(left.fullName, right.fullName);
520
- }
521
- if (left.relativeName === void 0 || right.relativeName === void 0) return false;
522
- return compareRelativeDistinguishedNames(left.relativeName, right.relativeName);
462
+ 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);
523
464
  }
524
465
  /** Set-equality comparison for GeneralName arrays (order-independent). */
525
- function sameGeneralNameSet(left, right) {
526
- if (left.length !== right.length) return false;
527
- const matched = new Array(right.length).fill(false);
528
- for (const leftName of left) {
529
- let found = false;
530
- for (let index = 0; index < right.length; index += 1) {
531
- const rightName = right[index];
532
- if (rightName === void 0 || matched[index]) continue;
533
- if (!compareGeneralNames(leftName, rightName)) continue;
534
- matched[index] = true;
535
- found = true;
536
- break;
466
+ function sameGeneralNameSet(e, t) {
467
+ if (e.length !== t.length) return !1;
468
+ let n = Array(t.length).fill(!1);
469
+ for (let r of e) {
470
+ let e = !1;
471
+ for (let i = 0; i < t.length; i += 1) {
472
+ let a = t[i];
473
+ if (!(a === void 0 || n[i]) && compareGeneralNames(r, a)) {
474
+ n[i] = !0, e = !0;
475
+ break;
476
+ }
537
477
  }
538
- if (!found) return false;
478
+ if (!e) return !1;
539
479
  }
540
- return true;
480
+ return !0;
541
481
  }
542
482
  /** Set-equality comparison for DistributionPointReason arrays. */
543
- function sameReasonSet(left, right) {
544
- if (left === void 0 || right === void 0) return left === right;
545
- if (left.flags.length !== right.flags.length) return false;
546
- return left.flags.every((reason) => right.flags.includes(reason));
483
+ function sameReasonSet(e, t) {
484
+ return e === void 0 || t === void 0 ? e === t : e.flags.length === t.flags.length && e.flags.every((e) => t.flags.includes(e));
547
485
  }
548
486
  /** Returns `true` if the certificate's DP reasons overlap the CRL's `onlySomeReasons`, or if either is absent (= all reasons). */
549
- function hasOverlappingReasons(certificateReasons, crlReasons) {
550
- if (certificateReasons === void 0 || crlReasons === void 0) return true;
551
- return certificateReasons.flags.some((reason) => crlReasons.flags.includes(reason));
487
+ function hasOverlappingReasons(e, t) {
488
+ return e === void 0 || t === void 0 || e.flags.some((e) => t.flags.includes(e));
552
489
  }
553
490
  /** Value-equality for two GeneralName entries, using DER comparison for directoryName. */
554
- function compareGeneralNames(left, right) {
555
- if (left.type === "dns" && right.type === "dns") return left.value === right.value;
556
- if (left.type === "email" && right.type === "email") return left.value === right.value;
557
- if (left.type === "ip" && right.type === "ip") return left.value === right.value;
558
- if (left.type === "uri" && right.type === "uri") return left.value === right.value;
559
- if (left.type === "directoryName" && right.type === "directoryName") {
560
- const leftName = parseDerHexName(left.derHex);
561
- const rightName = parseDerHexName(right.derHex);
562
- if (leftName === void 0 || rightName === void 0) return false;
563
- return compareDistinguishedNames(leftName, rightName);
491
+ 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;
493
+ if (e.type === "directoryName" && t.type === "directoryName") {
494
+ let n = parseDerHexName(e.derHex), r = parseDerHexName(t.derHex);
495
+ return n === void 0 || r === void 0 ? !1 : Y(n, r);
564
496
  }
565
- if (left.type === "unknown" && right.type === "unknown") return left.tag === right.tag && bytesEqual(left.value, right.value);
566
- return false;
497
+ return e.type === "unknown" && t.type === "unknown" && e.tag === t.tag && bytesEqual(e.value, t.value);
567
498
  }
568
499
  /** Constant-length byte-array equality check. */
569
- function bytesEqual(left, right) {
570
- if (left.length !== right.length) return false;
571
- for (let index = 0; index < left.length; index += 1) if (left[index] !== right[index]) return false;
572
- return true;
500
+ function bytesEqual(e, t) {
501
+ if (e.length !== t.length) return !1;
502
+ for (let n = 0; n < e.length; n += 1) if (e[n] !== t[n]) return !1;
503
+ return !0;
573
504
  }
574
505
  /** Set-equality comparison for RDN attribute sets (order-independent, RFC 4518 string prep). */
575
- function compareRelativeDistinguishedNames(left, right) {
576
- if (left.attributes.length !== right.attributes.length) return false;
577
- const matched = new Array(right.attributes.length).fill(false);
578
- for (const leftAttribute of left.attributes) {
579
- let found = false;
580
- for (let index = 0; index < right.attributes.length; index += 1) {
581
- const rightAttribute = right.attributes[index];
582
- if (rightAttribute === void 0 || matched[index]) continue;
583
- if (!compareNameAttributeValue(leftAttribute, rightAttribute)) continue;
584
- matched[index] = true;
585
- found = true;
586
- break;
506
+ function compareRelativeDistinguishedNames(e, t) {
507
+ if (e.attributes.length !== t.attributes.length) return !1;
508
+ let n = Array(t.attributes.length).fill(!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
+ }
587
517
  }
588
- if (!found) return false;
518
+ if (!e) return !1;
589
519
  }
590
- return true;
520
+ return !0;
591
521
  }
592
522
  /** Assembles the CRL-level v2 extensions (AKI, CRLNumber, deltaCRLIndicator, IDP, freshestCRL). */
593
- async function buildCrlExtensions(issuerPublicKey, crlNumber, baseCrlNumber, issuingDistributionPoint, freshestCrlDistributionPoints) {
594
- const extensions = [];
595
- if (issuerPublicKey !== void 0) {
596
- const spki = await exportSpkiDer(issuerPublicKey);
597
- extensions.push(encodeExtension(OIDS.authorityKeyIdentifier, sequence([implicitPrimitiveContext(0, buildSubjectKeyIdentifier(spki))])));
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))])));
598
528
  }
599
- if (crlNumber !== void 0) extensions.push(encodeExtension(OIDS.cRLNumber, integerFromNumber(crlNumber)));
600
- if (baseCrlNumber !== void 0) extensions.push(encodeExtension(OIDS.deltaCRLIndicator, integerFromNumber(baseCrlNumber), true));
601
- if (issuingDistributionPoint !== void 0) extensions.push(encodeExtension(OIDS.issuingDistributionPoint, encodeIssuingDistributionPoint(issuingDistributionPoint), true));
602
- if (freshestCrlDistributionPoints !== void 0 && freshestCrlDistributionPoints.length > 0) extensions.push(encodeExtension(OIDS.freshestCRL, encodeCrlDistributionPoints(freshestCrlDistributionPoints)));
603
- return extensions;
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;
604
530
  }
605
531
  /** DER-encodes a single revokedCertificate SEQUENCE (serial, date, optional extensions). */
606
- function createRevokedCertificate(entry, thisUpdate) {
607
- const extensions = buildRevokedCertificateExtensions(entry);
608
- return sequence([
609
- integer(entry.serialNumber),
610
- time(entry.revocationDate ?? thisUpdate),
611
- ...extensions.length === 0 ? [] : [sequence(extensions)]
532
+ function createRevokedCertificate(e, t) {
533
+ let n = buildRevokedCertificateExtensions(e);
534
+ return d([
535
+ o(e.serialNumber),
536
+ f(e.revocationDate ?? t),
537
+ ...n.length === 0 ? [] : [d(n)]
612
538
  ]);
613
539
  }
614
540
  /** Encodes CRL entry extensions (reasonCode, invalidityDate). */
615
- function buildRevokedCertificateExtensions(entry) {
616
- const extensions = [];
617
- if (entry.reasonCode !== void 0) extensions.push(encodeExtension(OIDS.cRLReason, tlv(10, Uint8Array.of(REVOCATION_REASON_CODES[entry.reasonCode]))));
618
- if (entry.invalidityDate !== void 0) extensions.push(encodeExtension(OIDS.invalidityDate, generalizedTime(entry.invalidityDate)));
619
- return extensions;
541
+ function buildRevokedCertificateExtensions(e) {
542
+ 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;
620
544
  }
621
545
  /** Decodes per-entry CRL extensions (reasonCode, invalidityDate, certificateIssuer). */
622
- function parseRevokedCertificateExtensions(entryDer, element) {
623
- if (entryDer === void 0 || element === void 0) return {};
624
- let reasonCode;
625
- let invalidityDate;
626
- let certificateIssuer;
627
- const seenOids = /* @__PURE__ */ new Set();
628
- for (const extension of childrenOf(entryDer, element)) {
629
- const parts = childrenOf(entryDer, extension);
630
- if (parts.length < 2 || parts.length > 3) throw new Error("Malformed revoked certificate extension");
631
- if (parts.length === 3 && parts[1]?.tag !== 1) throw new Error("Malformed revoked certificate extension");
632
- const oid = decodeObjectIdentifier(requireElement(parts[0], "revoked certificate extension OID").value);
633
- if (seenOids.has(oid)) throw new Error(`Duplicate revoked certificate extension OID: ${oid}`);
634
- seenOids.add(oid);
635
- const valueElement = requireElement(parts[parts.length - 1], "revoked certificate extension value");
636
- if (valueElement.tag !== 4) throw new Error("Revoked certificate extension value must use OCTET STRING");
637
- if (oid === OIDS.cRLReason) reasonCode = revocationReasonFromCode(readElement(valueElement.value).value[0]);
638
- if (oid === OIDS.invalidityDate) invalidityDate = parseTime(readElement(valueElement.value));
639
- if (oid === OIDS.certificateIssuer) {
640
- const generalNames = readRootElement(valueElement.value, { maxDepth: 64 });
641
- if (generalNames.tag !== 48) throw new Error("certificateIssuer must use SEQUENCE");
642
- certificateIssuer = parseGeneralNames(valueElement.value, generalNames);
643
- }
644
- }
546
+ function parseRevokedCertificateExtensions(e, t) {
547
+ if (e === void 0 || t === void 0) return {};
548
+ let n = {}, r = /* @__PURE__ */ new Set();
549
+ for (let i of m(e, t)) parseRevokedCertificateExtension(e, i, r, n);
645
550
  return {
646
- ...reasonCode === void 0 ? {} : { reasonCode },
647
- ...invalidityDate === void 0 ? {} : { invalidityDate },
648
- ...certificateIssuer === void 0 ? {} : { certificateIssuer }
551
+ ...n.reasonCode === void 0 ? {} : { reasonCode: n.reasonCode },
552
+ ...n.invalidityDate === void 0 ? {} : { invalidityDate: n.invalidityDate },
553
+ ...n.certificateIssuer === void 0 ? {} : { certificateIssuer: n.certificateIssuer }
649
554
  };
650
555
  }
556
+ function parseRevokedCertificateExtension(e, t, n, r) {
557
+ let i = m(e, t);
558
+ 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);
560
+ if (n.has(a)) throw Error(`Duplicate revoked certificate extension OID: ${a}`);
561
+ 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);
570
+ }
571
+ if (e === w.invalidityDate && (n.invalidityDate = x(c(t))), e === w.certificateIssuer) {
572
+ let e = l(t, { maxDepth: 64 });
573
+ if (e.tag !== 48) throw Error("certificateIssuer must use SEQUENCE");
574
+ n.certificateIssuer = parseGeneralNames(t, e);
575
+ }
576
+ }
651
577
  /** Decodes the IssuingDistributionPoint extension from its OCTET STRING content. */
652
- function parseIssuingDistributionPoint(valueDer) {
653
- const sequenceElement = readRootElement(valueDer, { maxDepth: 64 });
654
- let distributionPoint;
655
- let onlyContainsUserCerts;
656
- let onlyContainsCACerts;
657
- let onlySomeReasons;
658
- let indirectCrl;
659
- let onlyContainsAttributeCerts;
660
- for (const child of childrenOf(valueDer, sequenceElement)) if (child.tag === 160) {
661
- if (distributionPoint !== void 0) throw new Error("IssuingDistributionPoint distributionPoint must not repeat");
662
- const parsedDistributionPoint = parseDistributionPointName(valueDer, child);
663
- if (parsedDistributionPoint !== void 0) distributionPoint = parsedDistributionPoint;
664
- } else if (child.tag === 129) {
665
- if (onlyContainsUserCerts !== void 0) throw new Error("IssuingDistributionPoint onlyContainsUserCerts must not repeat");
666
- onlyContainsUserCerts = parseImplicitBoolean(child);
667
- } else if (child.tag === 130) {
668
- if (onlyContainsCACerts !== void 0) throw new Error("IssuingDistributionPoint onlyContainsCACerts must not repeat");
669
- onlyContainsCACerts = parseImplicitBoolean(child);
670
- } else if (child.tag === 131) {
671
- if (onlySomeReasons !== void 0) throw new Error("IssuingDistributionPoint onlySomeReasons must not repeat");
672
- onlySomeReasons = parseDistributionPointReasonFlagsContent(child.value);
673
- } else if (child.tag === 132) {
674
- if (indirectCrl !== void 0) throw new Error("IssuingDistributionPoint indirectCrl must not repeat");
675
- indirectCrl = parseImplicitBoolean(child);
676
- } else if (child.tag === 133) {
677
- if (onlyContainsAttributeCerts !== void 0) throw new Error("IssuingDistributionPoint onlyContainsAttributeCerts must not repeat");
678
- onlyContainsAttributeCerts = parseImplicitBoolean(child);
679
- } else throw new Error(`Unsupported IssuingDistributionPoint field tag: ${String(child.tag)}`);
578
+ function parseIssuingDistributionPoint(e) {
579
+ let t = l(e, { maxDepth: 64 }), n = {};
580
+ for (let r of m(e, t)) parseIssuingDistributionPointField(e, r, n);
680
581
  if ([
681
- onlyContainsUserCerts,
682
- onlyContainsCACerts,
683
- onlyContainsAttributeCerts
684
- ].filter((value) => value === true).length > 1) throw new Error("IssuingDistributionPoint scope booleans are mutually exclusive");
582
+ n.onlyContainsUserCerts,
583
+ n.onlyContainsCACerts,
584
+ n.onlyContainsAttributeCerts
585
+ ].filter((e) => e === !0).length > 1) throw Error("IssuingDistributionPoint scope booleans are mutually exclusive");
685
586
  return {
686
- ...distributionPoint === void 0 ? {} : { distributionPoint },
687
- ...onlyContainsUserCerts === void 0 ? {} : { onlyContainsUserCerts },
688
- ...onlyContainsCACerts === void 0 ? {} : { onlyContainsCACerts },
689
- ...onlySomeReasons === void 0 ? {} : { onlySomeReasons },
690
- ...indirectCrl === void 0 ? {} : { indirectCrl },
691
- ...onlyContainsAttributeCerts === void 0 ? {} : { onlyContainsAttributeCerts }
587
+ ...n.distributionPoint === void 0 ? {} : { distributionPoint: n.distributionPoint },
588
+ ...n.onlyContainsUserCerts === void 0 ? {} : { onlyContainsUserCerts: n.onlyContainsUserCerts },
589
+ ...n.onlyContainsCACerts === void 0 ? {} : { onlyContainsCACerts: n.onlyContainsCACerts },
590
+ ...n.onlySomeReasons === void 0 ? {} : { onlySomeReasons: n.onlySomeReasons },
591
+ ...n.indirectCrl === void 0 ? {} : { indirectCrl: n.indirectCrl },
592
+ ...n.onlyContainsAttributeCerts === void 0 ? {} : { onlyContainsAttributeCerts: n.onlyContainsAttributeCerts }
692
593
  };
693
594
  }
595
+ function parseIssuingDistributionPointField(e, t, n) {
596
+ switch (t.tag) {
597
+ case 160: {
598
+ if (n.distributionPoint !== void 0) throw Error("IssuingDistributionPoint distributionPoint must not repeat");
599
+ let r = parseDistributionPointName(e, t);
600
+ r !== void 0 && (n.distributionPoint = r);
601
+ return;
602
+ }
603
+ case 129:
604
+ n.onlyContainsUserCerts = parseUniqueIssuingDistributionPointBoolean(n.onlyContainsUserCerts, t, "onlyContainsUserCerts");
605
+ return;
606
+ case 130:
607
+ n.onlyContainsCACerts = parseUniqueIssuingDistributionPointBoolean(n.onlyContainsCACerts, t, "onlyContainsCACerts");
608
+ return;
609
+ case 131:
610
+ if (n.onlySomeReasons !== void 0) throw Error("IssuingDistributionPoint onlySomeReasons must not repeat");
611
+ n.onlySomeReasons = F(t.value);
612
+ return;
613
+ case 132:
614
+ n.indirectCrl = parseUniqueIssuingDistributionPointBoolean(n.indirectCrl, t, "indirectCrl");
615
+ return;
616
+ case 133:
617
+ n.onlyContainsAttributeCerts = parseUniqueIssuingDistributionPointBoolean(n.onlyContainsAttributeCerts, t, "onlyContainsAttributeCerts");
618
+ return;
619
+ default: throw Error(`Unsupported IssuingDistributionPoint field tag: ${String(t.tag)}`);
620
+ }
621
+ }
622
+ function parseUniqueIssuingDistributionPointBoolean(e, t, n) {
623
+ if (e !== void 0) throw Error(`IssuingDistributionPoint ${n} must not repeat`);
624
+ return parseImplicitBoolean(t);
625
+ }
694
626
  /** Decodes a SEQUENCE OF DistributionPoint from DER. */
695
- function parseDistributionPoints(valueDer) {
696
- const sequenceElement = readRootElement(valueDer, { maxDepth: 64 });
697
- if (sequenceElement.tag !== 48) throw new Error("DistributionPoints must use SEQUENCE");
698
- const elements = childrenOf(valueDer, sequenceElement);
699
- if (elements.length === 0) throw new Error("DistributionPoints must not be empty");
700
- return elements.map((distributionPoint) => parseDistributionPoint(valueDer, distributionPoint));
627
+ function parseDistributionPoints(e) {
628
+ let t = l(e, { maxDepth: 64 });
629
+ if (t.tag !== 48) throw Error("DistributionPoints must use SEQUENCE");
630
+ let n = m(e, t);
631
+ if (n.length === 0) throw Error("DistributionPoints must not be empty");
632
+ return n.map((t) => parseDistributionPoint(e, t));
701
633
  }
702
634
  /** Decodes a DistributionPointName (fullName or relativeName). */
703
- function parseDistributionPointName(valueDer, element) {
704
- const children = childrenOf(valueDer, element);
705
- if (children.length !== 1) throw new Error("distributionPointName must contain exactly one choice");
706
- const distributionPointName = requireElement(children[0], "distributionPointName");
707
- if (distributionPointName.tag === 160) {
708
- const fullName = childrenOf(valueDer, distributionPointName);
709
- if (fullName.length === 0) throw new Error("distributionPointName fullName must not be empty");
710
- for (const name of fullName) if ((name.tag & 192) !== 128) throw new Error("distributionPointName fullName must contain GeneralName entries");
711
- return { fullName: fullName.map((name) => parseGeneralName(name)) };
635
+ function parseDistributionPointName(e, t) {
636
+ let n = m(e, t);
637
+ if (n.length !== 1) throw Error("distributionPointName must contain exactly one choice");
638
+ let r = S(n[0], "distributionPointName");
639
+ if (r.tag === 160) {
640
+ let t = m(e, r);
641
+ if (t.length === 0) throw Error("distributionPointName fullName must not be empty");
642
+ 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)) };
712
644
  }
713
- if (distributionPointName.tag === 161) return { relativeName: parseRelativeName(valueDer, distributionPointName) };
714
- throw new Error(`Unsupported distributionPointName tag: ${String(distributionPointName.tag)}`);
645
+ if (r.tag === 161) return { relativeName: parseRelativeName(e, r) };
646
+ throw Error(`Unsupported distributionPointName tag: ${String(r.tag)}`);
715
647
  }
716
648
  /** Decodes a single DistributionPoint SEQUENCE. */
717
- function parseDistributionPoint(valueDer, element) {
718
- if (element.tag !== 48) throw new Error("DistributionPoint must use SEQUENCE");
719
- let distributionPoint;
720
- let reasons;
721
- let crlIssuer;
722
- for (const child of childrenOf(valueDer, element)) if (child.tag === 160) {
723
- if (distributionPoint !== void 0) throw new Error("DistributionPoint distributionPoint must not repeat");
724
- const parsedDistributionPoint = parseDistributionPointName(valueDer, child);
725
- if (parsedDistributionPoint !== void 0) distributionPoint = parsedDistributionPoint;
726
- } else if (child.tag === 129) {
727
- if (reasons !== void 0) throw new Error("DistributionPoint reasons must not repeat");
728
- reasons = parseDistributionPointReasonFlagsContent(child.value);
729
- } else if (child.tag === 162) {
730
- if (crlIssuer !== void 0) throw new Error("DistributionPoint crlIssuer must not repeat");
731
- crlIssuer = parseGeneralNames(valueDer, child);
732
- } else throw new Error(`Unsupported DistributionPoint field tag: ${String(child.tag)}`);
733
- if (distributionPoint === void 0 && crlIssuer === void 0) throw new Error("DistributionPoint must include distributionPoint or crlIssuer");
649
+ function parseDistributionPoint(e, t) {
650
+ if (t.tag !== 48) throw Error("DistributionPoint must use SEQUENCE");
651
+ let n = {};
652
+ for (let r of m(e, t)) parseDistributionPointField(e, r, n);
653
+ if (n.distributionPoint === void 0 && n.crlIssuer === void 0) throw Error("DistributionPoint must include distributionPoint or crlIssuer");
734
654
  return {
735
- ...distributionPoint === void 0 ? {} : { distributionPoint },
736
- ...reasons === void 0 ? {} : { reasons },
737
- ...crlIssuer === void 0 ? {} : { crlIssuer }
655
+ ...n.distributionPoint === void 0 ? {} : { distributionPoint: n.distributionPoint },
656
+ ...n.reasons === void 0 ? {} : { reasons: n.reasons },
657
+ ...n.crlIssuer === void 0 ? {} : { crlIssuer: n.crlIssuer }
738
658
  };
739
659
  }
660
+ function parseDistributionPointField(e, t, n) {
661
+ switch (t.tag) {
662
+ case 160: {
663
+ if (n.distributionPoint !== void 0) throw Error("DistributionPoint distributionPoint must not repeat");
664
+ let r = parseDistributionPointName(e, t);
665
+ r !== void 0 && (n.distributionPoint = r);
666
+ return;
667
+ }
668
+ case 129:
669
+ if (n.reasons !== void 0) throw Error("DistributionPoint reasons must not repeat");
670
+ n.reasons = F(t.value);
671
+ return;
672
+ case 162:
673
+ if (n.crlIssuer !== void 0) throw Error("DistributionPoint crlIssuer must not repeat");
674
+ n.crlIssuer = parseGeneralNames(e, t);
675
+ return;
676
+ default: throw Error(`Unsupported DistributionPoint field tag: ${String(t.tag)}`);
677
+ }
678
+ }
740
679
  /** Decodes a GeneralName from its context-tagged ASN.1 element. */
741
- function parseGeneralName(element) {
742
- switch (element.tag) {
680
+ function parseGeneralName(e) {
681
+ switch (e.tag) {
743
682
  case 129: return {
744
683
  type: "email",
745
- value: textDecoder.decode(element.value)
684
+ value: Q.decode(e.value)
746
685
  };
747
686
  case 130: return {
748
687
  type: "dns",
749
- value: textDecoder.decode(element.value)
688
+ value: Q.decode(e.value)
750
689
  };
751
690
  case 134: return {
752
691
  type: "uri",
753
- value: textDecoder.decode(element.value)
692
+ value: Q.decode(e.value)
754
693
  };
755
694
  case 135: return {
756
695
  type: "ip",
757
- value: decodeIpAddress(element.value)
696
+ value: N(e.value)
758
697
  };
759
698
  case 164: return {
760
699
  type: "directoryName",
761
- derHex: toHex(rebuildDirectoryNameFromImplicit(element))
700
+ derHex: C(rebuildDirectoryNameFromImplicit(e))
762
701
  };
763
702
  default: return {
764
703
  type: "unknown",
765
- tag: element.tag,
766
- value: new Uint8Array(element.value)
704
+ tag: e.tag,
705
+ value: new Uint8Array(e.value)
767
706
  };
768
707
  }
769
708
  }
770
- function parseGeneralNames(valueDer, element) {
771
- const names = childrenOf(valueDer, element);
772
- if (names.length === 0) throw new Error("GeneralNames must not be empty");
773
- for (const name of names) if ((name.tag & 192) !== 128) throw new Error("GeneralNames must contain GeneralName entries");
774
- return names.map((name) => parseGeneralName(name));
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));
775
714
  }
776
715
  /** Decodes a RelativeDistinguishedName SET from an implicitly-tagged context element. */
777
- function parseRelativeName(valueDer, element) {
778
- const attributes = [];
779
- const values = {};
780
- for (const attributeSequence of childrenOf(valueDer, element)) {
781
- const parts = childrenOf(valueDer, attributeSequence);
782
- const oid = decodeObjectIdentifier(requireElement(parts[0], "name OID").value);
783
- const valueElement = requireElement(parts[1], "name value");
784
- const fieldKey = nameFieldKeyFromOid(oid);
785
- const fieldValue = decodeNameValue(valueElement);
786
- const attribute = fieldKey === void 0 ? {
787
- oid,
788
- valueTag: valueElement.tag,
789
- value: fieldValue
716
+ function parseRelativeName(e, t) {
717
+ 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 ? {
720
+ oid: a,
721
+ valueTag: o.tag,
722
+ value: c
790
723
  } : {
791
- oid,
792
- key: fieldKey,
793
- valueTag: valueElement.tag,
794
- value: fieldValue
724
+ oid: a,
725
+ key: s,
726
+ valueTag: o.tag,
727
+ value: c
795
728
  };
796
- attributes.push(attribute);
797
- if (fieldKey !== void 0 && values[fieldKey] === void 0) values[fieldKey] = fieldValue;
729
+ n.push(l), s !== void 0 && r[s] === void 0 && (r[s] = c);
798
730
  }
799
731
  return {
800
- derHex: toHex(valueDer.slice(element.start - element.headerLength, element.end)),
801
- attributes,
802
- values
732
+ derHex: C(e.slice(t.start - t.headerLength, t.end)),
733
+ attributes: n,
734
+ values: r
803
735
  };
804
736
  }
805
737
  /** Decodes an ASN.1 string element (UTF8String, PrintableString, etc.) to a JS string. */
806
- function decodeNameValue(element) {
807
- return decodeString(element.tag, element.value);
738
+ function decodeNameValue(e) {
739
+ return v(e.tag, e.value);
808
740
  }
809
741
  /** Reads an implicitly-tagged BOOLEAN from a context element. Absent content → `false`. */
810
- function parseImplicitBoolean(element) {
811
- return (element.value[0] ?? 0) !== 0;
742
+ function parseImplicitBoolean(e) {
743
+ return (e.value[0] ?? 0) !== 0;
812
744
  }
813
745
  /** DER-encodes an IssuingDistributionPoint extension value. Throws on mutually-exclusive scope flags. */
814
- function encodeIssuingDistributionPoint(value) {
746
+ function encodeIssuingDistributionPoint(e) {
815
747
  if ([
816
- value.onlyContainsUserCerts === true,
817
- value.onlyContainsCACerts === true,
818
- value.onlyContainsAttributeCerts === true
819
- ].filter(Boolean).length > 1) throw new Error("IssuingDistributionPoint can assert at most one of user, CA, or attribute cert scope");
820
- const fields = [];
821
- if (value.distributionPoint !== void 0) fields.push(implicitConstructedContext(0, encodeDistributionPointName(value.distributionPoint)));
822
- if (value.onlyContainsUserCerts) fields.push(implicitPrimitiveContext(1, Uint8Array.of(255)));
823
- if (value.onlyContainsCACerts) fields.push(implicitPrimitiveContext(2, Uint8Array.of(255)));
824
- if (value.onlySomeReasons !== void 0 && value.onlySomeReasons.length > 0) fields.push(implicitPrimitiveContext(3, encodeDistributionPointReasonFlagsContent(value.onlySomeReasons)));
825
- if (value.indirectCrl) fields.push(implicitPrimitiveContext(4, Uint8Array.of(255)));
826
- if (value.onlyContainsAttributeCerts) fields.push(implicitPrimitiveContext(5, Uint8Array.of(255)));
827
- return sequence(fields);
748
+ e.onlyContainsUserCerts === !0,
749
+ e.onlyContainsCACerts === !0,
750
+ e.onlyContainsAttributeCerts === !0
751
+ ].filter(Boolean).length > 1) throw Error("IssuingDistributionPoint can assert at most one of user, CA, or attribute cert scope");
752
+ 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);
828
754
  }
829
755
  /** DER-encodes a DistributionPointName (fullName or relativeName). */
830
- function encodeDistributionPointName(value) {
831
- if (value === void 0) throw new Error("IssuingDistributionPoint distributionPoint is required");
832
- if (value.fullName !== void 0 && value.relativeName !== void 0) throw new Error("DistributionPointName cannot contain both fullName and relativeName");
833
- if (value.fullName !== void 0) {
834
- if (value.fullName.length === 0) throw new Error("DistributionPointName fullName must not be empty");
835
- return implicitConstructedContext(0, concatGeneralNames(value.fullName));
756
+ function encodeDistributionPointName(e) {
757
+ 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));
836
762
  }
837
- if (value.relativeName !== void 0) {
838
- const relativeName = encodeRelativeDistinguishedName(value.relativeName);
839
- const relativeNameElement = readElement(relativeName);
840
- return implicitConstructedContext(1, relativeName.slice(relativeNameElement.start, relativeNameElement.end));
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));
841
766
  }
842
- throw new Error("DistributionPointName must contain fullName or relativeName");
767
+ throw Error("DistributionPointName must contain fullName or relativeName");
843
768
  }
844
769
  /** DER-encodes and concatenates a list of GeneralName values. */
845
- function concatGeneralNames(names) {
846
- return concatBytes(names.map((name) => encodeSubjectAltName(name)));
770
+ function concatGeneralNames(e) {
771
+ return t(e.map((e) => H(e)));
847
772
  }
848
773
  /** Re-wraps an implicitly-tagged directoryName as an explicit SEQUENCE (tag 0x30). */
849
774
  /**
@@ -853,147 +778,130 @@ function concatGeneralNames(names) {
853
778
  * - Proper implicit: [4] replaces SEQUENCE tag, content is RDN SETs directly → wrap with 0x30
854
779
  * - Explicit-like: [4] wraps entire SEQUENCE, content starts with 0x30 → return content as-is
855
780
  */
856
- function rebuildDirectoryNameFromImplicit(element) {
857
- if (element.value.length > 0 && element.value[0] === 48) return new Uint8Array(element.value);
858
- return tlv(48, element.value);
781
+ function rebuildDirectoryNameFromImplicit(e) {
782
+ return e.value.length > 0 && e.value[0] === 48 ? new Uint8Array(e.value) : p(48, e.value);
859
783
  }
860
784
  /** Parses a Name SEQUENCE element into a full {@linkcode ParsedName}. */
861
- function parseIssuer(source, element) {
862
- const derHex = toHex(source.slice(element.start - element.headerLength, element.end));
863
- const rdns = [];
864
- const allAttributes = [];
865
- const values = {};
866
- for (const setElement of childrenOf(source, element)) {
867
- const rdnAttributes = [];
868
- const rdnValues = {};
869
- for (const attrSequence of childrenOf(source, setElement)) {
870
- const parts = childrenOf(source, attrSequence);
871
- const oidElement = requireElement(parts[0], "issuer attribute OID");
872
- const valueElement = requireElement(parts[1], "issuer attribute value");
873
- const oid = decodeObjectIdentifier(oidElement.value);
874
- let fieldValue;
785
+ 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)) {
788
+ 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;
875
791
  try {
876
- fieldValue = decodeString(valueElement.tag, valueElement.value);
792
+ u = v(c.tag, c.value);
877
793
  } catch {
878
- fieldValue = textDecoder.decode(valueElement.value);
794
+ u = Q.decode(c.value);
879
795
  }
880
- const fieldKey = nameFieldKeyFromOid(oid);
881
- const attribute = fieldKey !== void 0 ? {
882
- oid,
883
- key: fieldKey,
884
- valueTag: valueElement.tag,
885
- value: fieldValue
796
+ let d = I(l), f = d === void 0 ? {
797
+ oid: l,
798
+ valueTag: c.tag,
799
+ value: u
886
800
  } : {
887
- oid,
888
- valueTag: valueElement.tag,
889
- value: fieldValue
801
+ oid: l,
802
+ key: d,
803
+ valueTag: c.tag,
804
+ value: u
890
805
  };
891
- rdnAttributes.push(attribute);
892
- allAttributes.push(attribute);
893
- if (fieldKey !== void 0) {
894
- if (rdnValues[fieldKey] === void 0) rdnValues[fieldKey] = fieldValue;
895
- if (values[fieldKey] === void 0) values[fieldKey] = fieldValue;
896
- }
806
+ t.push(f), i.push(f), d !== void 0 && (o[d] === void 0 && (o[d] = u), a[d] === void 0 && (a[d] = u));
897
807
  }
898
- rdns.push({
899
- derHex: toHex(source.slice(setElement.start - setElement.headerLength, setElement.end)),
900
- attributes: rdnAttributes,
901
- values: rdnValues
808
+ r.push({
809
+ derHex: C(e.slice(n.start - n.headerLength, n.end)),
810
+ attributes: t,
811
+ values: o
902
812
  });
903
813
  }
904
814
  return {
905
- derHex,
906
- rdns,
907
- attributes: allAttributes,
908
- values
815
+ derHex: n,
816
+ rdns: r,
817
+ attributes: i,
818
+ values: a
909
819
  };
910
820
  }
911
821
  /** Re-parses a hex-encoded DER Name into a {@linkcode ParsedName}. Returns `undefined` on malformed input. */
912
- function parseDerHexName(hex) {
822
+ function parseDerHexName(e) {
913
823
  try {
914
- const bytes = hexToBytes(hex);
915
- const element = unwrapNameElement(bytes, readRootElement(bytes, { maxDepth: 64 }));
916
- if (element.tag !== 48) return;
917
- return parseIssuer(bytes, element);
824
+ let t = b(e), n = unwrapNameElement(t, l(t, { maxDepth: 64 }));
825
+ return n.tag === 48 ? parseIssuer(t, n) : void 0;
918
826
  } catch {
919
827
  return;
920
828
  }
921
829
  }
922
- function unwrapNameElement(source, element) {
923
- if (element.tag !== 48) return element;
924
- const children = childrenOf(source, element);
925
- const child = children[0];
926
- if (children.length === 1 && child?.tag === 48) return child;
927
- return element;
830
+ function unwrapNameElement(e, t) {
831
+ if (t.tag !== 48) return t;
832
+ let n = m(e, t), r = n[0];
833
+ return n.length === 1 && r?.tag === 48 ? r : t;
928
834
  }
929
835
  /** Semantic comparison of a GeneralName directoryName `derHex` against a {@linkcode ParsedName}. */
930
- function directoryNameDerHexMatchesParsedName(derHex, name) {
931
- const parsed = parseDerHexName(derHex);
932
- if (parsed === void 0) return false;
933
- return compareDistinguishedNames(parsed, name);
836
+ function directoryNameDerHexMatchesParsedName(e, t) {
837
+ let n = parseDerHexName(e);
838
+ return n !== void 0 && Y(n, t);
934
839
  }
935
840
  /** Extracts the keyIdentifier field from an AuthorityKeyIdentifier extension value. */
936
- function parseAuthorityKeyIdentifier(bytes) {
937
- const sequenceElement = readRootElement(bytes, {
841
+ function parseAuthorityKeyIdentifier(e) {
842
+ let t = l(e, {
938
843
  maxDepth: 64,
939
844
  allowOpaqueConstructedTags: [161, 162]
940
845
  });
941
- if (sequenceElement.tag !== 48) throw new Error("authorityKeyIdentifier must use SEQUENCE");
942
- let keyIdentifier;
943
- let sawAuthorityCertIssuer = false;
944
- let sawAuthorityCertSerialNumber = false;
945
- let lastFieldOrder = -1;
946
- for (const child of childrenOf(bytes, sequenceElement)) {
947
- if (child.tag === 128) {
948
- if (keyIdentifier !== void 0) throw new Error("authorityKeyIdentifier keyIdentifier must not repeat");
949
- if (lastFieldOrder >= 0) throw new Error("authorityKeyIdentifier fields must preserve DER order");
950
- keyIdentifier = toHex(child.value);
951
- lastFieldOrder = 0;
952
- continue;
953
- }
954
- if (child.tag === 161) {
955
- if (sawAuthorityCertIssuer) throw new Error("authorityKeyIdentifier authorityCertIssuer must not repeat");
956
- if (lastFieldOrder >= 1) throw new Error("authorityKeyIdentifier fields must preserve DER order");
957
- parseGeneralNames(bytes, child);
958
- sawAuthorityCertIssuer = true;
959
- lastFieldOrder = 1;
960
- continue;
961
- }
962
- if (child.tag === 130) {
963
- if (sawAuthorityCertSerialNumber) throw new Error("authorityKeyIdentifier authorityCertSerialNumber must not repeat");
964
- if (lastFieldOrder >= 2 || !sawAuthorityCertIssuer) throw new Error("authorityKeyIdentifier fields must preserve DER order");
965
- validateImplicitSerialNumberEncoding(child.value, "authorityKeyIdentifier authorityCertSerialNumber");
966
- sawAuthorityCertSerialNumber = true;
967
- lastFieldOrder = 2;
968
- continue;
969
- }
970
- throw new Error(`Unsupported authorityKeyIdentifier field tag: ${String(child.tag)}`);
846
+ if (t.tag !== 48) throw Error("authorityKeyIdentifier must use SEQUENCE");
847
+ let n = {
848
+ sawAuthorityCertIssuer: !1,
849
+ sawAuthorityCertSerialNumber: !1,
850
+ lastFieldOrder: -1
851
+ };
852
+ for (let r of m(e, t)) parseAuthorityKeyIdentifierField(e, r, n);
853
+ return n.keyIdentifier;
854
+ }
855
+ function parseAuthorityKeyIdentifierField(e, t, n) {
856
+ switch (t.tag) {
857
+ case 128:
858
+ parseAuthorityKeyIdentifierKeyId(t, n);
859
+ return;
860
+ case 161:
861
+ parseAuthorityKeyIdentifierIssuer(e, t, n);
862
+ return;
863
+ case 130:
864
+ parseAuthorityKeyIdentifierSerial(t, n);
865
+ return;
866
+ default: throw Error(`Unsupported authorityKeyIdentifier field tag: ${String(t.tag)}`);
971
867
  }
972
- return keyIdentifier;
973
868
  }
974
- function validateImplicitSerialNumberEncoding(bytes, label) {
975
- const first = bytes[0];
976
- if (first === void 0) throw new Error(`${label} must not be empty`);
977
- if ((first & 128) !== 0) throw new Error(`${label} must be non-negative`);
978
- if (bytes.length > 1 && first === 0 && ((bytes[1] ?? 0) & 128) === 0) throw new Error(`${label} must use minimal encoding`);
869
+ function parseAuthorityKeyIdentifierKeyId(e, t) {
870
+ if (t.keyIdentifier !== void 0) throw Error("authorityKeyIdentifier keyIdentifier must not repeat");
871
+ if (t.lastFieldOrder >= 0) throw Error("authorityKeyIdentifier fields must preserve DER order");
872
+ t.keyIdentifier = C(e.value), t.lastFieldOrder = 0;
873
+ }
874
+ function parseAuthorityKeyIdentifierIssuer(e, t, n) {
875
+ if (n.sawAuthorityCertIssuer) throw Error("authorityKeyIdentifier authorityCertIssuer must not repeat");
876
+ if (n.lastFieldOrder >= 1) throw Error("authorityKeyIdentifier fields must preserve DER order");
877
+ parseGeneralNames(e, t), n.sawAuthorityCertIssuer = !0, n.lastFieldOrder = 1;
878
+ }
879
+ function parseAuthorityKeyIdentifierSerial(e, t) {
880
+ if (t.sawAuthorityCertSerialNumber) throw Error("authorityKeyIdentifier authorityCertSerialNumber must not repeat");
881
+ if (t.lastFieldOrder >= 2 || !t.sawAuthorityCertIssuer) throw Error("authorityKeyIdentifier fields must preserve DER order");
882
+ validateImplicitSerialNumberEncoding(e.value, "authorityKeyIdentifier authorityCertSerialNumber"), t.sawAuthorityCertSerialNumber = !0, t.lastFieldOrder = 2;
883
+ }
884
+ function validateImplicitSerialNumberEncoding(e, t) {
885
+ let n = e[0];
886
+ if (n === void 0) throw Error(`${t} must not be empty`);
887
+ if (n & 128) throw Error(`${t} must be non-negative`);
888
+ if (e.length > 1 && n === 0 && !((e[1] ?? 0) & 128)) throw Error(`${t} must use minimal encoding`);
979
889
  }
980
890
  /** Extracts the algorithm OID from an AlgorithmIdentifier SEQUENCE. */
981
- function parseAlgorithmIdentifier(source, element) {
982
- const children = childrenOf(source, element);
983
- const oid = requireElement(children[0], "algorithm OID");
984
- const parameters = children[1];
985
- return parameters === void 0 ? { oid: decodeObjectIdentifier(oid.value) } : {
986
- oid: decodeObjectIdentifier(oid.value),
987
- parametersDer: source.slice(parameters.start - parameters.headerLength, parameters.end)
891
+ 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),
895
+ parametersDer: e.slice(i.start - i.headerLength, i.end)
988
896
  };
989
897
  }
990
898
  /** Lowercases a hex string for bytewise serial-number comparison. */
991
- function normalizeHex(value) {
992
- return value.toLowerCase();
899
+ function normalizeHex(e) {
900
+ return e.toLowerCase();
993
901
  }
994
902
  /** Maps an integer CRLReason code back to its {@linkcode RevocationReason} string, or `undefined` for unknown codes. */
995
- function revocationReasonFromCode(code) {
996
- switch (code) {
903
+ function revocationReasonFromCode(e) {
904
+ switch (e) {
997
905
  case 0: return "unspecified";
998
906
  case 1: return "keyCompromise";
999
907
  case 2: return "cACompromise";
@@ -1007,113 +915,113 @@ function revocationReasonFromCode(code) {
1007
915
  }
1008
916
  }
1009
917
  /** Thin wrapper — parses a DER-encoded certificate for use as a CRL issuer. */
1010
- function parseIssuerCertificateDer(der) {
1011
- return parseCertificateFromSource(der);
918
+ function parseIssuerCertificateDer(e) {
919
+ return W(e);
1012
920
  }
1013
921
  /** Thin wrapper — parses a PEM-encoded certificate for use as a CRL issuer. */
1014
- function parseIssuerCertificatePem(pem) {
1015
- return parseCertificateFromSource(pem);
922
+ function parseIssuerCertificatePem(e) {
923
+ return W(e);
1016
924
  }
1017
925
  /** Accepts PEM, DER, or already-parsed CRL and returns a parsed CRL. */
1018
- function normalizeCrl(source) {
1019
- if (typeof source === "string") return parseCertificateRevocationListPemOrThrow(source);
1020
- if (source instanceof Uint8Array) return parseCertificateRevocationListDerOrThrow(new Uint8Array(source));
1021
- if (hasReparseableCrlShape(source)) return parseCertificateRevocationListDerOrThrow(new Uint8Array(source.der));
1022
- throw new Error("certificate revocation list input is malformed");
1023
- }
1024
- function parseSignedCrlFields(tbsCertListDer) {
1025
- const tbsChildren = childrenOf(tbsCertListDer, readRootElement(tbsCertListDer, { maxDepth: 64 }));
1026
- let index = 0;
1027
- let version = 1;
1028
- const firstChild = tbsChildren[index];
1029
- if (firstChild !== void 0 && firstChild.tag !== 2 && firstChild.tag !== 48) throw new Error("version must use INTEGER");
1030
- if (firstChild?.tag === 2) {
1031
- const versionElement = requireElement(tbsChildren[index], "version");
1032
- if (versionElement.tag !== 2) throw new Error("version must use INTEGER");
1033
- version = decodeIntegerNumber(versionElement.value) + 1;
1034
- if (version !== 2) throw new Error(`Unsupported CRL version: ${String(version)}`);
1035
- index += 1;
1036
- }
1037
- index += 1;
1038
- const issuerElement = requireElement(tbsChildren[index], "issuer");
1039
- const thisUpdateElement = requireElement(tbsChildren[index + 1], "thisUpdate");
1040
- let cursor = index + 2;
1041
- const maybeNextUpdate = tbsChildren[cursor];
1042
- const nextUpdate = maybeNextUpdate !== void 0 && (maybeNextUpdate.tag === 23 || maybeNextUpdate.tag === 24) ? parseTime(maybeNextUpdate) : void 0;
1043
- if (nextUpdate !== void 0) cursor += 1;
1044
- let revokedCertificates = [];
1045
- const maybeRevoked = tbsChildren[cursor];
1046
- if (maybeRevoked?.tag === 48) {
1047
- revokedCertificates = childrenOf(tbsCertListDer, maybeRevoked).map((entry) => {
1048
- const entryDer = tbsCertListDer.slice(entry.start - entry.headerLength, entry.end);
1049
- const parts = readSequenceChildren(entryDer);
1050
- const serialNumber = requireElement(parts[0], "revoked serialNumber");
1051
- if (serialNumber.tag !== 2) throw new Error("revoked serialNumber must use INTEGER");
1052
- const entryExtensions = parts[2];
1053
- if (entryExtensions !== void 0 && version !== 2) throw new Error("revoked certificate extensions require CRL version 2");
1054
- const parsedEntryExtensions = parseRevokedCertificateExtensions(entryDer, entryExtensions);
1055
- return {
1056
- serialNumberHex: toHex(serialNumber.value),
1057
- revocationDate: parseTime(requireElement(parts[1], "revocationDate")),
1058
- ...parsedEntryExtensions.reasonCode === void 0 ? {} : { reasonCode: parsedEntryExtensions.reasonCode },
1059
- ...parsedEntryExtensions.invalidityDate === void 0 ? {} : { invalidityDate: parsedEntryExtensions.invalidityDate },
1060
- ...parsedEntryExtensions.certificateIssuer === void 0 ? {} : { certificateIssuer: parsedEntryExtensions.certificateIssuer }
1061
- };
1062
- });
1063
- cursor += 1;
1064
- }
1065
- let authorityKeyIdentifier;
1066
- let crlNumber;
1067
- let baseCrlNumber;
1068
- let issuingDistributionPoint;
1069
- let freshestCrlDistributionPoints;
1070
- const maybeExtensions = tbsChildren[cursor];
1071
- if (maybeExtensions?.tag === 160) {
1072
- if (version !== 2) throw new Error("CRL extensions require version 2");
1073
- const seenOids = /* @__PURE__ */ new Set();
1074
- const extensionSequence = requireElement(childrenOf(tbsCertListDer, maybeExtensions)[0], "crl extensions");
1075
- for (const extension of childrenOf(tbsCertListDer, extensionSequence)) {
1076
- const parts = childrenOf(tbsCertListDer, extension);
1077
- if (parts.length < 2 || parts.length > 3) throw new Error("Malformed CRL extension");
1078
- if (parts.length === 3 && parts[1]?.tag !== 1) throw new Error("Malformed CRL extension");
1079
- const oid = decodeObjectIdentifier(requireElement(parts[0], "extension OID").value);
1080
- if (seenOids.has(oid)) throw new Error(`Duplicate CRL extension OID: ${oid}`);
1081
- seenOids.add(oid);
1082
- const critical = parts.length === 3 ? decodeBoolean(requireElement(parts[1], "extension critical").value) : false;
1083
- const valueElement = requireElement(parts[parts.length - 1], "extension value");
1084
- if (valueElement.tag !== 4) throw new Error("CRL extension value must use OCTET STRING");
1085
- if (oid !== OIDS.authorityKeyIdentifier && oid !== OIDS.cRLNumber && oid !== OIDS.deltaCRLIndicator && oid !== OIDS.issuingDistributionPoint && oid !== OIDS.freshestCRL && critical) throw new Error(`Unsupported critical CRL extension OID: ${oid}`);
1086
- if (oid === OIDS.authorityKeyIdentifier) authorityKeyIdentifier = parseAuthorityKeyIdentifier(valueElement.value);
1087
- if (oid === OIDS.cRLNumber) crlNumber = decodeIntegerNumber(readElement(valueElement.value).value);
1088
- if (oid === OIDS.deltaCRLIndicator) baseCrlNumber = decodeIntegerNumber(readElement(valueElement.value).value);
1089
- if (oid === OIDS.issuingDistributionPoint) issuingDistributionPoint = parseIssuingDistributionPoint(valueElement.value);
1090
- if (oid === OIDS.freshestCRL) freshestCrlDistributionPoints = parseDistributionPoints(valueElement.value);
1091
- }
1092
- }
926
+ function normalizeCrl(e) {
927
+ if (typeof e == "string") return parseCertificateRevocationListPemOrThrow(e);
928
+ if (e instanceof Uint8Array) return parseCertificateRevocationListDerOrThrow(new Uint8Array(e));
929
+ if (hasReparseableCrlShape(e)) return parseCertificateRevocationListDerOrThrow(new Uint8Array(e.der));
930
+ throw Error("certificate revocation list input is malformed");
931
+ }
932
+ 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);
940
+ return {
941
+ version: r,
942
+ issuer: parseIssuer(e, a),
943
+ thisUpdate: x(o),
944
+ ...u === void 0 ? {} : { nextUpdate: u },
945
+ ...h.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: h.authorityKeyIdentifier },
946
+ ...h.crlNumber === void 0 ? {} : { crlNumber: h.crlNumber },
947
+ ...h.baseCrlNumber === void 0 ? {} : { baseCrlNumber: h.baseCrlNumber },
948
+ ...h.issuingDistributionPoint === void 0 ? {} : { issuingDistributionPoint: h.issuingDistributionPoint },
949
+ ...h.freshestCrlDistributionPoints === void 0 ? {} : { freshestCrlDistributionPoints: h.freshestCrlDistributionPoints },
950
+ revokedCertificates: f
951
+ };
952
+ }
953
+ function parseCrlVersionField(e) {
954
+ let t = e[0];
955
+ if (t !== void 0 && t.tag !== 2 && t.tag !== 48) throw Error("version must use INTEGER");
956
+ if (t?.tag !== 2) return {
957
+ version: 1,
958
+ nextIndex: 0
959
+ };
960
+ let n = g(t.value) + 1;
961
+ if (n !== 2) throw Error(`Unsupported CRL version: ${String(n)}`);
962
+ return {
963
+ version: n,
964
+ nextIndex: 1
965
+ };
966
+ }
967
+ function parseRevokedCertificates(e, t, n) {
968
+ return m(e, t).map((t) => parseRevokedCertificateEntry(e, t, n));
969
+ }
970
+ 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");
972
+ if (a.tag !== 2) throw Error("revoked serialNumber must use INTEGER");
973
+ let o = i[2];
974
+ if (o !== void 0 && n !== 2) throw Error("revoked certificate extensions require CRL version 2");
975
+ let s = parseRevokedCertificateExtensions(r, o);
1093
976
  return {
1094
- version,
1095
- issuer: parseIssuer(tbsCertListDer, issuerElement),
1096
- thisUpdate: parseTime(thisUpdateElement),
1097
- ...nextUpdate === void 0 ? {} : { nextUpdate },
1098
- ...authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier },
1099
- ...crlNumber === void 0 ? {} : { crlNumber },
1100
- ...baseCrlNumber === void 0 ? {} : { baseCrlNumber },
1101
- ...issuingDistributionPoint === void 0 ? {} : { issuingDistributionPoint },
1102
- ...freshestCrlDistributionPoints === void 0 ? {} : { freshestCrlDistributionPoints },
1103
- revokedCertificates
977
+ serialNumberHex: C(a.value),
978
+ revocationDate: x(S(i[1], "revocationDate")),
979
+ ...s.reasonCode === void 0 ? {} : { reasonCode: s.reasonCode },
980
+ ...s.invalidityDate === void 0 ? {} : { invalidityDate: s.invalidityDate },
981
+ ...s.certificateIssuer === void 0 ? {} : { certificateIssuer: s.certificateIssuer }
1104
982
  };
1105
983
  }
984
+ function parseCrlExtensionFields(e, t, n) {
985
+ if (t?.tag !== 160) return {};
986
+ 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);
989
+ return r;
990
+ }
991
+ function parseCrlExtensionField(e, t, n, r) {
992
+ let i = m(e, t);
993
+ 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);
995
+ if (n.has(a)) throw Error(`Duplicate CRL extension OID: ${a}`);
996
+ n.add(a);
997
+ let o = i.length === 3 && h(S(i[1], "extension critical").value), s = S(i[i.length - 1], "extension value");
998
+ if (s.tag !== 4) throw Error("CRL extension value must use OCTET STRING");
999
+ if (!isSupportedCrlExtensionOid(a) && o) throw Error(`Unsupported critical CRL extension OID: ${a}`);
1000
+ applyParsedCrlExtensionField(a, s.value, r);
1001
+ }
1002
+ function isSupportedCrlExtensionOid(e) {
1003
+ return e === w.authorityKeyIdentifier || e === w.cRLNumber || e === w.deltaCRLIndicator || e === w.issuingDistributionPoint || e === w.freshestCRL;
1004
+ }
1005
+ function applyParsedCrlExtensionField(e, t, n) {
1006
+ if (e === w.authorityKeyIdentifier) {
1007
+ let e = parseAuthorityKeyIdentifier(t);
1008
+ e !== void 0 && (n.authorityKeyIdentifier = e);
1009
+ }
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));
1011
+ }
1106
1012
  /** Accepts PEM, DER, or already-parsed certificate and returns a parsed certificate. */
1107
- function normalizeCrlCertificate(source) {
1108
- return hasParsedCertificateShape(source) ? parseCertificateDerOrThrow(new Uint8Array(source.der)) : parseCertificateFromSource(source);
1013
+ function normalizeCrlCertificate(e) {
1014
+ return hasParsedCertificateShape(e) ? U(new Uint8Array(e.der)) : W(e);
1109
1015
  }
1110
- function hasParsedCertificateShape(value) {
1111
- return typeof value !== "string" && "subjectPublicKeyInfoDer" in value;
1016
+ function hasParsedCertificateShape(e) {
1017
+ return typeof e != "string" && "subjectPublicKeyInfoDer" in e;
1112
1018
  }
1113
- function hasReparseableCrlShape(crl) {
1114
- return "der" in crl && crl.der instanceof Uint8Array;
1019
+ function hasReparseableCrlShape(e) {
1020
+ return "der" in e && e.der instanceof Uint8Array;
1115
1021
  }
1116
1022
  /** Shared UTF-8 decoder instance. */
1117
- const textDecoder = new TextDecoder();
1023
+ const Q = new TextDecoder();
1118
1024
  //#endregion
1119
1025
  export { checkCertificateRevocationAgainstCrl, createCertificateRevocationList, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, revocationReasonFromCode, validateCertificateRevocationList, verifyCertificateRevocationListSignature };
1026
+
1027
+ //# sourceMappingURL=crl.js.map