micro509 0.14.0 → 0.15.0

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