micro509 0.17.0 → 0.18.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 (137) hide show
  1. package/CHANGELOG.md +123 -6
  2. package/README.md +3 -0
  3. package/dist/crypto/crypto.d.ts +2 -3
  4. package/dist/crypto.d.ts +6 -0
  5. package/dist/der/der.d.ts +14 -4
  6. package/dist/der/der.js +19 -19
  7. package/dist/der.d.ts +26 -2
  8. package/dist/der.js +4 -4
  9. package/dist/index.d.ts +82 -15
  10. package/dist/index.js +19 -19
  11. package/dist/internal/asn1/asn1.d.ts +1 -2
  12. package/dist/internal/asn1/der.d.ts +1 -2
  13. package/dist/internal/asn1/oids.js +71 -353
  14. package/dist/internal/asn1/oids.js.map +1 -1
  15. package/dist/internal/asn1/oids.json.js +357 -0
  16. package/dist/internal/asn1/oids.json.js.map +1 -0
  17. package/dist/internal/crypto/algorithm-names.js +1 -1
  18. package/dist/internal/crypto/pbes2.d.ts +1 -2
  19. package/dist/internal/crypto/pbes2.js +70 -70
  20. package/dist/internal/crypto/prime-ec.js +37 -0
  21. package/dist/internal/crypto/prime-ec.js.map +1 -0
  22. package/dist/internal/crypto/rsa-pss.js +50 -50
  23. package/dist/internal/crypto/sig-verify.d.ts +1 -2
  24. package/dist/internal/crypto/sig-verify.js +60 -60
  25. package/dist/internal/crypto/signing.d.ts +1 -2
  26. package/dist/internal/crypto/signing.js +26 -26
  27. package/dist/internal/jose/json-data.js +108 -0
  28. package/dist/internal/jose/json-data.js.map +1 -0
  29. package/dist/internal/jose/strict-json.d.ts +1 -2
  30. package/dist/internal/shared/dn.d.ts +1 -2
  31. package/dist/internal/shared/dn.js +1 -1
  32. package/dist/internal/shared/ip.d.ts +1 -2
  33. package/dist/internal/verify/name-constraints-engine.js +64 -64
  34. package/dist/internal/verify/policy-engine.js +1 -1
  35. package/dist/internal/verify/verify-path.d.ts +1 -2
  36. package/dist/internal/verify/verify-path.js +19 -19
  37. package/dist/internal/x509/directory-name.js +10 -10
  38. package/dist/internal/x509/extension-errors.d.ts +1 -2
  39. package/dist/internal/x509/extension-registry.js +18 -18
  40. package/dist/internal/x509/general-name-profile.js +9 -9
  41. package/dist/internal/x509/general-name.js +32 -32
  42. package/dist/internal/x509/name-fields.js +1 -1
  43. package/dist/jose/base64url.d.ts +4 -0
  44. package/dist/jose/base64url.js +14 -0
  45. package/dist/jose/base64url.js.map +1 -0
  46. package/dist/jose/errors.d.ts +9 -3
  47. package/dist/jose/errors.js.map +1 -1
  48. package/dist/jose/jwe.d.ts +64 -0
  49. package/dist/jose/jwe.js +188 -0
  50. package/dist/jose/jwe.js.map +1 -0
  51. package/dist/jose/jwks.d.ts +38 -10
  52. package/dist/jose/jwks.js +156 -96
  53. package/dist/jose/jwks.js.map +1 -1
  54. package/dist/jose/jws.d.ts +8 -6
  55. package/dist/jose/jws.js +216 -170
  56. package/dist/jose/jws.js.map +1 -1
  57. package/dist/jose/jwt.d.ts +8 -2
  58. package/dist/jose/jwt.js +98 -98
  59. package/dist/jose/remote-jwks.d.ts +1 -2
  60. package/dist/jose/remote-jwks.js +106 -108
  61. package/dist/jose/remote-jwks.js.map +1 -1
  62. package/dist/jose.d.ts +15 -4
  63. package/dist/jose.js +7 -5
  64. package/dist/kdf/argon2-arithmetic.js +15 -0
  65. package/dist/kdf/argon2-arithmetic.js.map +1 -0
  66. package/dist/kdf/argon2-core.js +486 -0
  67. package/dist/kdf/argon2-core.js.map +1 -0
  68. package/dist/kdf/argon2-memory.js +20 -0
  69. package/dist/kdf/argon2-memory.js.map +1 -0
  70. package/dist/kdf/argon2-portable.js +18 -0
  71. package/dist/kdf/argon2-portable.js.map +1 -0
  72. package/dist/kdf/argon2.d.ts +22 -11
  73. package/dist/kdf/argon2.js +32 -13
  74. package/dist/kdf/argon2.js.map +1 -1
  75. package/dist/kdf.d.ts +6 -0
  76. package/dist/keys/keys.d.ts +31 -6
  77. package/dist/keys/keys.js +315 -233
  78. package/dist/keys/keys.js.map +1 -1
  79. package/dist/keys.d.ts +11 -2
  80. package/dist/keys.js +2 -2
  81. package/dist/pem/pem.d.ts +1 -2
  82. package/dist/pem/pem.js +40 -25
  83. package/dist/pem/pem.js.map +1 -1
  84. package/dist/pem.d.ts +6 -0
  85. package/dist/pkcs/pfx.d.ts +2 -3
  86. package/dist/pkcs/pfx.js +142 -142
  87. package/dist/pkcs/pkcs12-mac.d.ts +1 -2
  88. package/dist/pkcs/pkcs12-mac.js +122 -122
  89. package/dist/pkcs/pkcs7.d.ts +14 -3
  90. package/dist/pkcs/pkcs7.js +268 -248
  91. package/dist/pkcs/pkcs7.js.map +1 -1
  92. package/dist/pkcs.d.ts +10 -1
  93. package/dist/pkcs.js +4 -4
  94. package/dist/result/result.d.ts +1 -2
  95. package/dist/result.d.ts +6 -0
  96. package/dist/revocation/chain.d.ts +2 -3
  97. package/dist/revocation/chain.js +52 -52
  98. package/dist/revocation/crl.d.ts +2 -3
  99. package/dist/revocation/crl.js +319 -319
  100. package/dist/revocation/crl.js.map +1 -1
  101. package/dist/revocation/ocsp.d.ts +2 -3
  102. package/dist/revocation/ocsp.js +395 -395
  103. package/dist/revocation/revocation.d.ts +2 -3
  104. package/dist/revocation/revocation.js +22 -22
  105. package/dist/revocation.d.ts +12 -3
  106. package/dist/revocation.js +4 -4
  107. package/dist/ssh/ssh.d.ts +2 -3
  108. package/dist/ssh/ssh.js +165 -170
  109. package/dist/ssh/ssh.js.map +1 -1
  110. package/dist/ssh/wire.d.ts +1 -2
  111. package/dist/ssh/wire.js +10 -10
  112. package/dist/ssh.d.ts +8 -0
  113. package/dist/verify/identity.d.ts +1 -2
  114. package/dist/verify/identity.js +31 -31
  115. package/dist/verify/name-constraints.d.ts +9 -2
  116. package/dist/verify/policy.d.ts +9 -2
  117. package/dist/verify/verify.d.ts +3 -4
  118. package/dist/verify/verify.js +121 -121
  119. package/dist/verify.d.ts +9 -0
  120. package/dist/x509/certificate.d.ts +4 -5
  121. package/dist/x509/certificate.js +40 -40
  122. package/dist/x509/csr.d.ts +3 -4
  123. package/dist/x509/csr.js +15 -15
  124. package/dist/x509/extensions.d.ts +1 -2
  125. package/dist/x509/extensions.js +165 -165
  126. package/dist/x509/extensions.js.map +1 -1
  127. package/dist/x509/fingerprint.d.ts +1 -2
  128. package/dist/x509/name-text.d.ts +1 -2
  129. package/dist/x509/name.d.ts +1 -2
  130. package/dist/x509/name.js +15 -15
  131. package/dist/x509/parse.d.ts +3 -4
  132. package/dist/x509/parse.js +423 -423
  133. package/dist/x509.d.ts +17 -4
  134. package/dist/x509.js +8 -8
  135. package/package.json +27 -34
  136. package/dist/internal/asn1/oids2.js +0 -75
  137. package/dist/internal/asn1/oids2.js.map +0 -1
@@ -1,17 +1,17 @@
1
- import { DECODE_REFUSAL_CODES as e, failureResult as t, rethrowIfInvariant as n, successResult as r } from "../result/result.js";
2
- import { decodeFailureResult as i, decodeRefusalOf as a } from "../internal/asn1/decode-refusal.js";
3
- import { optionalBytesEqual as o, readElement as s, readRootElement as c, readSequenceChildren as l } from "../internal/asn1/der.js";
4
- import { childrenOf as u, decodeBoolean as d, decodeIntegerNumber as f, decodeNonNegativeIntegerNumber as p, decodeObjectIdentifier as m, decodeString as h, decodeVisibleString as g, extractBitStringValue as _, parseTime as v, requireElement as y, toHex as b } from "../internal/asn1/asn1.js";
5
- import { OIDS as x } from "../internal/asn1/oids2.js";
6
- import { pemDecodeOrThrow as S, splitPemBlocksOrThrow as C } from "../pem/pem.js";
7
- import { derivePublicKey as w, exportSpkiDer as T, importSpkiDer as E, importSpkiDerOrThrow as D } from "../keys/keys.js";
8
- import { describePublicKeyAlgorithm as O, describeSignatureAlgorithm as k } from "../internal/crypto/algorithm-names.js";
9
- import { readDirectoryNameTlv as A } from "../internal/x509/directory-name.js";
10
- import { parseDistributionPointReasonFlagsContent as j, parseKeyUsageExtension as M } from "../internal/x509/extension-bits.js";
11
- import { decodeSrvName as N, otherNameValueDer as P, parseGeneralName as F, parseGeneralNames as I, readOtherName as L } from "../internal/x509/general-name.js";
12
- import { nameFieldKeyFromOid as R } from "../internal/x509/name-fields.js";
1
+ import { childrenOf as e, decodeBoolean as t, decodeIntegerNumber as n, decodeNonNegativeIntegerNumber as r, decodeObjectIdentifier as i, decodeString as a, decodeVisibleString as o, extractBitStringValue as s, parseTime as c, requireElement as l, toHex as u } from "../internal/asn1/asn1.js";
2
+ import { decodeFailureResult as d, decodeRefusalOf as f } from "../internal/asn1/decode-refusal.js";
3
+ import { optionalBytesEqual as p, readElement as m, readRootElement as h, readSequenceChildren as g } from "../internal/asn1/der.js";
4
+ import { OIDS as _ } from "../internal/asn1/oids.js";
5
+ import { describePublicKeyAlgorithm as v, describeSignatureAlgorithm as y } from "../internal/crypto/algorithm-names.js";
6
+ import { readDirectoryNameTlv as b } from "../internal/x509/directory-name.js";
7
+ import { parseDistributionPointReasonFlagsContent as x, parseKeyUsageExtension as S } from "../internal/x509/extension-bits.js";
8
+ import { decodeAndApplyKnownExtension as C } from "../internal/x509/extension-registry.js";
9
+ import { decodeSrvName as w, otherNameValueDer as T, parseGeneralName as E, parseGeneralNames as D, readOtherName as O } from "../internal/x509/general-name.js";
10
+ import { derivePublicKey as k, exportSpkiDer as A, importSpkiDer as j, importSpkiDerOrThrow as M } from "../keys/keys.js";
11
+ import { pemDecodeOrThrow as N, splitPemBlocksOrThrow as P } from "../pem/pem.js";
12
+ import { DECODE_REFUSAL_CODES as F, failureResult as I, rethrowIfInvariant as L, successResult as R } from "../result/result.js";
13
13
  import { parseAuthorityInfoAccessMethodOid as z, parseExtendedKeyUsageOid as B } from "./extensions.js";
14
- import { decodeAndApplyKnownExtension as V } from "../internal/x509/extension-registry.js";
14
+ import { nameFieldKeyFromOid as V } from "../internal/x509/name-fields.js";
15
15
  // src/x509/parse.ts
16
16
  /**
17
17
  * Certificate and CSR parse boundary.
@@ -53,45 +53,45 @@ function defineExtensionDecoderMap(e) {
53
53
  * @param options Custom extension decoders to apply during parsing.
54
54
  */
55
55
  function parseCertificateDerOrThrow(e, t) {
56
- let n = l(e, { maxDepth: 64 });
56
+ let n = g(e, { maxDepth: 64 });
57
57
  if (n.length !== 3) throw Error("Malformed Certificate");
58
- let r = y(n[0], "TBSCertificate"), i = y(n[1], "signatureAlgorithm"), a = y(n[2], "signatureValue"), o = parseTbsCertificateFields(e, r), s = parseExtensionContainer(e, o.extensions), c = parseValidity(e, o.validity), u = parseSubjectPublicKeyInfo(e, o.subjectPublicKeyInfo), d = parseAlgorithmIdentifier(e, o.tbsSignatureAlgorithm), f = parseAlgorithmIdentifier(e, i);
59
- assertMatchingCertificateSignatureAlgorithms(d, f);
60
- let p = parseCustomExtensions(s.all, t);
58
+ let r = l(n[0], "TBSCertificate"), i = l(n[1], "signatureAlgorithm"), a = l(n[2], "signatureValue"), o = parseTbsCertificateFields(e, r), c = parseExtensionContainer(e, o.extensions), d = parseValidity(e, o.validity), f = parseSubjectPublicKeyInfo(e, o.subjectPublicKeyInfo), p = parseAlgorithmIdentifier(e, o.tbsSignatureAlgorithm), m = parseAlgorithmIdentifier(e, i);
59
+ assertMatchingCertificateSignatureAlgorithms(p, m);
60
+ let h = parseCustomExtensions(c.all, t);
61
61
  return {
62
62
  der: new Uint8Array(e),
63
63
  version: o.version,
64
- serialNumberHex: b(o.serialNumber.value),
64
+ serialNumberHex: u(o.serialNumber.value),
65
65
  tbsCertificateDer: e.slice(r.start - r.headerLength, r.end),
66
66
  subjectPublicKeyInfoDer: e.slice(o.subjectPublicKeyInfo.start - o.subjectPublicKeyInfo.headerLength, o.subjectPublicKeyInfo.end),
67
- signatureValue: _(a),
67
+ signatureValue: s(a),
68
68
  issuer: parseName(e, o.issuer),
69
69
  subject: parseName(e, o.subject),
70
- notBefore: c.notBefore,
71
- notAfter: c.notAfter,
72
- signatureAlgorithmOid: f.oid,
73
- signatureAlgorithmName: k(f.oid, f.parametersDer),
74
- ...f.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: f.parametersDer },
75
- publicKeyAlgorithmOid: u.oid,
76
- publicKeyAlgorithmName: O(u.oid, u.parametersOid),
77
- ...u.parametersDer === void 0 ? {} : { publicKeyAlgorithmParametersDer: u.parametersDer },
78
- ...u.parametersOid === void 0 ? {} : { publicKeyParametersOid: u.parametersOid },
79
- extensions: s.all,
80
- ...s.basicConstraints === void 0 ? {} : { basicConstraints: s.basicConstraints },
81
- ...s.keyUsage === void 0 ? {} : { keyUsage: s.keyUsage },
82
- ...s.extendedKeyUsage === void 0 ? {} : { extendedKeyUsage: s.extendedKeyUsage },
83
- ...s.subjectAltNames === void 0 ? {} : { subjectAltNames: s.subjectAltNames },
84
- ...s.issuerAltNames === void 0 ? {} : { issuerAltNames: s.issuerAltNames },
85
- ...s.nameConstraints === void 0 ? {} : { nameConstraints: s.nameConstraints },
86
- ...s.certificatePolicies === void 0 ? {} : { certificatePolicies: s.certificatePolicies },
87
- ...s.policyMappings === void 0 ? {} : { policyMappings: s.policyMappings },
88
- ...s.policyConstraints === void 0 ? {} : { policyConstraints: s.policyConstraints },
89
- ...s.inhibitAnyPolicy === void 0 ? {} : { inhibitAnyPolicy: s.inhibitAnyPolicy },
90
- ...accessExtensionFields(s),
91
- ...p.decodedExtensions === void 0 ? {} : { decodedExtensions: p.decodedExtensions },
92
- ...p.decodedExtensionMap === void 0 ? {} : { decodedExtensionMap: p.decodedExtensionMap },
93
- ...s.subjectKeyIdentifier === void 0 ? {} : { subjectKeyIdentifier: s.subjectKeyIdentifier },
94
- ...s.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: s.authorityKeyIdentifier }
70
+ notBefore: d.notBefore,
71
+ notAfter: d.notAfter,
72
+ signatureAlgorithmOid: m.oid,
73
+ signatureAlgorithmName: y(m.oid, m.parametersDer),
74
+ ...m.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: m.parametersDer },
75
+ publicKeyAlgorithmOid: f.oid,
76
+ publicKeyAlgorithmName: v(f.oid, f.parametersOid),
77
+ ...f.parametersDer === void 0 ? {} : { publicKeyAlgorithmParametersDer: f.parametersDer },
78
+ ...f.parametersOid === void 0 ? {} : { publicKeyParametersOid: f.parametersOid },
79
+ extensions: c.all,
80
+ ...c.basicConstraints === void 0 ? {} : { basicConstraints: c.basicConstraints },
81
+ ...c.keyUsage === void 0 ? {} : { keyUsage: c.keyUsage },
82
+ ...c.extendedKeyUsage === void 0 ? {} : { extendedKeyUsage: c.extendedKeyUsage },
83
+ ...c.subjectAltNames === void 0 ? {} : { subjectAltNames: c.subjectAltNames },
84
+ ...c.issuerAltNames === void 0 ? {} : { issuerAltNames: c.issuerAltNames },
85
+ ...c.nameConstraints === void 0 ? {} : { nameConstraints: c.nameConstraints },
86
+ ...c.certificatePolicies === void 0 ? {} : { certificatePolicies: c.certificatePolicies },
87
+ ...c.policyMappings === void 0 ? {} : { policyMappings: c.policyMappings },
88
+ ...c.policyConstraints === void 0 ? {} : { policyConstraints: c.policyConstraints },
89
+ ...c.inhibitAnyPolicy === void 0 ? {} : { inhibitAnyPolicy: c.inhibitAnyPolicy },
90
+ ...accessExtensionFields(c),
91
+ ...h.decodedExtensions === void 0 ? {} : { decodedExtensions: h.decodedExtensions },
92
+ ...h.decodedExtensionMap === void 0 ? {} : { decodedExtensionMap: h.decodedExtensionMap },
93
+ ...c.subjectKeyIdentifier === void 0 ? {} : { subjectKeyIdentifier: c.subjectKeyIdentifier },
94
+ ...c.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: c.authorityKeyIdentifier }
95
95
  };
96
96
  }
97
97
  function parseCustomExtensions(e, t) {
@@ -105,33 +105,33 @@ function parseCustomExtensions(e, t) {
105
105
  }
106
106
  }
107
107
  /** Extracts and validates the structural fields of a TBSCertificate sequence. */
108
- function parseTbsCertificateFields(e, t) {
109
- let n = u(e, t), r = parseCertificateVersionField(e, n), i = r.version, a = r.nextIndex, o = y(n[a], "serialNumber");
110
- if (o.tag !== 2) throw Error("serialNumber must use INTEGER");
111
- let s = validateOptionalTbsCertificateFields(n, a + 6, i);
108
+ function parseTbsCertificateFields(t, n) {
109
+ let r = e(t, n), i = parseCertificateVersionField(t, r), a = i.version, o = i.nextIndex, s = l(r[o], "serialNumber");
110
+ if (s.tag !== 2) throw Error("serialNumber must use INTEGER");
111
+ let c = validateOptionalTbsCertificateFields(r, o + 6, a);
112
112
  return {
113
- version: i,
114
- serialNumber: o,
115
- tbsSignatureAlgorithm: y(n[a + 1], "TBSCertificate signature"),
116
- issuer: y(n[a + 2], "issuer"),
117
- validity: y(n[a + 3], "validity"),
118
- subject: y(n[a + 4], "subject"),
119
- subjectPublicKeyInfo: y(n[a + 5], "subjectPublicKeyInfo"),
120
- ...n[s - 1]?.tag === 163 ? { extensions: n[s - 1] } : {}
113
+ version: a,
114
+ serialNumber: s,
115
+ tbsSignatureAlgorithm: l(r[o + 1], "TBSCertificate signature"),
116
+ issuer: l(r[o + 2], "issuer"),
117
+ validity: l(r[o + 3], "validity"),
118
+ subject: l(r[o + 4], "subject"),
119
+ subjectPublicKeyInfo: l(r[o + 5], "subjectPublicKeyInfo"),
120
+ ...r[c - 1]?.tag === 163 ? { extensions: r[c - 1] } : {}
121
121
  };
122
122
  }
123
- function parseCertificateVersionField(e, t) {
124
- let n = t[0];
125
- if (n?.tag !== 160) return {
123
+ function parseCertificateVersionField(t, r) {
124
+ let i = r[0];
125
+ if (i?.tag !== 160) return {
126
126
  version: 1,
127
127
  nextIndex: 0
128
128
  };
129
- let r = u(e, n), i = y(r[0], "version INTEGER");
130
- if (r.length !== 1 || i.tag !== 2) throw Error("version must use INTEGER");
131
- let a = f(i.value) + 1;
132
- if (a < 1 || a > 3) throw Error(`Unsupported certificate version: ${String(a)}`);
129
+ let a = e(t, i), o = l(a[0], "version INTEGER");
130
+ if (a.length !== 1 || o.tag !== 2) throw Error("version must use INTEGER");
131
+ let s = n(o.value) + 1;
132
+ if (s < 1 || s > 3) throw Error(`Unsupported certificate version: ${String(s)}`);
133
133
  return {
134
- version: a,
134
+ version: s,
135
135
  nextIndex: 1
136
136
  };
137
137
  }
@@ -141,11 +141,11 @@ function validateOptionalTbsCertificateFields(e, t, n) {
141
141
  if (n !== 3) throw Error("extensions require certificate version 3");
142
142
  r += 1;
143
143
  }
144
- if (r !== e.length) throw Error(`Unsupported TBSCertificate field tag: ${String(y(e[r], "TBSCertificate field").tag)}`);
144
+ if (r !== e.length) throw Error(`Unsupported TBSCertificate field tag: ${String(l(e[r], "TBSCertificate field").tag)}`);
145
145
  return r;
146
146
  }
147
147
  function validateCertificateUniqueId(e, t, n) {
148
- let r = y(e, n);
148
+ let r = l(e, n);
149
149
  if (t < 2) throw Error(`${n} requires certificate version 2 or 3`);
150
150
  validateImplicitBitStringContent(r.value, n);
151
151
  }
@@ -165,11 +165,11 @@ function validateCertificateUniqueId(e, t, n) {
165
165
  * @param der Raw DER bytes of an X.509 certificate.
166
166
  * @param options Custom extension decoders to apply during parsing.
167
167
  */
168
- function parseCertificateDer(t, a) {
168
+ function parseCertificateDer(e, t) {
169
169
  try {
170
- return r(parseCertificateDerOrThrow(t, a));
171
- } catch (t) {
172
- return n(t), i(t, e, "Malformed certificate");
170
+ return R(parseCertificateDerOrThrow(e, t));
171
+ } catch (e) {
172
+ return L(e), d(e, F, "Malformed certificate");
173
173
  }
174
174
  }
175
175
  /**
@@ -191,7 +191,7 @@ function parseCertificateDer(t, a) {
191
191
  * @param options Custom extension decoders to apply during parsing.
192
192
  */
193
193
  function parseCertificatePemOrThrow(e, t) {
194
- return parseCertificateDerOrThrow(S("CERTIFICATE", e), t);
194
+ return parseCertificateDerOrThrow(N("CERTIFICATE", e), t);
195
195
  }
196
196
  /**
197
197
  * Decode a PEM-encoded X.509 certificate into a {@linkcode ParsedCertificate}.
@@ -205,11 +205,11 @@ function parseCertificatePemOrThrow(e, t) {
205
205
  * @param pem PEM string with a CERTIFICATE block.
206
206
  * @param options Custom extension decoders to apply during parsing.
207
207
  */
208
- function parseCertificatePem(t, a) {
208
+ function parseCertificatePem(e, t) {
209
209
  try {
210
- return r(parseCertificatePemOrThrow(t, a));
211
- } catch (t) {
212
- return n(t), i(t, e, "Malformed certificate");
210
+ return R(parseCertificatePemOrThrow(e, t));
211
+ } catch (e) {
212
+ return L(e), d(e, F, "Malformed certificate");
213
213
  }
214
214
  }
215
215
  /** Normalizes a PEM bundle or single DER certificate source into parsed certificates. */
@@ -240,11 +240,11 @@ function parseCertificateChainPemOrThrow(e, t) {
240
240
  * @param pemBundle PEM text that may contain multiple CERTIFICATE blocks.
241
241
  * @param options Custom extension decoders to apply during parsing.
242
242
  */
243
- function parseCertificateChainPem(t, a) {
243
+ function parseCertificateChainPem(e, t) {
244
244
  try {
245
- return r(parseCertificateChainPemOrThrow(t, a));
246
- } catch (t) {
247
- return n(t), i(t, e, "Malformed certificate chain");
245
+ return R(parseCertificateChainPemOrThrow(e, t));
246
+ } catch (e) {
247
+ return L(e), d(e, F, "Malformed certificate chain");
248
248
  }
249
249
  }
250
250
  /**
@@ -254,51 +254,51 @@ function parseCertificateChainPem(t, a) {
254
254
  * @param options Custom extension decoders to apply during parsing.
255
255
  */
256
256
  function parseCertificateSigningRequestDerOrThrow(e, t) {
257
- let n = l(e, { maxDepth: 64 });
257
+ let n = g(e, { maxDepth: 64 });
258
258
  if (n.length !== 3) throw Error("Malformed CertificationRequest");
259
- let r = y(n[0], "CertificationRequestInfo"), i = y(n[1], "signatureAlgorithm"), a = y(n[2], "signatureValue"), o = parseCertificationRequestInfoFields(e, r), s = parseRequestedExtensions(e, o.attributes), c = parseSubjectPublicKeyInfo(e, o.subjectPublicKeyInfo), u = parseAlgorithmIdentifier(e, i), d = parseCustomExtensions(s.all, t);
259
+ let r = l(n[0], "CertificationRequestInfo"), i = l(n[1], "signatureAlgorithm"), a = l(n[2], "signatureValue"), o = parseCertificationRequestInfoFields(e, r), c = parseRequestedExtensions(e, o.attributes), u = parseSubjectPublicKeyInfo(e, o.subjectPublicKeyInfo), d = parseAlgorithmIdentifier(e, i), f = parseCustomExtensions(c.all, t);
260
260
  return {
261
261
  version: o.version,
262
262
  certificationRequestInfoDer: e.slice(r.start - r.headerLength, r.end),
263
263
  subjectPublicKeyInfoDer: e.slice(o.subjectPublicKeyInfo.start - o.subjectPublicKeyInfo.headerLength, o.subjectPublicKeyInfo.end),
264
- signatureValue: _(a),
264
+ signatureValue: s(a),
265
265
  subject: parseName(e, o.subject),
266
- signatureAlgorithmOid: u.oid,
267
- signatureAlgorithmName: k(u.oid, u.parametersDer),
268
- ...u.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: u.parametersDer },
269
- publicKeyAlgorithmOid: c.oid,
270
- publicKeyAlgorithmName: O(c.oid, c.parametersOid),
271
- ...c.parametersDer === void 0 ? {} : { publicKeyAlgorithmParametersDer: c.parametersDer },
272
- ...c.parametersOid === void 0 ? {} : { publicKeyParametersOid: c.parametersOid },
273
- requestedExtensions: s.all,
274
- ...s.basicConstraints === void 0 ? {} : { basicConstraints: s.basicConstraints },
275
- ...s.keyUsage === void 0 ? {} : { keyUsage: s.keyUsage },
276
- ...s.extendedKeyUsage === void 0 ? {} : { extendedKeyUsage: s.extendedKeyUsage },
277
- ...s.subjectAltNames === void 0 ? {} : { subjectAltNames: s.subjectAltNames },
278
- ...s.nameConstraints === void 0 ? {} : { nameConstraints: s.nameConstraints },
279
- ...s.certificatePolicies === void 0 ? {} : { certificatePolicies: s.certificatePolicies },
280
- ...s.policyMappings === void 0 ? {} : { policyMappings: s.policyMappings },
281
- ...s.policyConstraints === void 0 ? {} : { policyConstraints: s.policyConstraints },
282
- ...s.inhibitAnyPolicy === void 0 ? {} : { inhibitAnyPolicy: s.inhibitAnyPolicy },
283
- ...accessExtensionFields(s),
284
- ...d.decodedExtensions === void 0 ? {} : { decodedExtensions: d.decodedExtensions },
285
- ...d.decodedExtensionMap === void 0 ? {} : { decodedExtensionMap: d.decodedExtensionMap }
266
+ signatureAlgorithmOid: d.oid,
267
+ signatureAlgorithmName: y(d.oid, d.parametersDer),
268
+ ...d.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: d.parametersDer },
269
+ publicKeyAlgorithmOid: u.oid,
270
+ publicKeyAlgorithmName: v(u.oid, u.parametersOid),
271
+ ...u.parametersDer === void 0 ? {} : { publicKeyAlgorithmParametersDer: u.parametersDer },
272
+ ...u.parametersOid === void 0 ? {} : { publicKeyParametersOid: u.parametersOid },
273
+ requestedExtensions: c.all,
274
+ ...c.basicConstraints === void 0 ? {} : { basicConstraints: c.basicConstraints },
275
+ ...c.keyUsage === void 0 ? {} : { keyUsage: c.keyUsage },
276
+ ...c.extendedKeyUsage === void 0 ? {} : { extendedKeyUsage: c.extendedKeyUsage },
277
+ ...c.subjectAltNames === void 0 ? {} : { subjectAltNames: c.subjectAltNames },
278
+ ...c.nameConstraints === void 0 ? {} : { nameConstraints: c.nameConstraints },
279
+ ...c.certificatePolicies === void 0 ? {} : { certificatePolicies: c.certificatePolicies },
280
+ ...c.policyMappings === void 0 ? {} : { policyMappings: c.policyMappings },
281
+ ...c.policyConstraints === void 0 ? {} : { policyConstraints: c.policyConstraints },
282
+ ...c.inhibitAnyPolicy === void 0 ? {} : { inhibitAnyPolicy: c.inhibitAnyPolicy },
283
+ ...accessExtensionFields(c),
284
+ ...f.decodedExtensions === void 0 ? {} : { decodedExtensions: f.decodedExtensions },
285
+ ...f.decodedExtensionMap === void 0 ? {} : { decodedExtensionMap: f.decodedExtensionMap }
286
286
  };
287
287
  }
288
- function parseCertificationRequestInfoFields(e, t) {
289
- let n = u(e, t);
290
- if (n.length !== 4) throw Error("Malformed CertificationRequestInfo");
291
- let r = y(n[0], "version");
292
- if (r.tag !== 2) throw Error("version must use INTEGER");
293
- let i = f(r.value) + 1;
294
- if (i !== 1) throw Error(`Unsupported CertificationRequestInfo version: ${String(i)}`);
295
- let a = y(n[3], "attributes");
296
- if (a.tag !== 160) throw Error("CertificationRequestInfo attributes must use [0]");
288
+ function parseCertificationRequestInfoFields(t, r) {
289
+ let i = e(t, r);
290
+ if (i.length !== 4) throw Error("Malformed CertificationRequestInfo");
291
+ let a = l(i[0], "version");
292
+ if (a.tag !== 2) throw Error("version must use INTEGER");
293
+ let o = n(a.value) + 1;
294
+ if (o !== 1) throw Error(`Unsupported CertificationRequestInfo version: ${String(o)}`);
295
+ let s = l(i[3], "attributes");
296
+ if (s.tag !== 160) throw Error("CertificationRequestInfo attributes must use [0]");
297
297
  return {
298
- version: i,
299
- subject: y(n[1], "subject"),
300
- subjectPublicKeyInfo: y(n[2], "subjectPublicKeyInfo"),
301
- attributes: a
298
+ version: o,
299
+ subject: l(i[1], "subject"),
300
+ subjectPublicKeyInfo: l(i[2], "subjectPublicKeyInfo"),
301
+ attributes: s
302
302
  };
303
303
  }
304
304
  /**
@@ -307,15 +307,15 @@ function parseCertificationRequestInfoFields(e, t) {
307
307
  * @param der Raw DER bytes of a PKCS#10 certificate signing request.
308
308
  * @param options Custom extension decoders to apply during parsing.
309
309
  */
310
- function parseCertificateSigningRequestDer(t, a) {
310
+ function parseCertificateSigningRequestDer(e, t) {
311
311
  try {
312
- return r(parseCertificateSigningRequestDerOrThrow(t, a));
313
- } catch (t) {
314
- return n(t), i(t, e, "Malformed certificate signing request");
312
+ return R(parseCertificateSigningRequestDerOrThrow(e, t));
313
+ } catch (e) {
314
+ return L(e), d(e, F, "Malformed certificate signing request");
315
315
  }
316
316
  }
317
317
  function parseCertificatesFromPemBlocks(e, t) {
318
- return C(e).filter((e) => e.label === "CERTIFICATE").map((e) => parseCertificateDerOrThrow(e.bytes, t));
318
+ return P(e).filter((e) => e.label === "CERTIFICATE").map((e) => parseCertificateDerOrThrow(e.bytes, t));
319
319
  }
320
320
  function hasParsedCertificateShape(e) {
321
321
  return "subjectPublicKeyInfoDer" in e;
@@ -327,7 +327,7 @@ function hasParsedCertificateShape(e) {
327
327
  * @param options Custom extension decoders to apply during parsing.
328
328
  */
329
329
  function parseCertificateSigningRequestPemOrThrow(e, t) {
330
- return parseCertificateSigningRequestDerOrThrow(S("CERTIFICATE REQUEST", e), t);
330
+ return parseCertificateSigningRequestDerOrThrow(N("CERTIFICATE REQUEST", e), t);
331
331
  }
332
332
  /**
333
333
  * Decode a PEM-encoded PKCS#10 CSR into a {@linkcode ParsedCertificateSigningRequest}.
@@ -335,11 +335,11 @@ function parseCertificateSigningRequestPemOrThrow(e, t) {
335
335
  * @param pem PEM string with a CERTIFICATE REQUEST block.
336
336
  * @param options Custom extension decoders to apply during parsing.
337
337
  */
338
- function parseCertificateSigningRequestPem(t, a) {
338
+ function parseCertificateSigningRequestPem(e, t) {
339
339
  try {
340
- return r(parseCertificateSigningRequestPemOrThrow(t, a));
341
- } catch (t) {
342
- return n(t), i(t, e, "Malformed certificate signing request");
340
+ return R(parseCertificateSigningRequestPemOrThrow(e, t));
341
+ } catch (e) {
342
+ return L(e), d(e, F, "Malformed certificate signing request");
343
343
  }
344
344
  }
345
345
  /**
@@ -371,7 +371,7 @@ function parseCertificateSigningRequestPem(t, a) {
371
371
  * @see {@linkcode getSubjectPublicKey} for the non-throwing variant
372
372
  */
373
373
  function getSubjectPublicKeyOrThrow(e, t) {
374
- return D(e.subjectPublicKeyInfoDer, t);
374
+ return M(e.subjectPublicKeyInfoDer, t);
375
375
  }
376
376
  /**
377
377
  * Import the subject public key of a parsed certificate or CSR as a WebCrypto `CryptoKey`.
@@ -379,11 +379,11 @@ function getSubjectPublicKeyOrThrow(e, t) {
379
379
  * @see `getSubjectPublicKeyOrThrow` for the throwing variant
380
380
  */
381
381
  function getSubjectPublicKey(e, t) {
382
- return E(e.subjectPublicKeyInfoDer, t);
382
+ return j(e.subjectPublicKeyInfoDer, t);
383
383
  }
384
384
  /** Extract the AlgorithmIdentifier TLV from a SubjectPublicKeyInfo DER buffer. */
385
385
  function subjectPublicKeyInfoAlgorithmDer(e) {
386
- let t = l(e, { maxDepth: 64 }), n = y(t[0], "SubjectPublicKeyInfo algorithm");
386
+ let t = g(e, { maxDepth: 64 }), n = l(t[0], "SubjectPublicKeyInfo algorithm");
387
387
  return e.slice(n.start - n.headerLength, n.end);
388
388
  }
389
389
  /**
@@ -396,8 +396,8 @@ function subjectPublicKeyInfoAlgorithmDer(e) {
396
396
  * mismatch or a cross-algorithm (`key_type_mismatch`) one.
397
397
  */
398
398
  async function compareCertificateToPrivateKey(e, t) {
399
- let n = await T(await w(t));
400
- return o(n, e) ? "match" : o(subjectPublicKeyInfoAlgorithmDer(n), subjectPublicKeyInfoAlgorithmDer(e)) ? "key_mismatch" : "key_type_mismatch";
399
+ let n = await A(await k(t));
400
+ return p(n, e) ? "match" : p(subjectPublicKeyInfoAlgorithmDer(n), subjectPublicKeyInfoAlgorithmDer(e)) ? "key_mismatch" : "key_type_mismatch";
401
401
  }
402
402
  /**
403
403
  * Check whether a certificate's subject public key belongs to a private key.
@@ -489,26 +489,26 @@ async function certificateMatchesPrivateKey(e, t) {
489
489
  *
490
490
  * @see {@linkcode certificateMatchesPrivateKey} for the plain-boolean variant
491
491
  */
492
- async function matchCertificatePrivateKey(i, o) {
493
- let s;
492
+ async function matchCertificatePrivateKey(e, t) {
493
+ let n;
494
494
  try {
495
- s = parseCertificateFromSource(i);
496
- } catch (r) {
497
- n(r);
498
- let i = a(r, e);
499
- return i === void 0 ? t("malformed_certificate", r instanceof Error ? r.message : "Malformed certificate") : t(i.code, i.message);
495
+ n = parseCertificateFromSource(e);
496
+ } catch (e) {
497
+ L(e);
498
+ let t = f(e, F);
499
+ return t === void 0 ? I("malformed_certificate", e instanceof Error ? e.message : "Malformed certificate") : I(t.code, t.message);
500
500
  }
501
- let c;
501
+ let r;
502
502
  try {
503
- c = await compareCertificateToPrivateKey(s.subjectPublicKeyInfoDer, o);
503
+ r = await compareCertificateToPrivateKey(n.subjectPublicKeyInfoDer, t);
504
504
  } catch (e) {
505
- return n(e), t("unsupported_private_key", e instanceof Error ? e.message : "Unsupported private key");
505
+ return L(e), I("unsupported_private_key", e instanceof Error ? e.message : "Unsupported private key");
506
506
  }
507
- switch (c) {
508
- case "match": return r(void 0);
509
- case "key_mismatch": return t("key_mismatch", "Private key does not match the certificate's subject public key");
510
- case "key_type_mismatch": return t("key_type_mismatch", "Private key algorithm does not match the certificate's subject public key algorithm");
511
- default: throw Error(`Unhandled key comparison result: ${String(c)}`);
507
+ switch (r) {
508
+ case "match": return R(void 0);
509
+ case "key_mismatch": return I("key_mismatch", "Private key does not match the certificate's subject public key");
510
+ case "key_type_mismatch": return I("key_type_mismatch", "Private key algorithm does not match the certificate's subject public key algorithm");
511
+ default: throw Error(`Unhandled key comparison result: ${String(r)}`);
512
512
  }
513
513
  }
514
514
  /**
@@ -582,70 +582,70 @@ function accessExtensionFields(e) {
582
582
  };
583
583
  }
584
584
  /** Decode the explicit [3] extensions wrapper from a TBSCertificate. */
585
- function parseExtensionContainer(e, t) {
586
- return t === void 0 ? { all: [] } : parseExtensionSequence(e, y(u(e, t)[0], "extensions sequence"), "certificate");
585
+ function parseExtensionContainer(t, n) {
586
+ return n === void 0 ? { all: [] } : parseExtensionSequence(t, l(e(t, n)[0], "extensions sequence"), "certificate");
587
587
  }
588
588
  /** Extract extensions from the CSR extensionRequest attribute. */
589
- function parseRequestedExtensions(e, t) {
590
- let n;
591
- for (let r of u(e, t)) {
592
- if (r.tag !== 48) throw Error("CSR attribute must use SEQUENCE");
593
- let t = u(e, r);
594
- if (t.length !== 2) throw Error("Malformed CSR attribute");
595
- let i = y(t[0], "attribute OID");
596
- if (i.tag !== 6) throw Error("CSR attribute type must use OBJECT IDENTIFIER");
597
- let a = y(t[1], "attribute values");
598
- if (a.tag !== 49) throw Error("CSR attribute values must use SET");
599
- let o = u(e, a);
600
- if (o.length === 0) throw Error("CSR attribute values must not be empty");
601
- if (m(i.value) === x.extensionRequest) {
602
- if (n !== void 0) throw Error("extensionRequest attribute must not repeat");
603
- if (o.length !== 1) throw Error("extensionRequest attribute must contain exactly one value");
604
- n = parseExtensionSequence(e, y(o[0], "requested extensions"), "csr");
589
+ function parseRequestedExtensions(t, n) {
590
+ let r;
591
+ for (let a of e(t, n)) {
592
+ if (a.tag !== 48) throw Error("CSR attribute must use SEQUENCE");
593
+ let n = e(t, a);
594
+ if (n.length !== 2) throw Error("Malformed CSR attribute");
595
+ let o = l(n[0], "attribute OID");
596
+ if (o.tag !== 6) throw Error("CSR attribute type must use OBJECT IDENTIFIER");
597
+ let s = l(n[1], "attribute values");
598
+ if (s.tag !== 49) throw Error("CSR attribute values must use SET");
599
+ let c = e(t, s);
600
+ if (c.length === 0) throw Error("CSR attribute values must not be empty");
601
+ if (i(o.value) === _.extensionRequest) {
602
+ if (r !== void 0) throw Error("extensionRequest attribute must not repeat");
603
+ if (c.length !== 1) throw Error("extensionRequest attribute must contain exactly one value");
604
+ r = parseExtensionSequence(t, l(c[0], "requested extensions"), "csr");
605
605
  }
606
606
  }
607
- return n ?? { all: [] };
607
+ return r ?? { all: [] };
608
608
  }
609
609
  /** Walk a SEQUENCE OF Extension and decode each one, populating known-extension slots. */
610
- function parseExtensionSequence(e, t, n) {
611
- let r = [], i = {}, a = /* @__PURE__ */ new Set();
612
- for (let o of u(e, t)) {
613
- let t = u(e, o);
614
- if (t.length < 2 || t.length > 3) throw Error("Malformed Extension");
615
- let s = y(t[0], "extension OID"), c = m(s.value);
616
- if (a.has(c)) throw Error(`Duplicate extension OID: ${c}`);
617
- a.add(c);
618
- let l = 1, f = !1, p = t[l];
619
- p?.tag === 1 && (f = d(p.value), l += 1);
620
- let h = y(t[l], "extension value");
621
- if (h.tag !== 4 || l !== t.length - 1) throw Error("Extension value must use OCTET STRING");
622
- r.push({
623
- oid: c,
624
- critical: f,
625
- valueDer: new Uint8Array(h.value),
626
- valueHex: b(h.value)
627
- }), V(n, c, i, h.value);
610
+ function parseExtensionSequence(n, r, a) {
611
+ let o = [], s = {}, c = /* @__PURE__ */ new Set();
612
+ for (let d of e(n, r)) {
613
+ let r = e(n, d);
614
+ if (r.length < 2 || r.length > 3) throw Error("Malformed Extension");
615
+ let f = l(r[0], "extension OID"), p = i(f.value);
616
+ if (c.has(p)) throw Error(`Duplicate extension OID: ${p}`);
617
+ c.add(p);
618
+ let m = 1, h = !1, g = r[m];
619
+ g?.tag === 1 && (h = t(g.value), m += 1);
620
+ let _ = l(r[m], "extension value");
621
+ if (_.tag !== 4 || m !== r.length - 1) throw Error("Extension value must use OCTET STRING");
622
+ o.push({
623
+ oid: p,
624
+ critical: h,
625
+ valueDer: new Uint8Array(_.value),
626
+ valueHex: u(_.value)
627
+ }), C(a, p, s, _.value);
628
628
  }
629
629
  return {
630
- all: r,
631
- ...i
630
+ all: o,
631
+ ...s
632
632
  };
633
633
  }
634
634
  /** Decode an X.501 Name (issuer / subject) into a {@linkcode ParsedName}. */
635
- function parseName(e, t) {
636
- if (t.tag !== 48) throw Error("Name must use SEQUENCE");
637
- let n = [], r = [], i = {};
638
- for (let a of u(e, t)) {
639
- if (a.tag !== 49) throw Error("RelativeDistinguishedName must use SET");
640
- let t = parseNameAttributeSet(e, a);
641
- n.push(t);
642
- for (let e of t.attributes) r.push(e), e.key !== void 0 && i[e.key] === void 0 && (i[e.key] = e.value);
635
+ function parseName(t, n) {
636
+ if (n.tag !== 48) throw Error("Name must use SEQUENCE");
637
+ let r = [], i = [], a = {};
638
+ for (let o of e(t, n)) {
639
+ if (o.tag !== 49) throw Error("RelativeDistinguishedName must use SET");
640
+ let e = parseNameAttributeSet(t, o);
641
+ r.push(e);
642
+ for (let t of e.attributes) i.push(t), t.key !== void 0 && a[t.key] === void 0 && (a[t.key] = t.value);
643
643
  }
644
644
  return {
645
- derHex: b(e.slice(t.start - t.headerLength, t.end)),
646
- rdns: n,
647
- attributes: r,
648
- values: i
645
+ derHex: u(t.slice(n.start - n.headerLength, n.end)),
646
+ rdns: r,
647
+ attributes: i,
648
+ values: a
649
649
  };
650
650
  }
651
651
  /** Decode a single RDN SET element. */
@@ -653,155 +653,155 @@ function parseRelativeDistinguishedName(e, t) {
653
653
  return parseNameAttributeSet(e, t);
654
654
  }
655
655
  /** Decode the AttributeTypeAndValue pairs within a SET element. */
656
- function parseNameAttributeSet(e, t) {
657
- let n = [], r = {};
658
- for (let i of u(e, t)) {
659
- if (i.tag !== 48) throw Error("AttributeTypeAndValue must use SEQUENCE");
660
- let t = u(e, i);
661
- if (t.length !== 2) throw Error("AttributeTypeAndValue must contain type and value");
662
- let a = y(t[0], "name OID");
663
- if (a.tag !== 6) throw Error("AttributeTypeAndValue type must use OBJECT IDENTIFIER");
664
- let o = m(a.value), s = y(t[1], "name value"), c = R(o), l = h(s.tag, s.value), d = c === void 0 ? {
665
- oid: o,
666
- valueTag: s.tag,
667
- value: l
656
+ function parseNameAttributeSet(t, n) {
657
+ let r = [], o = {};
658
+ for (let s of e(t, n)) {
659
+ if (s.tag !== 48) throw Error("AttributeTypeAndValue must use SEQUENCE");
660
+ let n = e(t, s);
661
+ if (n.length !== 2) throw Error("AttributeTypeAndValue must contain type and value");
662
+ let c = l(n[0], "name OID");
663
+ if (c.tag !== 6) throw Error("AttributeTypeAndValue type must use OBJECT IDENTIFIER");
664
+ let u = i(c.value), d = l(n[1], "name value"), f = V(u), p = a(d.tag, d.value), m = f === void 0 ? {
665
+ oid: u,
666
+ valueTag: d.tag,
667
+ value: p
668
668
  } : {
669
- oid: o,
670
- key: c,
671
- valueTag: s.tag,
672
- value: l
669
+ oid: u,
670
+ key: f,
671
+ valueTag: d.tag,
672
+ value: p
673
673
  };
674
- n.push(d), c !== void 0 && r[c] === void 0 && (r[c] = l);
674
+ r.push(m), f !== void 0 && o[f] === void 0 && (o[f] = p);
675
675
  }
676
676
  return {
677
- derHex: b(e.slice(t.start - t.headerLength, t.end)),
678
- attributes: n,
679
- values: r
677
+ derHex: u(t.slice(n.start - n.headerLength, n.end)),
678
+ attributes: r,
679
+ values: o
680
680
  };
681
681
  }
682
682
  /** Decode the Validity SEQUENCE into notBefore / notAfter Dates. */
683
- function parseValidity(e, t) {
684
- let n = u(e, t);
683
+ function parseValidity(t, n) {
684
+ let r = e(t, n);
685
685
  return {
686
- notBefore: v(y(n[0], "notBefore")),
687
- notAfter: v(y(n[1], "notAfter"))
686
+ notBefore: c(l(r[0], "notBefore")),
687
+ notAfter: c(l(r[1], "notAfter"))
688
688
  };
689
689
  }
690
690
  /** Extract the algorithm identifier from a SubjectPublicKeyInfo SEQUENCE. */
691
- function parseSubjectPublicKeyInfo(e, t) {
692
- if (t.tag !== 48) throw Error("SubjectPublicKeyInfo must use SEQUENCE");
693
- let n = u(e, t);
694
- if (n.length !== 2) throw Error("SubjectPublicKeyInfo must contain algorithm and subjectPublicKey");
695
- let r = y(n[0], "SPKI algorithm");
696
- if (r.tag !== 48) throw Error("SubjectPublicKeyInfo algorithm must use SEQUENCE");
697
- let i = parseAlgorithmIdentifier(e, r);
698
- return _(y(n[1], "subjectPublicKey BIT STRING")), i;
691
+ function parseSubjectPublicKeyInfo(t, n) {
692
+ if (n.tag !== 48) throw Error("SubjectPublicKeyInfo must use SEQUENCE");
693
+ let r = e(t, n);
694
+ if (r.length !== 2) throw Error("SubjectPublicKeyInfo must contain algorithm and subjectPublicKey");
695
+ let i = l(r[0], "SPKI algorithm");
696
+ if (i.tag !== 48) throw Error("SubjectPublicKeyInfo algorithm must use SEQUENCE");
697
+ let a = parseAlgorithmIdentifier(t, i);
698
+ return s(l(r[1], "subjectPublicKey BIT STRING")), a;
699
699
  }
700
700
  /** Decode an AlgorithmIdentifier SEQUENCE (OID + optional parameters). */
701
- function parseAlgorithmIdentifier(e, t) {
702
- if (t.tag !== 48) throw Error("AlgorithmIdentifier must use SEQUENCE");
703
- let n = u(e, t);
704
- if (n.length === 0 || n.length > 2) throw Error("Malformed AlgorithmIdentifier");
705
- let r = y(n[0], "algorithm OID");
706
- if (r.tag !== 6) throw Error("AlgorithmIdentifier algorithm must use OBJECT IDENTIFIER");
707
- let i = m(r.value), a = n[1];
708
- if (a === void 0) return { oid: i };
709
- let o = e.slice(a.start - a.headerLength, a.end);
710
- return a?.tag === 6 ? {
711
- oid: i,
712
- parametersDer: o,
713
- parametersOid: m(a.value)
701
+ function parseAlgorithmIdentifier(t, n) {
702
+ if (n.tag !== 48) throw Error("AlgorithmIdentifier must use SEQUENCE");
703
+ let r = e(t, n);
704
+ if (r.length === 0 || r.length > 2) throw Error("Malformed AlgorithmIdentifier");
705
+ let a = l(r[0], "algorithm OID");
706
+ if (a.tag !== 6) throw Error("AlgorithmIdentifier algorithm must use OBJECT IDENTIFIER");
707
+ let o = i(a.value), s = r[1];
708
+ if (s === void 0) return { oid: o };
709
+ let c = t.slice(s.start - s.headerLength, s.end);
710
+ return s?.tag === 6 ? {
711
+ oid: o,
712
+ parametersDer: c,
713
+ parametersOid: i(s.value)
714
714
  } : {
715
- oid: i,
716
- parametersDer: o
715
+ oid: o,
716
+ parametersDer: c
717
717
  };
718
718
  }
719
719
  function assertMatchingCertificateSignatureAlgorithms(e, t) {
720
- if (e.oid !== t.oid || !o(e.parametersDer, t.parametersDer)) throw Error("Certificate signatureAlgorithm must match TBSCertificate signature");
720
+ if (e.oid !== t.oid || !p(e.parametersDer, t.parametersDer)) throw Error("Certificate signatureAlgorithm must match TBSCertificate signature");
721
721
  }
722
722
  /** Decodes the Basic Constraints extension value DER. */
723
- function parseBasicConstraints(e) {
724
- let t = c(e, { maxDepth: 64 });
725
- if (t.tag !== 48) throw Error("basicConstraints must use SEQUENCE");
726
- let n = u(e, t), r = !1, i, a = !1, o = !1;
727
- for (let e of n) if (e.tag === 1) {
728
- if (a) throw Error("basicConstraints cA must not repeat");
729
- if (o) throw Error("basicConstraints cA must precede pathLength");
730
- a = !0, r = d(e.value);
723
+ function parseBasicConstraints(n) {
724
+ let i = h(n, { maxDepth: 64 });
725
+ if (i.tag !== 48) throw Error("basicConstraints must use SEQUENCE");
726
+ let a = e(n, i), o = !1, s, c = !1, l = !1;
727
+ for (let e of a) if (e.tag === 1) {
728
+ if (c) throw Error("basicConstraints cA must not repeat");
729
+ if (l) throw Error("basicConstraints cA must precede pathLength");
730
+ c = !0, o = t(e.value);
731
731
  } else if (e.tag === 2) {
732
- if (o) throw Error("basicConstraints pathLength must not repeat");
733
- o = !0, i = p(e.value, "basicConstraints pathLength");
732
+ if (l) throw Error("basicConstraints pathLength must not repeat");
733
+ l = !0, s = r(e.value, "basicConstraints pathLength");
734
734
  } else throw Error(`Unsupported basicConstraints field tag: ${String(e.tag)}`);
735
- if (i !== void 0 && r !== !0) throw Error("basicConstraints pathLength requires cA = true");
736
- return r ? i === void 0 ? { ca: !0 } : {
735
+ if (s !== void 0 && o !== !0) throw Error("basicConstraints pathLength requires cA = true");
736
+ return o ? s === void 0 ? { ca: !0 } : {
737
737
  ca: !0,
738
- pathLength: i
738
+ pathLength: s
739
739
  } : { ca: !1 };
740
740
  }
741
741
  /** Decodes the Key Usage BIT STRING extension value. */
742
742
  function parseKeyUsage(e) {
743
- return M(e);
743
+ return S(e);
744
744
  }
745
745
  /** Decodes the Extended Key Usage SEQUENCE OF OIDs. */
746
746
  function parseExtendedKeyUsage(e) {
747
- let t = l(e, { maxDepth: 64 });
747
+ let t = g(e, { maxDepth: 64 });
748
748
  if (t.length === 0) throw Error("extendedKeyUsage must not be empty");
749
749
  return t.map((e) => {
750
750
  if (e.tag !== 6) throw Error("extendedKeyUsage entry must use OBJECT IDENTIFIER");
751
- return B(m(e.value));
751
+ return B(i(e.value));
752
752
  });
753
753
  }
754
754
  /** Decodes the Certificate Policies extension value. */
755
- function parseCertificatePolicies(e) {
756
- let t = y(c(e, { maxDepth: 64 }), "certificatePolicies sequence"), n = u(e, t);
757
- if (n.length === 0) throw Error("certificatePolicies must not be empty");
758
- return n.map((t) => parsePolicyInformation(e, t));
755
+ function parseCertificatePolicies(t) {
756
+ let n = l(h(t, { maxDepth: 64 }), "certificatePolicies sequence"), r = e(t, n);
757
+ if (r.length === 0) throw Error("certificatePolicies must not be empty");
758
+ return r.map((e) => parsePolicyInformation(t, e));
759
759
  }
760
760
  /** Decode a single PolicyInformation SEQUENCE (OID + optional qualifiers). */
761
- function parsePolicyInformation(e, t) {
762
- let n = u(e, t), r = m(y(n[0], "policyIdentifier").value), i = n[1];
763
- if (n.length > 2) throw Error("policyInformation has unexpected trailing fields");
764
- if (i === void 0) return { policyIdentifier: r };
765
- let a = u(e, i);
766
- if (a.length === 0) throw Error("policyQualifiers must not be empty");
761
+ function parsePolicyInformation(t, n) {
762
+ let r = e(t, n), a = i(l(r[0], "policyIdentifier").value), o = r[1];
763
+ if (r.length > 2) throw Error("policyInformation has unexpected trailing fields");
764
+ if (o === void 0) return { policyIdentifier: a };
765
+ let s = e(t, o);
766
+ if (s.length === 0) throw Error("policyQualifiers must not be empty");
767
767
  return {
768
- policyIdentifier: r,
769
- policyQualifiers: a.map((t) => parsePolicyQualifierInfo(e, t))
768
+ policyIdentifier: a,
769
+ policyQualifiers: s.map((e) => parsePolicyQualifierInfo(t, e))
770
770
  };
771
771
  }
772
772
  /** Decode a PolicyQualifierInfo (CPS URI, UserNotice, or opaque OID). */
773
- function parsePolicyQualifierInfo(e, t) {
774
- let n = u(e, t), r = m(y(n[0], "policyQualifierId").value), i = y(n[1], "policyQualifier");
775
- if (n.length > 2) throw Error("policyQualifierInfo has unexpected trailing fields");
776
- if (r === x.cpsPolicyQualifier) {
777
- if (i.tag !== 22) throw Error("cps policy qualifier must use IA5String");
773
+ function parsePolicyQualifierInfo(t, n) {
774
+ let r = e(t, n), o = i(l(r[0], "policyQualifierId").value), s = l(r[1], "policyQualifier");
775
+ if (r.length > 2) throw Error("policyQualifierInfo has unexpected trailing fields");
776
+ if (o === _.cpsPolicyQualifier) {
777
+ if (s.tag !== 22) throw Error("cps policy qualifier must use IA5String");
778
778
  return {
779
779
  type: "cps",
780
- uri: h(i.tag, i.value)
780
+ uri: a(s.tag, s.value)
781
781
  };
782
782
  }
783
- return r === x.userNoticePolicyQualifier ? {
783
+ return o === _.userNoticePolicyQualifier ? {
784
784
  type: "userNotice",
785
- ...parseUserNoticePolicyQualifierInfo(e, i)
785
+ ...parseUserNoticePolicyQualifierInfo(t, s)
786
786
  } : {
787
787
  type: "oid",
788
- oid: r,
789
- qualifierDer: e.slice(i.start - i.headerLength, i.end)
788
+ oid: o,
789
+ qualifierDer: t.slice(s.start - s.headerLength, s.end)
790
790
  };
791
791
  }
792
792
  /** Decode a UserNotice qualifier (optional noticeRef + optional explicitText). */
793
- function parseUserNoticePolicyQualifierInfo(e, t) {
794
- let n = u(e, t), r, i;
795
- for (let t of n) if (t.tag === 48) {
796
- if (r !== void 0) throw Error("userNotice must not contain multiple noticeRef values");
797
- r = parsePolicyNoticeReference(e, t);
793
+ function parseUserNoticePolicyQualifierInfo(t, n) {
794
+ let r = e(t, n), i, a;
795
+ for (let e of r) if (e.tag === 48) {
796
+ if (i !== void 0) throw Error("userNotice must not contain multiple noticeRef values");
797
+ i = parsePolicyNoticeReference(t, e);
798
798
  } else {
799
- if (i !== void 0) throw Error("userNotice must not contain multiple explicitText values");
800
- i = parseExplicitText(t);
799
+ if (a !== void 0) throw Error("userNotice must not contain multiple explicitText values");
800
+ a = parseExplicitText(e);
801
801
  }
802
802
  return {
803
- ...r === void 0 ? {} : { noticeRef: r },
804
- ...i
803
+ ...i === void 0 ? {} : { noticeRef: i },
804
+ ...a
805
805
  };
806
806
  }
807
807
  function parseExplicitText(e) {
@@ -813,112 +813,112 @@ function parseExplicitText(e) {
813
813
  };
814
814
  }
815
815
  /** Decode a NoticeReference (organization name + notice number list). */
816
- function parsePolicyNoticeReference(e, t) {
817
- if (t.tag !== 48) throw Error("noticeRef must use SEQUENCE");
818
- let n = u(e, t), r = parseDisplayText(y(n[0], "noticeRef organization")), i = y(n[1], "noticeRef noticeNumbers");
819
- if (n.length > 2) throw Error("noticeRef has unexpected trailing fields");
816
+ function parsePolicyNoticeReference(t, n) {
817
+ if (n.tag !== 48) throw Error("noticeRef must use SEQUENCE");
818
+ let r = e(t, n), i = parseDisplayText(l(r[0], "noticeRef organization")), a = l(r[1], "noticeRef noticeNumbers");
819
+ if (r.length > 2) throw Error("noticeRef has unexpected trailing fields");
820
820
  return {
821
- organization: r.text,
822
- noticeNumbers: parsePolicyNoticeNumbers(e, i),
823
- ...r.oversized === void 0 ? {} : { oversizedOrganization: r.oversized }
821
+ organization: i.text,
822
+ noticeNumbers: parsePolicyNoticeNumbers(t, a),
823
+ ...i.oversized === void 0 ? {} : { oversizedOrganization: i.oversized }
824
824
  };
825
825
  }
826
826
  /** Decode a SEQUENCE OF INTEGER notice numbers. */
827
- function parsePolicyNoticeNumbers(e, t) {
828
- if (t.tag !== 48) throw Error("noticeRef noticeNumbers must use SEQUENCE");
829
- let n = u(e, t);
830
- if (n.length === 0) throw Error("noticeRef noticeNumbers must not be empty");
831
- return n.map((e) => {
827
+ function parsePolicyNoticeNumbers(t, n) {
828
+ if (n.tag !== 48) throw Error("noticeRef noticeNumbers must use SEQUENCE");
829
+ let i = e(t, n);
830
+ if (i.length === 0) throw Error("noticeRef noticeNumbers must not be empty");
831
+ return i.map((e) => {
832
832
  if (e.tag !== 2) throw Error("noticeRef noticeNumber must use INTEGER");
833
- return p(e.value, "noticeRef noticeNumber");
833
+ return r(e.value, "noticeRef noticeNumber");
834
834
  });
835
835
  }
836
836
  /** Decodes the Policy Mappings extension value. */
837
- function parsePolicyMappings(e) {
838
- let t = y(c(e, { maxDepth: 64 }), "policyMappings sequence"), n = u(e, t);
839
- if (n.length === 0) throw Error("policyMappings must not be empty");
840
- return n.map((t) => {
841
- let n = u(e, t), r = m(y(n[0], "policyMappings issuerDomainPolicy").value), i = m(y(n[1], "policyMappings subjectDomainPolicy").value);
842
- if (n.length > 2) throw Error("policyMappings entry has unexpected trailing fields");
843
- if (r === x.anyPolicy || i === x.anyPolicy) throw Error("policyMappings must not use anyPolicy");
837
+ function parsePolicyMappings(t) {
838
+ let n = l(h(t, { maxDepth: 64 }), "policyMappings sequence"), r = e(t, n);
839
+ if (r.length === 0) throw Error("policyMappings must not be empty");
840
+ return r.map((n) => {
841
+ let r = e(t, n), a = i(l(r[0], "policyMappings issuerDomainPolicy").value), o = i(l(r[1], "policyMappings subjectDomainPolicy").value);
842
+ if (r.length > 2) throw Error("policyMappings entry has unexpected trailing fields");
843
+ if (a === _.anyPolicy || o === _.anyPolicy) throw Error("policyMappings must not use anyPolicy");
844
844
  return {
845
- issuerDomainPolicy: r,
846
- subjectDomainPolicy: i
845
+ issuerDomainPolicy: a,
846
+ subjectDomainPolicy: o
847
847
  };
848
848
  });
849
849
  }
850
850
  /** Decodes the Policy Constraints extension value. */
851
- function parsePolicyConstraints(e) {
852
- let t = y(c(e, { maxDepth: 64 }), "policyConstraints sequence"), n, r;
853
- for (let i of u(e, t)) if (i.tag === 128) {
854
- if (n !== void 0) throw Error("policyConstraints must not repeat requireExplicitPolicy");
855
- n = p(i.value, "policyConstraints requireExplicitPolicy");
856
- } else if (i.tag === 129) {
857
- if (r !== void 0) throw Error("policyConstraints must not repeat inhibitPolicyMapping");
858
- r = p(i.value, "policyConstraints inhibitPolicyMapping");
859
- } else throw Error(`Unsupported policyConstraints field tag: ${i.tag}`);
860
- if (n === void 0 && r === void 0) throw Error("policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping");
851
+ function parsePolicyConstraints(t) {
852
+ let n = l(h(t, { maxDepth: 64 }), "policyConstraints sequence"), i, a;
853
+ for (let o of e(t, n)) if (o.tag === 128) {
854
+ if (i !== void 0) throw Error("policyConstraints must not repeat requireExplicitPolicy");
855
+ i = r(o.value, "policyConstraints requireExplicitPolicy");
856
+ } else if (o.tag === 129) {
857
+ if (a !== void 0) throw Error("policyConstraints must not repeat inhibitPolicyMapping");
858
+ a = r(o.value, "policyConstraints inhibitPolicyMapping");
859
+ } else throw Error(`Unsupported policyConstraints field tag: ${o.tag}`);
860
+ if (i === void 0 && a === void 0) throw Error("policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping");
861
861
  return {
862
- ...n === void 0 ? {} : { requireExplicitPolicy: n },
863
- ...r === void 0 ? {} : { inhibitPolicyMapping: r }
862
+ ...i === void 0 ? {} : { requireExplicitPolicy: i },
863
+ ...a === void 0 ? {} : { inhibitPolicyMapping: a }
864
864
  };
865
865
  }
866
866
  /** Decodes the Inhibit anyPolicy extension (single INTEGER). */
867
867
  function parseInhibitAnyPolicy(e) {
868
- let t = y(c(e, { maxDepth: 64 }), "inhibitAnyPolicy integer");
868
+ let t = l(h(e, { maxDepth: 64 }), "inhibitAnyPolicy integer");
869
869
  if (t.tag !== 2) throw Error("inhibitAnyPolicy must be an INTEGER");
870
- return { skipCerts: p(t.value, "inhibitAnyPolicy skipCerts") };
870
+ return { skipCerts: r(t.value, "inhibitAnyPolicy skipCerts") };
871
871
  }
872
872
  /** Decodes a subjectAltName or issuerAltName SEQUENCE OF GeneralName. */
873
873
  function parseSubjectAltNames(e, t = "subjectAltName") {
874
- let n = y(c(e, { maxDepth: 64 }), `${t} sequence`);
874
+ let n = l(h(e, { maxDepth: 64 }), `${t} sequence`);
875
875
  if (n.tag !== 48) throw Error(`${t} must use SEQUENCE`);
876
- return I(e, n);
876
+ return D(e, n);
877
877
  }
878
878
  /** Decodes a bare DER-encoded X.501 Name, as carried in a `directoryName` GeneralName. */
879
879
  function parseDistinguishedNameDer(e) {
880
- let t = y(c(e, { maxDepth: 64 }), "distinguished name sequence");
880
+ let t = l(h(e, { maxDepth: 64 }), "distinguished name sequence");
881
881
  if (t.tag !== 48) throw Error("distinguished name must use SEQUENCE");
882
882
  return parseName(e, t);
883
883
  }
884
884
  /** Decodes the Authority Information Access extension value. */
885
- function parseAuthorityInfoAccess(e) {
886
- let t = y(c(e, { maxDepth: 64 }), "authorityInfoAccess sequence");
887
- if (t.tag !== 48) throw Error("authorityInfoAccess must use SEQUENCE");
888
- let n = u(e, t);
889
- if (n.length === 0) throw Error("authorityInfoAccess must not be empty");
890
- return n.map((t) => {
891
- if (t.tag !== 48) throw Error("authorityInfoAccess entry must use SEQUENCE");
892
- let n = u(e, t);
893
- if (n.length !== 2) throw Error("authorityInfoAccess entry must contain method and location only");
894
- let r = y(n[0], "authorityInfoAccess method"), i = y(n[1], "authorityInfoAccess location");
895
- if (r.tag !== 6) throw Error("authorityInfoAccess method must use OBJECT IDENTIFIER");
885
+ function parseAuthorityInfoAccess(t) {
886
+ let n = l(h(t, { maxDepth: 64 }), "authorityInfoAccess sequence");
887
+ if (n.tag !== 48) throw Error("authorityInfoAccess must use SEQUENCE");
888
+ let r = e(t, n);
889
+ if (r.length === 0) throw Error("authorityInfoAccess must not be empty");
890
+ return r.map((n) => {
891
+ if (n.tag !== 48) throw Error("authorityInfoAccess entry must use SEQUENCE");
892
+ let r = e(t, n);
893
+ if (r.length !== 2) throw Error("authorityInfoAccess entry must contain method and location only");
894
+ let a = l(r[0], "authorityInfoAccess method"), o = l(r[1], "authorityInfoAccess location");
895
+ if (a.tag !== 6) throw Error("authorityInfoAccess method must use OBJECT IDENTIFIER");
896
896
  return {
897
- method: z(m(r.value)),
898
- location: F(e, i)
897
+ method: z(i(a.value)),
898
+ location: E(t, o)
899
899
  };
900
900
  });
901
901
  }
902
902
  /** Decodes the CRL Distribution Points extension value. */
903
- function parseCrlDistributionPoints(e) {
904
- let t = y(c(e, { maxDepth: 64 }), "CRLDistributionPoints sequence");
905
- if (t.tag !== 48) throw Error("CRLDistributionPoints must use SEQUENCE");
906
- let n = u(e, t);
907
- if (n.length === 0) throw Error("CRLDistributionPoints must not be empty");
908
- let r = [];
909
- for (let t of n) r.push(parseDistributionPoint(e, t));
910
- return r;
903
+ function parseCrlDistributionPoints(t) {
904
+ let n = l(h(t, { maxDepth: 64 }), "CRLDistributionPoints sequence");
905
+ if (n.tag !== 48) throw Error("CRLDistributionPoints must use SEQUENCE");
906
+ let r = e(t, n);
907
+ if (r.length === 0) throw Error("CRLDistributionPoints must not be empty");
908
+ let i = [];
909
+ for (let e of r) i.push(parseDistributionPoint(t, e));
910
+ return i;
911
911
  }
912
912
  /** Decode a single DistributionPoint SEQUENCE. */
913
- function parseDistributionPoint(e, t) {
914
- if (t.tag !== 48) throw Error("DistributionPoint must use SEQUENCE");
915
- let n = {};
916
- for (let r of u(e, t)) parseDistributionPointField(e, r, n);
917
- if (n.distributionPoint === void 0 && n.crlIssuer === void 0) throw Error("DistributionPoint must include distributionPoint or crlIssuer");
913
+ function parseDistributionPoint(t, n) {
914
+ if (n.tag !== 48) throw Error("DistributionPoint must use SEQUENCE");
915
+ let r = {};
916
+ for (let i of e(t, n)) parseDistributionPointField(t, i, r);
917
+ if (r.distributionPoint === void 0 && r.crlIssuer === void 0) throw Error("DistributionPoint must include distributionPoint or crlIssuer");
918
918
  return {
919
- ...n.distributionPoint === void 0 ? {} : { distributionPoint: n.distributionPoint },
920
- ...n.reasons === void 0 ? {} : { reasons: n.reasons },
921
- ...n.crlIssuer === void 0 ? {} : { crlIssuer: n.crlIssuer }
919
+ ...r.distributionPoint === void 0 ? {} : { distributionPoint: r.distributionPoint },
920
+ ...r.reasons === void 0 ? {} : { reasons: r.reasons },
921
+ ...r.crlIssuer === void 0 ? {} : { crlIssuer: r.crlIssuer }
922
922
  };
923
923
  }
924
924
  function parseDistributionPointField(e, t, n) {
@@ -929,38 +929,38 @@ function parseDistributionPointField(e, t, n) {
929
929
  return;
930
930
  case 129:
931
931
  if (n.reasons !== void 0) throw Error("DistributionPoint reasons must not repeat");
932
- n.reasons = j(t.value);
932
+ n.reasons = x(t.value);
933
933
  return;
934
934
  case 162:
935
935
  if (n.crlIssuer !== void 0) throw Error("DistributionPoint crlIssuer must not repeat");
936
- n.crlIssuer = I(e, t);
936
+ n.crlIssuer = D(e, t);
937
937
  return;
938
938
  default: throw Error(`Unsupported DistributionPoint field tag: ${String(t.tag)}`);
939
939
  }
940
940
  }
941
941
  /** Decode a DistributionPointName (fullName or relativeName). */
942
- function parseDistributionPointName(e, t) {
943
- let n = u(e, t);
944
- if (n.length !== 1) throw Error("distributionPointName must contain exactly one choice");
945
- let r = y(n[0], "distributionPointName");
946
- if (r.tag === 160) {
947
- let t = u(e, r);
948
- if (t.length === 0) throw Error("distributionPointName fullName must not be empty");
949
- for (let e of t) if ((e.tag & 192) != 128) throw Error("distributionPointName fullName must contain GeneralName entries");
942
+ function parseDistributionPointName(t, n) {
943
+ let r = e(t, n);
944
+ if (r.length !== 1) throw Error("distributionPointName must contain exactly one choice");
945
+ let i = l(r[0], "distributionPointName");
946
+ if (i.tag === 160) {
947
+ let n = e(t, i);
948
+ if (n.length === 0) throw Error("distributionPointName fullName must not be empty");
949
+ for (let e of n) if ((e.tag & 192) != 128) throw Error("distributionPointName fullName must contain GeneralName entries");
950
950
  return {
951
951
  type: "fullName",
952
- fullName: t.map((t) => F(e, t))
952
+ fullName: n.map((e) => E(t, e))
953
953
  };
954
954
  }
955
- if (r.tag === 161) return {
955
+ if (i.tag === 161) return {
956
956
  type: "relativeName",
957
- relativeName: parseRelativeDistinguishedName(e, r)
957
+ relativeName: parseRelativeDistinguishedName(t, i)
958
958
  };
959
- throw Error(`Unsupported distributionPointName tag: ${r.tag}`);
959
+ throw Error(`Unsupported distributionPointName tag: ${i.tag}`);
960
960
  }
961
961
  /** Decodes the Name Constraints extension value. */
962
- function parseNameConstraints(e) {
963
- let t = y(c(e, {
962
+ function parseNameConstraints(t) {
963
+ let n = l(h(t, {
964
964
  maxDepth: 64,
965
965
  allowOpaqueConstructedTags: [
966
966
  160,
@@ -968,64 +968,64 @@ function parseNameConstraints(e) {
968
968
  165
969
969
  ]
970
970
  }), "nameConstraints sequence");
971
- if (t.tag !== 48) throw Error("nameConstraints must use SEQUENCE");
972
- let n, r;
973
- for (let i of u(e, t)) if (i.tag === 160) {
974
- if (n !== void 0) throw Error("nameConstraints permittedSubtrees must not repeat");
975
- n = parseGeneralSubtrees(e, i);
976
- } else if (i.tag === 161) {
977
- if (r !== void 0) throw Error("nameConstraints excludedSubtrees must not repeat");
978
- r = parseGeneralSubtrees(e, i);
979
- } else throw Error(`Unsupported nameConstraints field tag: ${String(i.tag)}`);
971
+ if (n.tag !== 48) throw Error("nameConstraints must use SEQUENCE");
972
+ let r, i;
973
+ for (let a of e(t, n)) if (a.tag === 160) {
974
+ if (r !== void 0) throw Error("nameConstraints permittedSubtrees must not repeat");
975
+ r = parseGeneralSubtrees(t, a);
976
+ } else if (a.tag === 161) {
977
+ if (i !== void 0) throw Error("nameConstraints excludedSubtrees must not repeat");
978
+ i = parseGeneralSubtrees(t, a);
979
+ } else throw Error(`Unsupported nameConstraints field tag: ${String(a.tag)}`);
980
980
  return {
981
- ...n === void 0 ? {} : { permittedSubtrees: n },
982
- ...r === void 0 ? {} : { excludedSubtrees: r }
981
+ ...r === void 0 ? {} : { permittedSubtrees: r },
982
+ ...i === void 0 ? {} : { excludedSubtrees: i }
983
983
  };
984
984
  }
985
985
  /** Decode a SEQUENCE OF GeneralSubtree from a permittedSubtrees or excludedSubtrees wrapper. */
986
- function parseGeneralSubtrees(e, t) {
987
- let n = [], r = u(e, t);
988
- if (r.length === 0) throw Error("name constraints GeneralSubtrees must not be empty");
989
- for (let t of r) {
990
- let r = parseGeneralSubtree(e, t);
991
- r !== void 0 && n.push({ base: r });
986
+ function parseGeneralSubtrees(t, n) {
987
+ let r = [], i = e(t, n);
988
+ if (i.length === 0) throw Error("name constraints GeneralSubtrees must not be empty");
989
+ for (let e of i) {
990
+ let n = parseGeneralSubtree(t, e);
991
+ n !== void 0 && r.push({ base: n });
992
992
  }
993
- return n;
993
+ return r;
994
994
  }
995
- function parseGeneralSubtree(e, t) {
996
- if (t.tag !== 48) throw Error("name constraints GeneralSubtree must use SEQUENCE");
997
- let n = u(e, t), r = n[0];
998
- if (r === void 0) throw Error("GeneralSubtree base is required");
999
- return validateGeneralSubtreeBounds(n.slice(1)), parseNameConstraintGeneralName(e, r);
995
+ function parseGeneralSubtree(t, n) {
996
+ if (n.tag !== 48) throw Error("name constraints GeneralSubtree must use SEQUENCE");
997
+ let r = e(t, n), i = r[0];
998
+ if (i === void 0) throw Error("GeneralSubtree base is required");
999
+ return validateGeneralSubtreeBounds(r.slice(1)), parseNameConstraintGeneralName(t, i);
1000
1000
  }
1001
1001
  function validateGeneralSubtreeBounds(e) {
1002
1002
  let t = !1;
1003
1003
  for (let n of e) if (n.tag === 128) {
1004
1004
  if (t) throw Error("name constraints GeneralSubtree minimum must not repeat");
1005
- if (t = !0, p(n.value, "name constraints GeneralSubtree minimum") !== 0) throw Error("name constraints GeneralSubtree minimum must be 0");
1005
+ if (t = !0, r(n.value, "name constraints GeneralSubtree minimum") !== 0) throw Error("name constraints GeneralSubtree minimum must be 0");
1006
1006
  } else throw n.tag === 129 ? Error("name constraints GeneralSubtree maximum is not supported") : Error(`Unsupported name constraints GeneralSubtree field tag: ${String(n.tag)}`);
1007
1007
  }
1008
1008
  /** Decode a GeneralName for use in name constraints (IP carries address+mask). */
1009
1009
  function parseNameConstraintGeneralName(e, t) {
1010
1010
  switch (t.tag) {
1011
1011
  case 160: {
1012
- let { typeId: n, value: r } = L(e, t);
1013
- return n === x.idOnDnsSrv ? {
1012
+ let { typeId: n, value: r } = O(e, t);
1013
+ return n === _.idOnDnsSrv ? {
1014
1014
  type: "srv",
1015
- value: N(r)
1015
+ value: w(r)
1016
1016
  } : {
1017
1017
  type: "otherName",
1018
1018
  typeId: n,
1019
- value: P(e, r)
1019
+ value: T(e, r)
1020
1020
  };
1021
1021
  }
1022
1022
  case 129: return {
1023
1023
  type: "email",
1024
- value: h(22, t.value)
1024
+ value: a(22, t.value)
1025
1025
  };
1026
1026
  case 130: return {
1027
1027
  type: "dns",
1028
- value: h(22, t.value)
1028
+ value: a(22, t.value)
1029
1029
  };
1030
1030
  case 163: return {
1031
1031
  type: "x400Address",
@@ -1033,7 +1033,7 @@ function parseNameConstraintGeneralName(e, t) {
1033
1033
  };
1034
1034
  case 134: return {
1035
1035
  type: "uri",
1036
- value: h(22, t.value)
1036
+ value: a(22, t.value)
1037
1037
  };
1038
1038
  case 135:
1039
1039
  if (t.value.length === 8) return {
@@ -1049,7 +1049,7 @@ function parseNameConstraintGeneralName(e, t) {
1049
1049
  throw Error(`Invalid IP name constraint: expected 8 (IPv4) or 32 (IPv6) bytes, got ${String(t.value.length)}`);
1050
1050
  case 164: return {
1051
1051
  type: "directoryName",
1052
- derHex: b(A(t))
1052
+ derHex: u(b(t))
1053
1053
  };
1054
1054
  case 165: return {
1055
1055
  type: "ediPartyName",
@@ -1057,7 +1057,7 @@ function parseNameConstraintGeneralName(e, t) {
1057
1057
  };
1058
1058
  case 136: return {
1059
1059
  type: "registeredID",
1060
- value: m(t.value)
1060
+ value: i(t.value)
1061
1061
  };
1062
1062
  }
1063
1063
  throw Error(`Unsupported name constraint GeneralName tag: ${String(t.tag)}`);
@@ -1087,14 +1087,14 @@ function decodeDisplayText(e) {
1087
1087
  switch (e.tag) {
1088
1088
  case 12:
1089
1089
  case 22:
1090
- case 30: return h(e.tag, e.value);
1091
- case 26: return g(e.value);
1090
+ case 30: return a(e.tag, e.value);
1091
+ case 26: return o(e.value);
1092
1092
  default: throw Error(`Unsupported DisplayText tag: ${e.tag}`);
1093
1093
  }
1094
1094
  }
1095
1095
  /** Decodes the Authority Key Identifier extension, returning the keyIdentifier hex or undefined. */
1096
1096
  function parseAuthorityKeyIdentifier(e) {
1097
- let t = y(s(e, 0), "authorityKeyIdentifier sequence");
1097
+ let t = l(m(e, 0), "authorityKeyIdentifier sequence");
1098
1098
  if (t.end !== e.length) throw Error("Trailing data after DER element");
1099
1099
  let n = {
1100
1100
  sawAuthorityCertIssuer: !1,
@@ -1102,7 +1102,7 @@ function parseAuthorityKeyIdentifier(e) {
1102
1102
  lastFieldOrder: -1
1103
1103
  }, r = t.start;
1104
1104
  for (; r < t.end;) {
1105
- let i = s(e, r);
1105
+ let i = m(e, r);
1106
1106
  if (i.end > t.end) throw Error("DER child exceeds parent length");
1107
1107
  parseAuthorityKeyIdentifierField(e, i, n), r = i.end;
1108
1108
  }
@@ -1127,18 +1127,18 @@ function parseAuthorityKeyIdentifierField(e, t, n) {
1127
1127
  function parseAuthorityKeyIdentifierKeyId(e, t) {
1128
1128
  if (t.keyIdentifier !== void 0) throw Error("authorityKeyIdentifier keyIdentifier must not repeat");
1129
1129
  if (t.lastFieldOrder >= 0) throw Error("authorityKeyIdentifier fields must preserve DER order");
1130
- t.keyIdentifier = b(e.value), t.lastFieldOrder = 0;
1131
- }
1132
- function parseAuthorityKeyIdentifierIssuer(e, t, n) {
1133
- if (n.sawAuthorityCertIssuer) throw Error("authorityKeyIdentifier authorityCertIssuer must not repeat");
1134
- if (n.lastFieldOrder >= 1) throw Error("authorityKeyIdentifier fields must preserve DER order");
1135
- let r = u(e, t);
1136
- if (r.length === 0) throw Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
1137
- for (let t of r) {
1138
- if ((t.tag & 192) != 128) throw Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
1139
- F(e, t);
1130
+ t.keyIdentifier = u(e.value), t.lastFieldOrder = 0;
1131
+ }
1132
+ function parseAuthorityKeyIdentifierIssuer(t, n, r) {
1133
+ if (r.sawAuthorityCertIssuer) throw Error("authorityKeyIdentifier authorityCertIssuer must not repeat");
1134
+ if (r.lastFieldOrder >= 1) throw Error("authorityKeyIdentifier fields must preserve DER order");
1135
+ let i = e(t, n);
1136
+ if (i.length === 0) throw Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
1137
+ for (let e of i) {
1138
+ if ((e.tag & 192) != 128) throw Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
1139
+ E(t, e);
1140
1140
  }
1141
- n.sawAuthorityCertIssuer = !0, n.lastFieldOrder = 1;
1141
+ r.sawAuthorityCertIssuer = !0, r.lastFieldOrder = 1;
1142
1142
  }
1143
1143
  function parseAuthorityKeyIdentifierSerial(e, t) {
1144
1144
  if (t.sawAuthorityCertSerialNumber) throw Error("authorityKeyIdentifier authorityCertSerialNumber must not repeat");