micro509 0.14.0 → 0.16.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 (164) hide show
  1. package/CHANGELOG.md +2119 -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 +11 -11
  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/spki-distrust.js +23 -0
  73. package/dist/internal/verify/spki-distrust.js.map +1 -0
  74. package/dist/internal/verify/verify-path.d.ts +1 -4
  75. package/dist/internal/verify/verify-path.js +282 -129
  76. package/dist/internal/verify/verify-path.js.map +1 -1
  77. package/dist/internal/x509/directory-name.js +1 -2
  78. package/dist/internal/x509/directory-name.js.map +1 -1
  79. package/dist/internal/x509/extension-bits.js +2 -3
  80. package/dist/internal/x509/extension-bits.js.map +1 -1
  81. package/dist/internal/x509/extension-errors.d.ts +1 -4
  82. package/dist/internal/x509/extension-errors.js +1 -2
  83. package/dist/internal/x509/extension-errors.js.map +1 -1
  84. package/dist/internal/x509/extension-registry.js +107 -89
  85. package/dist/internal/x509/extension-registry.js.map +1 -1
  86. package/dist/internal/x509/general-name-profile.js +129 -0
  87. package/dist/internal/x509/general-name-profile.js.map +1 -0
  88. package/dist/internal/x509/general-name-tags.js +1 -2
  89. package/dist/internal/x509/general-name-tags.js.map +1 -1
  90. package/dist/internal/x509/general-name.js +128 -42
  91. package/dist/internal/x509/general-name.js.map +1 -1
  92. package/dist/internal/x509/name-fields.js +1 -2
  93. package/dist/internal/x509/name-fields.js.map +1 -1
  94. package/dist/internal/x509/or-address.js +217 -0
  95. package/dist/internal/x509/or-address.js.map +1 -0
  96. package/dist/keys/keys.d.ts +122 -104
  97. package/dist/keys/keys.js +211 -204
  98. package/dist/keys/keys.js.map +1 -1
  99. package/dist/keys.d.ts +3 -3
  100. package/dist/pem/pem.d.ts +14 -17
  101. package/dist/pem/pem.js +16 -17
  102. package/dist/pem/pem.js.map +1 -1
  103. package/dist/pem.js +1 -2
  104. package/dist/pkcs/pfx.d.ts +57 -32
  105. package/dist/pkcs/pfx.js +209 -173
  106. package/dist/pkcs/pfx.js.map +1 -1
  107. package/dist/pkcs/pkcs12-mac.d.ts +104 -27
  108. package/dist/pkcs/pkcs12-mac.js +266 -79
  109. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  110. package/dist/pkcs/pkcs7.d.ts +43 -37
  111. package/dist/pkcs/pkcs7.js +218 -217
  112. package/dist/pkcs/pkcs7.js.map +1 -1
  113. package/dist/pkcs.d.ts +4 -3
  114. package/dist/result/result.d.ts +27 -20
  115. package/dist/result/result.js +8 -3
  116. package/dist/result/result.js.map +1 -1
  117. package/dist/result.d.ts +2 -2
  118. package/dist/result.js +1 -2
  119. package/dist/revocation/chain.d.ts +101 -23
  120. package/dist/revocation/chain.js +436 -182
  121. package/dist/revocation/chain.js.map +1 -1
  122. package/dist/revocation/crl.d.ts +131 -67
  123. package/dist/revocation/crl.js +443 -327
  124. package/dist/revocation/crl.js.map +1 -1
  125. package/dist/revocation/ocsp.d.ts +94 -59
  126. package/dist/revocation/ocsp.js +331 -293
  127. package/dist/revocation/ocsp.js.map +1 -1
  128. package/dist/revocation/revocation.d.ts +47 -35
  129. package/dist/revocation/revocation.js +88 -57
  130. package/dist/revocation/revocation.js.map +1 -1
  131. package/dist/revocation.d.ts +3 -3
  132. package/dist/verify/identity.d.ts +16 -19
  133. package/dist/verify/identity.js +118 -89
  134. package/dist/verify/identity.js.map +1 -1
  135. package/dist/verify/name-constraints.d.ts +1 -4
  136. package/dist/verify/policy.d.ts +9 -7
  137. package/dist/verify/verify.d.ts +115 -46
  138. package/dist/verify/verify.js +373 -183
  139. package/dist/verify/verify.js.map +1 -1
  140. package/dist/verify.d.ts +2 -2
  141. package/dist/x509/certificate.d.ts +20 -21
  142. package/dist/x509/certificate.js +62 -46
  143. package/dist/x509/certificate.js.map +1 -1
  144. package/dist/x509/csr.d.ts +5 -7
  145. package/dist/x509/csr.js +10 -11
  146. package/dist/x509/csr.js.map +1 -1
  147. package/dist/x509/extensions.d.ts +154 -66
  148. package/dist/x509/extensions.js +317 -151
  149. package/dist/x509/extensions.js.map +1 -1
  150. package/dist/x509/fingerprint.d.ts +15 -7
  151. package/dist/x509/fingerprint.js +20 -3
  152. package/dist/x509/fingerprint.js.map +1 -1
  153. package/dist/x509/name-text.d.ts +7 -9
  154. package/dist/x509/name-text.js +18 -4
  155. package/dist/x509/name-text.js.map +1 -1
  156. package/dist/x509/name.d.ts +9 -11
  157. package/dist/x509/name.js +18 -19
  158. package/dist/x509/name.js.map +1 -1
  159. package/dist/x509/parse.d.ts +84 -69
  160. package/dist/x509/parse.js +421 -400
  161. package/dist/x509/parse.js.map +1 -1
  162. package/dist/x509.d.ts +3 -3
  163. package/dist/x509.js +3 -3
  164. package/package.json +76 -59
@@ -1,15 +1,20 @@
1
- import { bool as e, concatBytes as t, explicitContext as n, ia5Bytes as r, ia5String as i, implicitConstructedContext as a, implicitPrimitiveContext as o, integerFromNumber as s, objectIdentifier as c, octetString as l, readElement as u, readRootElement as d, readSequenceChildren as f, sequence as p, tlv as m, utf8String as h } from "../internal/asn1/der.js";
2
- import { canonicalizeOid as g, childrenOf as _, decodeObjectIdentifier as v, hexToBytes as y, toHex as b } from "../internal/asn1/asn1.js";
3
- import { OIDS as x } from "../internal/asn1/oids2.js";
4
- import { sha1 as S } from "../internal/crypto/hash.js";
5
- import { isResultError as C } from "../result/result.js";
6
- import { throwExtensionEncoderError as w } from "../internal/x509/extension-errors.js";
7
- import { encodeDistributionPointReasonFlagsContent as T, encodeKeyUsageExtension as E } from "../internal/x509/extension-bits.js";
8
- import { allOnesMaskForIpAddress as D, decodeIpAddress as O, normalizeIpAddress as k, parseIpAddressToBytes as A } from "../internal/shared/ip.js";
9
- import { GENERAL_NAME_WIRE_TAGS as j } from "../internal/x509/general-name-tags.js";
10
- import { encodeRelativeDistinguishedName as M } from "./name.js";
11
- import { AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION as N, AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION as P, BASIC_CONSTRAINTS_EXTENSION_DEFINITION as F, CERTIFICATE_POLICIES_EXTENSION_DEFINITION as I, CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION as L, EXTENDED_KEY_USAGE_EXTENSION_DEFINITION as R, INHIBIT_ANY_POLICY_EXTENSION_DEFINITION as z, KEY_USAGE_EXTENSION_DEFINITION as B, NAME_CONSTRAINTS_EXTENSION_DEFINITION as V, POLICY_CONSTRAINTS_EXTENSION_DEFINITION as H, POLICY_MAPPINGS_EXTENSION_DEFINITION as U, SUBJECT_ALT_NAME_EXTENSION_DEFINITION as W, SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION as G, getExtensionDefinition as K } from "../internal/x509/extension-registry.js";
12
- //#region src/x509/extensions.ts
1
+ import { DECODE_REFUSAL_CODES as e, isResultError as t } from "../result/result.js";
2
+ import { rethrowDecodeRefusal as n } from "../internal/asn1/decode-refusal.js";
3
+ import { bmpString as r, bool as i, concatBytes as a, explicitContext as o, hasLoneSurrogate as s, ia5Bytes as ee, ia5String as te, implicitConstructedContext as c, implicitPrimitiveContext as l, integerFromNumber as u, objectIdentifier as d, octetString as ne, readElement as f, readRootElement as p, readSequenceChildren as m, sequence as h, tlv as g, utf8String as _, visibleString as v } from "../internal/asn1/der.js";
4
+ import { canonicalizeOid as y, checkStrictDer as re, childrenOf as b, decodeObjectIdentifier as ie, hexToBytes as x, toHex as S } from "../internal/asn1/asn1.js";
5
+ import { OIDS as C } from "../internal/asn1/oids2.js";
6
+ import { sha1 as w } from "../internal/crypto/hash.js";
7
+ import { throwExtensionEncoderError as T } from "../internal/x509/extension-errors.js";
8
+ import { encodeDistributionPointReasonFlagsContent as E, encodeKeyUsageExtension as D } from "../internal/x509/extension-bits.js";
9
+ import { domainToAscii as O } from "../internal/shared/idna.js";
10
+ import { allOnesMaskForIpAddress as k, decodeIpAddress as A, normalizeIpAddress as j, parseIpAddressToBytes as M } from "../internal/shared/ip.js";
11
+ import { isMailboxDomain as N, isSmtpUtf8LocalPart as P } from "../internal/shared/mailbox.js";
12
+ import { typedOtherName as F } from "../internal/x509/general-name.js";
13
+ import { checkEdiPartyName as I, checkOrAddress as L, normalizeLabelSeparators as R, parsePresentedSrvName as z, parseSrvNameRestriction as B, parseUriNameConstraint as V } from "../internal/x509/general-name-profile.js";
14
+ import { GENERAL_NAME_WIRE_TAGS as H } from "../internal/x509/general-name-tags.js";
15
+ import { encodeRelativeDistinguishedName as U } from "./name.js";
16
+ import { AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION as W, AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION as G, BASIC_CONSTRAINTS_EXTENSION_DEFINITION as K, CERTIFICATE_POLICIES_EXTENSION_DEFINITION as q, CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION as J, EXTENDED_KEY_USAGE_EXTENSION_DEFINITION as Y, INHIBIT_ANY_POLICY_EXTENSION_DEFINITION as ae, KEY_USAGE_EXTENSION_DEFINITION as X, NAME_CONSTRAINTS_EXTENSION_DEFINITION as oe, NO_REV_AVAIL_EXTENSION_DEFINITION as se, POLICY_CONSTRAINTS_EXTENSION_DEFINITION as ce, POLICY_MAPPINGS_EXTENSION_DEFINITION as le, SUBJECT_ALT_NAME_EXTENSION_DEFINITION as Z, SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION as ue, getExtensionDefinition as Q } from "../internal/x509/extension-registry.js";
17
+ // src/x509/extensions.ts
13
18
  /**
14
19
  * Typed certificate and CSR extension model plus ASN.1 encoder helpers.
15
20
  *
@@ -19,35 +24,35 @@ import { AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION as N, AUTHORITY_KEY_IDENTIFI
19
24
  * @module
20
25
  */
21
26
  /** Map from well-known EKU names to their dotted-decimal OIDs. */
22
- const q = {
23
- serverAuth: x.serverAuth,
24
- clientAuth: x.clientAuth,
25
- codeSigning: x.codeSigning,
26
- emailProtection: x.emailProtection,
27
- timeStamping: x.timeStamping,
28
- ocspSigning: x.ocspSigning
29
- }, J = {
30
- ocsp: x.ocspAccessMethod,
31
- caIssuers: x.caIssuersAccessMethod
27
+ const de = {
28
+ serverAuth: C.serverAuth,
29
+ clientAuth: C.clientAuth,
30
+ codeSigning: C.codeSigning,
31
+ emailProtection: C.emailProtection,
32
+ timeStamping: C.timeStamping,
33
+ ocspSigning: C.ocspSigning
34
+ }, fe = {
35
+ ocsp: C.ocspAccessMethod,
36
+ caIssuers: C.caIssuersAccessMethod
32
37
  };
33
38
  /**
34
39
  * Build the v3 extensions block for a certificate.
35
40
  *
36
- * Automatically adds SKI, AKI (when issuer key is available), and
41
+ * Automatically adds SKI, AKI (when a key identifier is given), and
37
42
  * basicConstraints (defaults to `{ ca: false }`). Additional extensions
38
43
  * come from the caller's {@linkcode CertificateExtensionsInput}.
39
44
  *
40
45
  * @param subjectPublicKeyInfo DER-encoded SPKI of the subject.
41
- * @param issuerPublicKeyInfo DER-encoded SPKI of the issuer, or `undefined` for self-signed.
46
+ * @param authorityKeyIdentifier Key identifier for the AKI, or `undefined` to omit it.
42
47
  * @param input Optional extension configuration.
43
48
  * @param subjectIsEmpty Whether the certificate subject DN is empty. When `true`, a
44
49
  * subjectAltName extension is required and marked critical per RFC 5280 §4.2.1.6.
45
50
  * @returns Array of DER-encoded Extension SEQUENCEs.
46
51
  */
47
52
  function buildCertificateExtensions(e, t, n, r = !1) {
48
- assertCustomExtensionsValid(n, "certificate"), r && assertEmptySubjectHasCriticalSubjectAltName(n), assertPathLengthKeyUsage(n), assertSafeCurveKeyUsage(e, n);
49
- let i = [], a = /* @__PURE__ */ new Set();
50
- return pushKnownExtension(i, a, F, n?.basicConstraints ?? { ca: !1 }), pushKnownExtension(i, a, G, buildSubjectKeyIdentifier(e)), t !== void 0 && pushKnownExtension(i, a, P, buildSubjectKeyIdentifier(t)), appendConfiguredExtensions(i, a, n, {
53
+ assertCustomExtensionsValid(n, "certificate"), r && assertEmptySubjectHasCriticalSubjectAltName(n), assertPathLengthKeyUsage(n), assertSafeCurveKeyUsage(e, n), assertNoRevAvailProfile(n);
54
+ let i = [], a = /* @__PURE__ */ new Set(), o = n?.basicConstraints ?? { ca: !1 };
55
+ return pushKnownExtension(i, a, K, o), pushKnownExtension(i, a, ue, buildSubjectKeyIdentifier(e)), t !== void 0 && pushKnownExtension(i, a, G, t), appendConfiguredExtensions(i, a, n, {
51
56
  includeBasicConstraints: !1,
52
57
  subjectIsEmpty: r
53
58
  }), i;
@@ -77,20 +82,20 @@ function appendConfiguredExtensions(e, t, n, r) {
77
82
  function assertPathLengthKeyUsage(e) {
78
83
  if (resolveEffectiveBasicConstraints(e)?.pathLength === void 0) return;
79
84
  let t = resolveEffectiveKeyUsage(e);
80
- (t === void 0 || t.length === 0 || !t.includes("keyCertSign")) && w("path_length_requires_key_cert_sign", "basicConstraints pathLength requires the keyUsage keyCertSign bit");
85
+ t !== void 0 && t.length !== 0 && t.includes("keyCertSign") || T("path_length_requires_key_cert_sign", "basicConstraints pathLength requires the keyUsage keyCertSign bit");
81
86
  }
82
87
  /** RFC 9295 §3: an end-entity id-Ed25519 or id-Ed448 certificate needs one of these. */
83
- const Y = [
88
+ const $ = [
84
89
  "nonRepudiation",
85
90
  "digitalSignature",
86
91
  "cRLSign"
87
- ], X = [
92
+ ], pe = [
88
93
  "keyEncipherment",
89
94
  "dataEncipherment",
90
95
  "keyAgreement",
91
96
  "encipherOnly",
92
97
  "decipherOnly"
93
- ], Z = [
98
+ ], me = [
94
99
  "digitalSignature",
95
100
  "nonRepudiation",
96
101
  "keyEncipherment",
@@ -120,32 +125,26 @@ function assertSafeCurveKeyUsage(e, t) {
120
125
  let n = resolveEffectiveKeyUsage(t);
121
126
  if (n === void 0 || n.length === 0) return;
122
127
  let r = readSubjectKeyAlgorithmOid(e);
123
- if (r !== void 0) {
124
- if (oidEquals(r, x.x25519) || oidEquals(r, x.x448)) {
125
- assertMontgomeryKeyUsage(n);
126
- return;
127
- }
128
- (oidEquals(r, x.ed25519) || oidEquals(r, x.ed448)) && assertEdwardsKeyUsage(n, resolveEffectiveBasicConstraints(t)?.ca === !0);
129
- }
128
+ r !== void 0 && (oidEquals(r, C.x25519) || oidEquals(r, C.x448) ? assertMontgomeryKeyUsage(n) : (oidEquals(r, C.ed25519) || oidEquals(r, C.ed448)) && assertEdwardsKeyUsage(n, resolveEffectiveBasicConstraints(t)?.ca === !0));
130
129
  }
131
130
  /** The X25519 and X448 half of RFC 9295 §3. */
132
131
  function assertMontgomeryKeyUsage(e) {
133
- e.includes("keyAgreement") || w("montgomery_key_usage_requires_key_agreement", "keyUsage on an X25519 or X448 certificate must set keyAgreement");
134
- let t = Z.filter((t) => e.includes(t));
135
- t.length > 0 && w("montgomery_key_usage_forbids_signature_bit", `keyUsage on an X25519 or X448 certificate must not set ${t.join(", ")}`), e.includes("encipherOnly") && e.includes("decipherOnly") && w("montgomery_key_usage_forbids_both_cipher_bits", "keyUsage on an X25519 or X448 certificate must not set both encipherOnly and decipherOnly");
132
+ e.includes("keyAgreement") || T("montgomery_key_usage_requires_key_agreement", "keyUsage on an X25519 or X448 certificate must set keyAgreement");
133
+ let t = me.filter((t) => e.includes(t));
134
+ t.length > 0 && T("montgomery_key_usage_forbids_signature_bit", `keyUsage on an X25519 or X448 certificate must not set ${t.join(", ")}`), e.includes("encipherOnly") && e.includes("decipherOnly") && T("montgomery_key_usage_forbids_both_cipher_bits", "keyUsage on an X25519 or X448 certificate must not set both encipherOnly and decipherOnly");
136
135
  }
137
136
  /** The Ed25519 and Ed448 half of RFC 9295 §3. */
138
137
  function assertEdwardsKeyUsage(e, t) {
139
- t ? e.includes("keyCertSign") || w("edwards_key_usage_requires_key_cert_sign", "keyUsage on an Ed25519 or Ed448 certification authority certificate must set keyCertSign") : Y.some((t) => e.includes(t)) || w("edwards_key_usage_requires_signing_bit", `keyUsage on an Ed25519 or Ed448 certificate must set one of ${Y.join(", ")}`);
140
- let n = X.filter((t) => e.includes(t));
141
- n.length > 0 && w("edwards_key_usage_forbids_agreement_bit", `keyUsage on an Ed25519 or Ed448 certificate must not set ${n.join(", ")}`), !t && e.includes("keyCertSign") && w("edwards_key_usage_forbids_key_cert_sign", "keyUsage on an Ed25519 or Ed448 end-entity certificate must not set keyCertSign");
138
+ t ? e.includes("keyCertSign") || T("edwards_key_usage_requires_key_cert_sign", "keyUsage on an Ed25519 or Ed448 certification authority certificate must set keyCertSign") : $.some((t) => e.includes(t)) || T("edwards_key_usage_requires_signing_bit", `keyUsage on an Ed25519 or Ed448 certificate must set one of ${$.join(", ")}`);
139
+ let n = pe.filter((t) => e.includes(t));
140
+ n.length > 0 && T("edwards_key_usage_forbids_agreement_bit", `keyUsage on an Ed25519 or Ed448 certificate must not set ${n.join(", ")}`), !t && e.includes("keyCertSign") && T("edwards_key_usage_forbids_key_cert_sign", "keyUsage on an Ed25519 or Ed448 end-entity certificate must not set keyCertSign");
142
141
  }
143
142
  /** The algorithm OID of a SubjectPublicKeyInfo, or `undefined` when the field is not an OID. */
144
143
  function readSubjectKeyAlgorithmOid(e) {
145
- let t = f(e)[0];
144
+ let t = m(e)[0];
146
145
  if (t === void 0 || t.tag !== 48) return;
147
- let n = _(e, t)[0];
148
- return n?.tag === 6 ? v(n.value) : void 0;
146
+ let n = b(e, t)[0];
147
+ return n?.tag === 6 ? ie(n.value) : void 0;
149
148
  }
150
149
  /**
151
150
  * RFC 5280 §4.2.1.9: basicConstraints is critical in a CA certificate whose key
@@ -161,17 +160,35 @@ function readSubjectKeyAlgorithmOid(e) {
161
160
  * always emitted with the registry default.
162
161
  */
163
162
  function assertCaBasicConstraintsCritical(e) {
164
- let t = e?.customExtensions?.find((e) => oidEquals(e.oid, x.basicConstraints));
165
- if (t === void 0 || t.critical === !0 || !F.decode(new Uint8Array(t.value)).ca) return;
163
+ let t = e?.customExtensions?.find((e) => oidEquals(e.oid, C.basicConstraints));
164
+ if (t === void 0 || t.critical === !0 || !K.decode(new Uint8Array(t.value)).ca) return;
166
165
  let n = resolveEffectiveKeyUsage(e);
167
166
  (n === void 0 || n.length === 0 || n.includes("keyCertSign")) && assertExtensionCriticality("basicConstraints", !0, !1);
168
167
  }
169
168
  /**
169
+ * RFC 9608 §2 and §3: a certificate carrying noRevAvail is not a CA certificate
170
+ * and carries no cRLDistributionPoints, no freshestCRL, and no id-ad-ocsp
171
+ * authorityInfoAccess entry. Known extensions supplied through customExtensions
172
+ * participate in the effective view.
173
+ */
174
+ function assertNoRevAvailProfile(e) {
175
+ (e?.noRevAvail === !0 || findCustomExtensionValue(e, C.noRevAvail) !== void 0) && (resolveEffectiveBasicConstraints(e)?.ca === !0 && throwNoRevAvailConflict("basicConstraints with cA TRUE"), ((e?.crlDistributionPoints?.length ?? 0) > 0 || findCustomExtensionValue(e, C.cRLDistributionPoints) !== void 0) && throwNoRevAvailConflict("cRLDistributionPoints"), findCustomExtensionValue(e, C.freshestCRL) !== void 0 && throwNoRevAvailConflict("freshestCRL"), resolveEffectiveAuthorityInfoAccess(e).some((e) => getAuthorityInfoAccessMethodOid(e.method) === C.ocspAccessMethod) && throwNoRevAvailConflict("an id-ad-ocsp authorityInfoAccess entry"));
176
+ }
177
+ /** The authorityInfoAccess entries the builder will emit: the typed list when non-empty, otherwise a custom-known extension. */
178
+ function resolveEffectiveAuthorityInfoAccess(e) {
179
+ if (e?.authorityInfoAccess !== void 0 && e.authorityInfoAccess.length > 0) return e.authorityInfoAccess;
180
+ let t = findCustomExtensionValue(e, C.authorityInfoAccess);
181
+ return t === void 0 ? [] : W.decode(t);
182
+ }
183
+ function throwNoRevAvailConflict(e) {
184
+ T("no_rev_avail_conflict", `A certificate carrying noRevAvail must not also carry ${e}`);
185
+ }
186
+ /**
170
187
  * RFC 5280 §4.2.1.6: an empty subject DN requires a subjectAltName extension
171
188
  * present, marked critical, and carrying at least one non-empty GeneralName.
172
189
  */
173
190
  function assertEmptySubjectHasCriticalSubjectAltName(e) {
174
- e?.subjectAltNames?.some(subjectAltNameHasIdentity) !== !0 && e?.customExtensions?.some((e) => oidEquals(e.oid, x.subjectAltName) && e.critical === !0 && customSubjectAltNameHasIdentity(e.value)) !== !0 && w("empty_subject_requires_subject_alt_name", "An empty subject requires a critical subjectAltName extension");
191
+ e?.subjectAltNames?.some(subjectAltNameHasIdentity) !== !0 && e?.customExtensions?.some((e) => oidEquals(e.oid, C.subjectAltName) && e.critical === !0 && customSubjectAltNameHasIdentity(e.value)) !== !0 && T("empty_subject_requires_subject_alt_name", "An empty subject requires a critical subjectAltName extension");
175
192
  }
176
193
  /**
177
194
  * Canonical OID equality: matches even when arcs carry redundant leading zeros.
@@ -180,7 +197,7 @@ function assertEmptySubjectHasCriticalSubjectAltName(e) {
180
197
  * which rejects an OID that cannot be canonicalized.
181
198
  */
182
199
  function oidEquals(e, t) {
183
- return e === t || g(e) === g(t);
200
+ return e === t || y(e) === y(t);
184
201
  }
185
202
  /** First customExtensions value whose OID canonically matches `oid`. */
186
203
  function findCustomExtensionValue(e, t) {
@@ -195,8 +212,8 @@ function findCustomExtensionValue(e, t) {
195
212
  */
196
213
  function assertCustomExtensionsValid(e, t) {
197
214
  for (let n of e?.customExtensions ?? []) {
198
- let e = K(validateOid(n.oid));
199
- e !== void 0 && (e.contexts.includes(t) || w("extension_not_supported_in_context", `Extension ${n.oid} is not supported in ${t} context`), assertKnownExtensionPayload(e, new Uint8Array(n.value), n.critical ?? !1, n.oid));
215
+ let e = validateOid(n.oid), r = Q(e);
216
+ r !== void 0 && (r.contexts.includes(t) || T("extension_not_supported_in_context", `Extension ${n.oid} is not supported in ${t} context`), assertKnownExtensionPayload(r, new Uint8Array(n.value), n.critical ?? !1, n.oid));
200
217
  }
201
218
  }
202
219
  /**
@@ -206,50 +223,54 @@ function assertCustomExtensionsValid(e, t) {
206
223
  * A profile violation already carries its own code and propagates unchanged; a
207
224
  * decode failure means the payload is not the DER the OID's schema defines.
208
225
  */
209
- function assertKnownExtensionPayload(e, t, n, r) {
226
+ function assertKnownExtensionPayload(e, n, r, i) {
210
227
  try {
211
- e.assertDerProfile(t, n);
212
- } catch (t) {
213
- if (C(t)) throw t;
214
- w("malformed_known_extension_value", `Custom extension ${r} does not decode as ${e.oid}`);
228
+ e.assertDerProfile(n, r);
229
+ } catch (n) {
230
+ if (t(n)) throw n;
231
+ T("malformed_known_extension_value", `Custom extension ${i} does not decode as ${e.oid}`);
215
232
  }
216
233
  }
217
234
  /** Effective basicConstraints across the typed field and any custom-known extension. */
218
235
  function resolveEffectiveBasicConstraints(e) {
219
236
  if (e?.basicConstraints !== void 0) return e.basicConstraints;
220
- let t = findCustomExtensionValue(e, x.basicConstraints);
221
- return t === void 0 ? void 0 : F.decode(t);
237
+ let t = findCustomExtensionValue(e, C.basicConstraints);
238
+ return t === void 0 ? void 0 : K.decode(t);
222
239
  }
223
240
  /** Effective keyUsage flags across the typed field and any custom-known extension. */
224
241
  function resolveEffectiveKeyUsage(e) {
225
242
  if (e?.keyUsage !== void 0) return e.keyUsage;
226
- let t = findCustomExtensionValue(e, x.keyUsage);
227
- return t === void 0 ? void 0 : B.decode(t).flags;
243
+ let t = findCustomExtensionValue(e, C.keyUsage);
244
+ return t === void 0 ? void 0 : X.decode(t).flags;
228
245
  }
229
246
  /** Whether a typed GeneralName carries a non-empty identity value. */
230
247
  function subjectAltNameHasIdentity(e) {
231
- return e.type === "directoryName" ? e.derHex.length > 0 : e.value.length > 0;
248
+ switch (e.type) {
249
+ case "directoryName": return e.derHex.length > 0;
250
+ case "krb5PrincipalName": return e.realm.length > 0 || e.nameString.length > 0;
251
+ default: return e.value.length > 0;
252
+ }
232
253
  }
233
254
  /** Whether a custom subjectAltName value decodes to at least one non-empty GeneralName. */
234
255
  function customSubjectAltNameHasIdentity(e) {
235
- return W.decode(e).some(subjectAltNameHasIdentity);
256
+ return Z.decode(e).some(subjectAltNameHasIdentity);
236
257
  }
237
258
  function appendConstraintExtensions(e, t, n, r) {
238
- assertPathLengthKeyUsage(n), assertCaBasicConstraintsCritical(n), r && n.basicConstraints !== void 0 && pushKnownExtension(e, t, F, n.basicConstraints), n.keyUsage !== void 0 && n.keyUsage.length > 0 && pushKnownExtension(e, t, B, n.keyUsage), n.nameConstraints !== void 0 && pushKnownExtension(e, t, V, n.nameConstraints);
259
+ assertPathLengthKeyUsage(n), assertCaBasicConstraintsCritical(n), r && n.basicConstraints !== void 0 && pushKnownExtension(e, t, K, n.basicConstraints), n.keyUsage !== void 0 && n.keyUsage.length > 0 && pushKnownExtension(e, t, X, n.keyUsage), n.nameConstraints !== void 0 && pushKnownExtension(e, t, oe, n.nameConstraints);
239
260
  }
240
261
  function appendIdentityExtensions(e, t, n, r) {
241
262
  if (n.subjectAltNames !== void 0 && n.subjectAltNames.length > 0) {
242
263
  let i = r ? !0 : void 0;
243
- pushKnownExtension(e, t, W, n.subjectAltNames, i);
264
+ pushKnownExtension(e, t, Z, n.subjectAltNames, i);
244
265
  }
245
- n.extendedKeyUsage !== void 0 && n.extendedKeyUsage.length > 0 && pushKnownExtension(e, t, R, n.extendedKeyUsage);
266
+ n.extendedKeyUsage !== void 0 && n.extendedKeyUsage.length > 0 && pushKnownExtension(e, t, Y, n.extendedKeyUsage);
246
267
  }
247
268
  /** Appends configured certificate-policy extensions while enforcing unique OIDs. */
248
269
  function appendPolicyExtensions(e, t, n) {
249
- n.certificatePolicies !== void 0 && n.certificatePolicies.length > 0 && pushKnownExtension(e, t, I, n.certificatePolicies), n.policyMappings !== void 0 && n.policyMappings.length > 0 && pushKnownExtension(e, t, U, n.policyMappings), n.policyConstraints !== void 0 && pushKnownExtension(e, t, H, n.policyConstraints), n.inhibitAnyPolicy !== void 0 && pushKnownExtension(e, t, z, n.inhibitAnyPolicy);
270
+ n.certificatePolicies !== void 0 && n.certificatePolicies.length > 0 && pushKnownExtension(e, t, q, n.certificatePolicies), n.policyMappings !== void 0 && n.policyMappings.length > 0 && pushKnownExtension(e, t, le, n.policyMappings), n.policyConstraints !== void 0 && pushKnownExtension(e, t, ce, n.policyConstraints), n.inhibitAnyPolicy !== void 0 && pushKnownExtension(e, t, ae, n.inhibitAnyPolicy);
250
271
  }
251
272
  function appendAccessExtensions(e, t, n) {
252
- n.authorityInfoAccess !== void 0 && n.authorityInfoAccess.length > 0 && pushKnownExtension(e, t, N, n.authorityInfoAccess), n.crlDistributionPoints !== void 0 && n.crlDistributionPoints.length > 0 && pushKnownExtension(e, t, L, n.crlDistributionPoints);
273
+ n.authorityInfoAccess !== void 0 && n.authorityInfoAccess.length > 0 && pushKnownExtension(e, t, W, n.authorityInfoAccess), n.crlDistributionPoints !== void 0 && n.crlDistributionPoints.length > 0 && pushKnownExtension(e, t, J, n.crlDistributionPoints), n.noRevAvail === !0 && pushKnownExtension(e, t, se, !0);
253
274
  }
254
275
  /** Push each custom extension. Context and payload were checked by `assertCustomExtensionsValid`. */
255
276
  function appendCustomExtensions(e, t, n) {
@@ -266,10 +287,10 @@ function pushKnownExtension(e, t, n, r, i = n.defaultCritical) {
266
287
  * @param extnValue DER-encoded extension payload.
267
288
  * @param critical Whether to mark the extension as critical. Default `false`.
268
289
  */
269
- function encodeExtension(t, n, r = !1) {
270
- validateOid(t);
271
- let i = [c(t)];
272
- return r && i.push(e(!0)), i.push(l(n)), p(i);
290
+ function encodeExtension(e, t, n = !1) {
291
+ validateOid(e);
292
+ let r = [d(e)];
293
+ return n && r.push(i(!0)), r.push(ne(t)), h(r);
273
294
  }
274
295
  /**
275
296
  * DER-encode a {@linkcode BasicConstraints} value.
@@ -277,9 +298,9 @@ function encodeExtension(t, n, r = !1) {
277
298
  * @param input CA flag and optional pathLength.
278
299
  * @returns DER SEQUENCE suitable for wrapping in an Extension OCTET STRING.
279
300
  */
280
- function encodeBasicConstraints(t) {
281
- let n = [];
282
- return t.ca && n.push(e(!0)), t.pathLength !== void 0 && (t.ca || w("path_length_requires_ca", "basicConstraints pathLength requires ca = true"), n.push(s(t.pathLength))), p(n);
301
+ function encodeBasicConstraints(e) {
302
+ let t = [];
303
+ return e.ca && t.push(i(!0)), e.pathLength !== void 0 && (e.ca || T("path_length_requires_ca", "basicConstraints pathLength requires ca = true"), t.push(u(e.pathLength))), h(t);
283
304
  }
284
305
  /**
285
306
  * DER-encode a Key Usage BIT STRING from an array of {@linkcode KeyUsage} flags.
@@ -287,18 +308,106 @@ function encodeBasicConstraints(t) {
287
308
  * @param usages Flags to set in the bit string.
288
309
  */
289
310
  function encodeKeyUsage(e) {
290
- return E(e);
311
+ return D(e);
291
312
  }
292
313
  function encodeIa5Content(e) {
293
314
  try {
294
- return r(e);
315
+ return ee(e);
295
316
  } catch {
296
- w("invalid_ia5_string", "Invalid IA5String: contains non-ASCII characters");
317
+ T("invalid_ia5_string", "Invalid IA5String: contains non-ASCII characters");
297
318
  }
298
319
  }
299
320
  /** RFC 5280 §4.2.1.6: reject an empty GeneralName string value (empty dNSName, rfc822Name, URI, or SRV name). */
300
321
  function requireNonEmptyName(e) {
301
- return e.length === 0 && w("empty_general_name_value", "GeneralName value must not be empty"), e;
322
+ return e.length === 0 && T("empty_general_name_value", "GeneralName value must not be empty"), e;
323
+ }
324
+ /**
325
+ * RFC 9598 §3: a SmtpUTF8Mailbox carries no Byte Order Mark, is used only when
326
+ * the Local-part holds a non-ASCII character, and stores its domain as
327
+ * lowercase A-labels and NR-LDH labels.
328
+ */
329
+ function assertSmtpUtf8Mailbox(e) {
330
+ let t = requireNonEmptyName(e).lastIndexOf("@"), n = t > 0 ? e.slice(0, t) : "", r = toAsciiDomain(e.slice(t + 1));
331
+ return (n.length === 0 || e.includes("") || !N(r, "registration")) && T("invalid_smtp_utf8_mailbox", "SmtpUTF8Mailbox must be Local-part@Domain with no Byte Order Mark and a domain of lowercase A-labels and NR-LDH labels"), [...n].some((e) => (e.codePointAt(0) ?? 0) > 127) || T("smtp_utf8_mailbox_ascii_local_part", "A mailbox with an ASCII Local-part must use rfc822Name (type email)"), P(n) || T("invalid_smtp_utf8_mailbox", "SmtpUTF8Mailbox Local-part must be an RFC 6531 Dot-string or Quoted-string"), `${n}@${r}`;
332
+ }
333
+ /**
334
+ * @internal A decoded SAN or IAN entry of a custom extension, which is emitted
335
+ * as given: the typed builder's rules, with a SmtpUTF8Mailbox domain already
336
+ * stored in A-labels.
337
+ */
338
+ function assertStoredSubjectAltName(e) {
339
+ encodeSubjectAltName(e), e.type === "smtpUtf8Mailbox" && assertSmtpUtf8Mailbox(e.value) !== e.value && T("invalid_smtp_utf8_mailbox", "SmtpUTF8Mailbox domain must be stored as lowercase A-labels and NR-LDH labels");
340
+ }
341
+ /** RFC 5891 §4: the domain with each U-label converted to its A-label and each A-label checked. */
342
+ function toAsciiDomain(e) {
343
+ let t = O(e, "registration");
344
+ return t.ok ? t.value : T("invalid_idn", `Domain name is not valid IDNA2008 (${t.reason})`);
345
+ }
346
+ /** RFC 5280 §4.2.1.6 dNSName and rfc822Name domains take the RFC 1034 §3.5 preferred name syntax, which has no trailing root dot. */
347
+ function requireRelativeDomain(e) {
348
+ return e.endsWith(".") && T("domain_trailing_dot", "A dNSName or rfc822Name domain must not end in \".\" (RFC 5280 §4.2.1.6)"), e;
349
+ }
350
+ /** A dNSName or dNSName constraint with its leading `*.` or `.` kept and its domain in A-labels. */
351
+ function toAsciiDnsName(e) {
352
+ let t = e.startsWith("*.") ? "*." : e.startsWith(".") ? "." : "";
353
+ return `${t}${toAsciiDomain(requireRelativeDomain(e.slice(t.length)))}`;
354
+ }
355
+ /**
356
+ * RFC 4985 §3: a SRVName or SRVName restriction with its label separators
357
+ * normalized, its `_Service` label kept, and its Name in A-labels.
358
+ */
359
+ function toAsciiSrvComponents(e) {
360
+ let t = R(e), n = t.indexOf(".");
361
+ if (!t.startsWith("_")) return toAsciiDomain(t);
362
+ if (n < 0) return t;
363
+ let r = t.slice(n + 1);
364
+ return `${t.slice(0, n + 1)}${r.length === 0 ? "" : toAsciiDomain(r)}`;
365
+ }
366
+ /** RFC 4985 §2 and RFC 6335 §5.1: a presented SRVName is `_Service.Name`. */
367
+ function toAsciiSrvName(e) {
368
+ let t = toAsciiSrvComponents(e);
369
+ return z(t) === void 0 && T("invalid_srv_name", "A SRVName is _Service.Name with an RFC 6335 service and an LDH Name (RFC 4985 §2)"), t;
370
+ }
371
+ /** RFC 4985 §4: a SRVName constraint is `_Service.Name`, `_Service`, or `Name`. */
372
+ function toAsciiSrvNameConstraint(e) {
373
+ let t = toAsciiSrvComponents(e);
374
+ return B(t) === void 0 && T("invalid_srv_name_constraint", "A SRVName constraint is _Service.Name, _Service, or Name (RFC 4985 §4)"), t;
375
+ }
376
+ /** RFC 4120 §5.2.1 KerberosString content: IA5String characters in a GeneralString, without code-extension controls. */
377
+ function kerberosString(e, t) {
378
+ let outside = (e) => e > 127 || e === 14 || e === 15 || e === 27;
379
+ return [...e].some((e) => outside(e.codePointAt(0) ?? 0)) && T("invalid_krb5_principal_name", `KRB5PrincipalName ${t} must hold IA5String characters other than SO, SI and ESC (RFC 4120 §5.2.1)`), g(27, new TextEncoder().encode(e));
380
+ }
381
+ /** RFC 4120 §5.2.4 Int32 as a DER-minimal two's-complement INTEGER. */
382
+ function int32(e) {
383
+ (!Number.isInteger(e) || e < -2147483648 || e > 2147483647) && T("invalid_krb5_principal_name", "KRB5PrincipalName nameType must be an Int32 (RFC 4120 §5.2.4)");
384
+ let t = [], n = e;
385
+ do
386
+ t.unshift(n & 255), n >>= 8;
387
+ while (!(n === 0 && (t[0] ?? 0) < 128) && !(n === -1 && (t[0] ?? 0) >= 128));
388
+ return g(2, Uint8Array.from(t));
389
+ }
390
+ /** RFC 4556 §3.2.2 KRB5PrincipalName in the EXPLICIT tagging of RFC 4120's module. */
391
+ function encodeKrb5PrincipalName(e) {
392
+ return e.realm.includes("\0") && T("invalid_krb5_principal_name", "KRB5PrincipalName realm must not contain NUL (RFC 4120 §5.2.2)"), h([o(0, kerberosString(e.realm, "realm")), o(1, h([o(0, int32(e.nameType)), o(1, h(e.nameString.map((e) => kerberosString(e, "nameString"))))]))]);
393
+ }
394
+ /** An otherName type-id that has no dedicated {@linkcode SubjectAltName} variant. */
395
+ function validateOtherNameTypeId(e) {
396
+ let t = validateOid(e);
397
+ return (t === C.idOnDnsSrv || t === C.idOnSmtpUtf8Mailbox) && T("other_name_type_id_has_variant", `otherName type-id ${t} is encoded through its dedicated SubjectAltName variant`), t;
398
+ }
399
+ function requireGeneralNameContent(e, t, n) {
400
+ let r = n(e);
401
+ return r.ok || T("invalid_general_name_content", r.reason === "unsupported" ? `${t} contents use an encoding micro509 cannot validate` : `${t} contents do not match the ${t === "x400Address" ? "ORAddress" : "EDIPartyName"} ASN.1 (RFC 5280)`), e;
402
+ }
403
+ function requireSingleDerElement(e) {
404
+ let t = re(e);
405
+ return t !== "valid" && T("invalid_other_name_value", t === "unsupported" ? "otherName value uses an encoding micro509 cannot validate" : "otherName value must be exactly one DER element"), e;
406
+ }
407
+ /** RFC 9549 §2.5: an rfc822Name or rfc822Name constraint with its host in A-labels. */
408
+ function toAsciiMailbox(e) {
409
+ let t = e.lastIndexOf("@");
410
+ return t < 0 ? toAsciiDnsName(e) : `${e.slice(0, t + 1)}${toAsciiDomain(requireRelativeDomain(e.slice(t + 1)))}`;
302
411
  }
303
412
  /**
304
413
  * DER-encode a single {@linkcode SubjectAltName} GeneralName element.
@@ -307,13 +416,23 @@ function requireNonEmptyName(e) {
307
416
  */
308
417
  function encodeSubjectAltName(e) {
309
418
  switch (e.type) {
310
- case "dns": return o(2, encodeIa5Content(requireNonEmptyName(e.value)));
311
- case "email": return o(1, encodeIa5Content(requireNonEmptyName(e.value)));
312
- case "uri": return o(6, encodeIa5Content(requireNonEmptyName(e.value)));
313
- case "srv": return a(0, t([c(x.idOnDnsSrv), n(0, m(22, encodeIa5Content(requireNonEmptyName(e.value))))]));
314
- case "ip": return o(7, encodeIpAddress(e.value));
315
- case "directoryName": return a(4, readDirectoryNameTlv(e.derHex));
316
- case "unknown": return j.has(e.tag) || w("invalid_general_name_tag", `Invalid GeneralName tag: ${e.tag}`), m(e.tag, e.value);
419
+ case "dns": return l(2, encodeIa5Content(toAsciiDnsName(requireNonEmptyName(e.value))));
420
+ case "email": return l(1, encodeIa5Content(toAsciiMailbox(requireNonEmptyName(e.value))));
421
+ case "uri": return l(6, encodeIa5Content(requireNonEmptyName(e.value)));
422
+ case "srv": return c(0, a([d(C.idOnDnsSrv), o(0, g(22, encodeIa5Content(toAsciiSrvName(requireNonEmptyName(e.value)))))]));
423
+ case "smtpUtf8Mailbox": return c(0, a([d(C.idOnSmtpUtf8Mailbox), o(0, _(assertSmtpUtf8Mailbox(e.value)))]));
424
+ case "upn": return c(0, a([d(C.ntPrincipalName), o(0, _(requireNonEmptyName(e.value)))]));
425
+ case "krb5PrincipalName": return c(0, a([d(C.idPkinitSan), o(0, encodeKrb5PrincipalName(e))]));
426
+ case "ip": return l(7, encodeIpAddress(e.value));
427
+ case "directoryName": return c(4, readDirectoryNameTlv(e.derHex));
428
+ case "otherName": {
429
+ let t = validateOtherNameTypeId(e.typeId), n = requireSingleDerElement(e.value);
430
+ return F(t, n, p(n)) !== void 0 && T("other_name_type_id_has_variant", `otherName type-id ${t} with this value is encoded through its dedicated SubjectAltName variant`), c(0, a([d(t), o(0, n)]));
431
+ }
432
+ case "x400Address": return requireGeneralNameContent(c(3, e.value), "x400Address", L);
433
+ case "ediPartyName": return requireGeneralNameContent(c(5, e.value), "ediPartyName", I);
434
+ case "registeredID": return l(8, p(d(validateOid(e.value))).value);
435
+ case "unknown": return H.has(e.tag) || T("invalid_general_name_tag", `Invalid GeneralName tag: ${e.tag}`), g(e.tag, e.value);
317
436
  default: throw Error(`Unhandled SubjectAltName type: ${String(e)}`);
318
437
  }
319
438
  }
@@ -323,7 +442,7 @@ function encodeSubjectAltName(e) {
323
442
  * @param usages EKU purposes to encode.
324
443
  */
325
444
  function encodeExtendedKeyUsage(e) {
326
- return e.length === 0 && w("extended_key_usage_empty", "extendedKeyUsage must not be empty"), p(e.map((e) => c(getExtendedKeyUsageOid(e))));
445
+ return e.length === 0 && T("extended_key_usage_empty", "extendedKeyUsage must not be empty"), h(e.map((e) => d(getExtendedKeyUsageOid(e))));
327
446
  }
328
447
  /**
329
448
  * DER-encode an Authority Information Access SEQUENCE.
@@ -331,7 +450,7 @@ function encodeExtendedKeyUsage(e) {
331
450
  * @param entries AIA entries (OCSP, caIssuers, or custom) to encode.
332
451
  */
333
452
  function encodeAuthorityInfoAccess(e) {
334
- return assertAuthorityInfoAccessProfile(e), p(e.map((e) => p([c(getAuthorityInfoAccessMethodOid(e.method)), encodeSubjectAltName(e.location)])));
453
+ return assertAuthorityInfoAccessProfile(e), h(e.map((e) => h([d(getAuthorityInfoAccessMethodOid(e.method)), encodeSubjectAltName(e.location)])));
335
454
  }
336
455
  /**
337
456
  * @internal RFC 5280 §4.2.2.1 and RFC 6960 §3.1 rules for Authority Information
@@ -341,8 +460,8 @@ function encodeAuthorityInfoAccess(e) {
341
460
  * smuggle a non-URI OCSP location past the input union.
342
461
  */
343
462
  function assertAuthorityInfoAccessProfile(e) {
344
- e.length === 0 && w("authority_info_access_empty", "authorityInfoAccess must not be empty");
345
- for (let t of e) getAuthorityInfoAccessMethodOid(t.method) === x.ocspAccessMethod && t.location.type !== "uri" && w("authority_info_access_ocsp_not_uri", "authorityInfoAccess OCSP location must be a URI");
463
+ e.length === 0 && T("authority_info_access_empty", "authorityInfoAccess must not be empty");
464
+ for (let t of e) getAuthorityInfoAccessMethodOid(t.method) === C.ocspAccessMethod && t.location.type !== "uri" && T("authority_info_access_ocsp_not_uri", "authorityInfoAccess OCSP location must be a URI");
346
465
  }
347
466
  /**
348
467
  * DER-encode a CRL Distribution Points SEQUENCE.
@@ -350,7 +469,7 @@ function assertAuthorityInfoAccessProfile(e) {
350
469
  * @param points Distribution points to encode.
351
470
  */
352
471
  function encodeCrlDistributionPoints(e) {
353
- return assertCrlDistributionPointsProfile(e), p(e.map((e) => p(encodeDistributionPoint(e))));
472
+ return assertCrlDistributionPointsProfile(e), h(e.map((e) => h(encodeDistributionPoint(e))));
354
473
  }
355
474
  /**
356
475
  * @internal RFC 5280 §4.2.1.13 profile rules for a CRLDistributionPoints value,
@@ -361,12 +480,12 @@ function encodeCrlDistributionPoints(e) {
361
480
  * a decoded point carries the parsed one. The rules only read its presence.
362
481
  */
363
482
  function assertCrlDistributionPointsProfile(e) {
364
- e.length === 0 && w("crl_distribution_points_empty", "cRLDistributionPoints must not be empty");
483
+ e.length === 0 && T("crl_distribution_points_empty", "cRLDistributionPoints must not be empty");
365
484
  for (let t of e) assertDistributionPointProfile(t);
366
485
  }
367
486
  /** RFC 5280 §4.2.1.13 rules for one distribution point. */
368
487
  function assertDistributionPointProfile(e) {
369
- e.crlIssuer !== void 0 && e.crlIssuer.length === 0 && w("distribution_point_crl_issuer_empty", "DistributionPoint crlIssuer must not be empty"), e.distributionPoint === void 0 && e.crlIssuer === void 0 && w("distribution_point_empty", "DistributionPoint must contain distributionPoint or crlIssuer"), assertCrlIssuerDistinguishedNames(e), e.distributionPoint?.type === "fullName" && e.distributionPoint.fullName.length === 0 && w("distribution_point_full_name_empty", "DistributionPointName fullName must not be empty");
488
+ e.crlIssuer !== void 0 && e.crlIssuer.length === 0 && T("distribution_point_crl_issuer_empty", "DistributionPoint crlIssuer must not be empty"), e.distributionPoint === void 0 && e.crlIssuer === void 0 && T("distribution_point_empty", "DistributionPoint must contain distributionPoint or crlIssuer"), assertCrlIssuerDistinguishedNames(e), e.distributionPoint?.type === "fullName" && e.distributionPoint.fullName.length === 0 && T("distribution_point_full_name_empty", "DistributionPointName fullName must not be empty");
370
489
  }
371
490
  /**
372
491
  * DER-encode a Name Constraints extension value.
@@ -375,8 +494,8 @@ function assertDistributionPointProfile(e) {
375
494
  */
376
495
  function encodeNameConstraints(e) {
377
496
  assertNameConstraintsProfile(e);
378
- let n = [];
379
- return e.permittedSubtrees !== void 0 && e.permittedSubtrees.length > 0 && n.push(a(0, t(e.permittedSubtrees.map(encodeGeneralSubtree)))), e.excludedSubtrees !== void 0 && e.excludedSubtrees.length > 0 && n.push(a(1, t(e.excludedSubtrees.map(encodeGeneralSubtree)))), p(n);
497
+ let t = [];
498
+ return e.permittedSubtrees !== void 0 && e.permittedSubtrees.length > 0 && t.push(c(0, a(e.permittedSubtrees.map(encodeGeneralSubtree)))), e.excludedSubtrees !== void 0 && e.excludedSubtrees.length > 0 && t.push(c(1, a(e.excludedSubtrees.map(encodeGeneralSubtree)))), h(t);
380
499
  }
381
500
  /**
382
501
  * @internal RFC 5280 fixes the criticality of several extensions: nameConstraints
@@ -389,7 +508,7 @@ function encodeNameConstraints(e) {
389
508
  * @param critical The criticality the caller asked for.
390
509
  */
391
510
  function assertExtensionCriticality(e, t, n) {
392
- n !== t && w(t ? "extension_must_be_critical" : "extension_must_be_non_critical", `The ${e} extension must be marked ${t ? "critical" : "non-critical"}`);
511
+ n !== t && T(t ? "extension_must_be_critical" : "extension_must_be_non_critical", `The ${e} extension must be marked ${t ? "critical" : "non-critical"}`);
393
512
  }
394
513
  /**
395
514
  * @internal RFC 5280 §4.2.1.10: a nameConstraints extension states at least one
@@ -397,7 +516,7 @@ function assertExtensionCriticality(e, t, n) {
397
516
  */
398
517
  function assertNameConstraintsProfile(e) {
399
518
  let t = e.permittedSubtrees?.length ?? 0, n = e.excludedSubtrees?.length ?? 0;
400
- t === 0 && n === 0 && w("name_constraints_empty", "nameConstraints must set permittedSubtrees or excludedSubtrees");
519
+ t === 0 && n === 0 && T("name_constraints_empty", "nameConstraints must set permittedSubtrees or excludedSubtrees");
401
520
  }
402
521
  /**
403
522
  * DER-encode a Certificate Policies extension value.
@@ -405,13 +524,13 @@ function assertNameConstraintsProfile(e) {
405
524
  * @param policies Non-empty array of policy information entries.
406
525
  */
407
526
  function encodeCertificatePolicies(e) {
408
- e.length === 0 && w("certificate_policies_empty", "certificatePolicies must not be empty");
527
+ e.length === 0 && T("certificate_policies_empty", "certificatePolicies must not be empty");
409
528
  let t = /* @__PURE__ */ new Set();
410
529
  for (let n of e) {
411
530
  let e = validatePolicyOid(n.policyIdentifier);
412
- t.has(e) && w("duplicate_policy_oid", `Duplicate certificate policy OID: ${n.policyIdentifier}`), t.add(e);
531
+ t.has(e) && T("duplicate_policy_oid", `Duplicate certificate policy OID: ${n.policyIdentifier}`), t.add(e);
413
532
  }
414
- return p(e.map(encodePolicyInformation));
533
+ return h(e.map(encodePolicyInformation));
415
534
  }
416
535
  /**
417
536
  * DER-encode a Policy Mappings extension value.
@@ -419,9 +538,9 @@ function encodeCertificatePolicies(e) {
419
538
  * @param mappings Non-empty array of issuer-to-subject policy pairs. Neither OID may be anyPolicy.
420
539
  */
421
540
  function encodePolicyMappings(e) {
422
- return e.length === 0 && w("policy_mappings_empty", "policyMappings must not be empty"), p(e.map((e) => {
541
+ return e.length === 0 && T("policy_mappings_empty", "policyMappings must not be empty"), h(e.map((e) => {
423
542
  let t = validatePolicyOid(e.issuerDomainPolicy), n = validatePolicyOid(e.subjectDomainPolicy);
424
- return (t === x.anyPolicy || n === x.anyPolicy) && w("policy_mappings_any_policy", "policyMappings must not use anyPolicy"), p([c(e.issuerDomainPolicy), c(e.subjectDomainPolicy)]);
543
+ return (t === C.anyPolicy || n === C.anyPolicy) && T("policy_mappings_any_policy", "policyMappings must not use anyPolicy"), h([d(e.issuerDomainPolicy), d(e.subjectDomainPolicy)]);
425
544
  }));
426
545
  }
427
546
  /**
@@ -431,7 +550,7 @@ function encodePolicyMappings(e) {
431
550
  */
432
551
  function encodePolicyConstraints(e) {
433
552
  let t = [];
434
- return e.requireExplicitPolicy !== void 0 && t.push(o(0, encodeIntegerContent(e.requireExplicitPolicy))), e.inhibitPolicyMapping !== void 0 && t.push(o(1, encodeIntegerContent(e.inhibitPolicyMapping))), t.length === 0 && w("policy_constraints_empty", "policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping"), p(t);
553
+ return e.requireExplicitPolicy !== void 0 && t.push(l(0, encodeIntegerContent(e.requireExplicitPolicy))), e.inhibitPolicyMapping !== void 0 && t.push(l(1, encodeIntegerContent(e.inhibitPolicyMapping))), t.length === 0 && T("policy_constraints_empty", "policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping"), h(t);
435
554
  }
436
555
  /**
437
556
  * DER-encode an Inhibit anyPolicy extension value (single INTEGER).
@@ -439,47 +558,84 @@ function encodePolicyConstraints(e) {
439
558
  * @param input The skipCerts threshold.
440
559
  */
441
560
  function encodeInhibitAnyPolicy(e) {
442
- return s(e.skipCerts);
561
+ return u(e.skipCerts);
443
562
  }
444
563
  /** DER-encode a single PolicyInformation SEQUENCE. */
445
564
  function encodePolicyInformation(e) {
446
565
  validatePolicyOid(e.policyIdentifier);
447
- let t = [c(e.policyIdentifier)];
448
- return e.policyQualifiers !== void 0 && e.policyQualifiers.length > 0 && t.push(p(e.policyQualifiers.map(encodePolicyQualifierInfo))), p(t);
566
+ let t = [d(e.policyIdentifier)];
567
+ return e.policyQualifiers !== void 0 && e.policyQualifiers.length > 0 && t.push(h(e.policyQualifiers.map(encodePolicyQualifierInfo))), h(t);
449
568
  }
450
569
  /** DER-encode a single PolicyQualifierInfo SEQUENCE. */
451
570
  function encodePolicyQualifierInfo(e) {
452
571
  switch (e.type) {
453
- case "cps": return p([c(x.cpsPolicyQualifier), i(e.uri)]);
454
- case "userNotice": return p([c(x.userNoticePolicyQualifier), encodeUserNoticePolicyQualifierInfo(e)]);
572
+ case "cps": return h([d(C.cpsPolicyQualifier), te(e.uri)]);
573
+ case "userNotice": return h([d(C.userNoticePolicyQualifier), encodeUserNoticePolicyQualifierInfo(e)]);
455
574
  case "oid": {
456
575
  validateOid(e.oid);
457
- let t = c(e.oid), n = b(t);
458
- return (n === b(c(x.cpsPolicyQualifier)) || n === b(c(x.userNoticePolicyQualifier))) && w("reserved_policy_qualifier_oid", "Policy qualifier must use the typed cps or userNotice variant, not a built-in OID"), p([t, new Uint8Array(e.qualifierDer)]);
576
+ let t = d(e.oid), n = S(t);
577
+ return (n === S(d(C.cpsPolicyQualifier)) || n === S(d(C.userNoticePolicyQualifier))) && T("reserved_policy_qualifier_oid", "Policy qualifier must use the typed cps or userNotice variant, not a built-in OID"), h([t, new Uint8Array(e.qualifierDer)]);
459
578
  }
460
579
  default: throw Error(`Unhandled PolicyQualifierInfo type: ${String(e)}`);
461
580
  }
462
581
  }
463
582
  /** DER-encode a UserNotice qualifier SEQUENCE. */
464
583
  function assertDisplayText(e) {
584
+ s(e) && T("display_text_lone_surrogate", "DisplayText must not hold a lone UTF-16 surrogate");
465
585
  let t = [...e].length;
466
- (t === 0 || t > 200) && w("display_text_out_of_range", "DisplayText must be 1 to 200 characters");
586
+ (t === 0 || t > 200) && T("display_text_out_of_range", "DisplayText must be 1 to 200 characters");
467
587
  }
468
588
  function encodeUserNoticePolicyQualifierInfo(e) {
469
589
  let t = [];
470
- return e.noticeRef !== void 0 && t.push(encodePolicyNoticeReference(e.noticeRef)), e.explicitText !== void 0 && (assertDisplayText(e.explicitText), t.push(h(e.explicitText))), p(t);
590
+ return e.noticeRef !== void 0 && t.push(encodePolicyNoticeReference(e.noticeRef)), e.explicitText !== void 0 && (assertDisplayText(e.explicitText), t.push(encodeExplicitText(e.explicitText, e.explicitTextType))), h(t);
591
+ }
592
+ /**
593
+ * RFC 6818 §3, replacing the explicitText paragraph of RFC 5280 §4.2.1.4:
594
+ * UTF8String is preferred, VisibleString and BMPString are acceptable,
595
+ * IA5String is forbidden, control characters should not appear, and UTF8String
596
+ * and BMPString text should be in Unicode normalization form C.
597
+ */
598
+ function encodeExplicitText(e, t = "utf8String") {
599
+ switch ([...e].some(isControlCharacter) && T("display_text_control_character", "explicitText must not contain control characters"), t) {
600
+ case "utf8String": return assertNormalizationFormC(e), _(e);
601
+ case "bmpString": return assertNormalizationFormC(e), encodeBmpDisplayText(e);
602
+ case "visibleString": return encodeVisibleDisplayText(e);
603
+ case "ia5String": return T("display_text_ia5_string", "explicitText must not be encoded as IA5String");
604
+ default: throw Error(`Unhandled DisplayText type: ${String(t)}`);
605
+ }
606
+ }
607
+ function isControlCharacter(e) {
608
+ let t = e.codePointAt(0) ?? 0;
609
+ return t <= 31 || t >= 127 && t <= 159;
610
+ }
611
+ function assertNormalizationFormC(e) {
612
+ e.normalize("NFC") !== e && T("display_text_not_nfc", "explicitText must be in Unicode normalization form C");
613
+ }
614
+ function encodeVisibleDisplayText(e) {
615
+ try {
616
+ return v(e);
617
+ } catch {
618
+ return T("invalid_visible_string", "VisibleString explicitText must be printable ASCII");
619
+ }
620
+ }
621
+ function encodeBmpDisplayText(e) {
622
+ try {
623
+ return r(e);
624
+ } catch {
625
+ return T("invalid_bmp_string", "BMPString explicitText must hold Basic Multilingual Plane characters other than surrogates, U+FFFE and U+FFFF");
626
+ }
471
627
  }
472
628
  /** DER-encode a NoticeReference SEQUENCE. */
473
629
  function encodePolicyNoticeReference(e) {
474
- return assertDisplayText(e.organization), p([h(e.organization), p(e.noticeNumbers.map((e) => s(e)))]);
630
+ return assertDisplayText(e.organization), h([_(e.organization), h(e.noticeNumbers.map((e) => u(e)))]);
475
631
  }
476
632
  /** Encode an INTEGER and return only the content bytes (no TLV wrapper). */
477
633
  function encodeIntegerContent(e) {
478
- return u(s(e)).value;
634
+ return f(u(e)).value;
479
635
  }
480
636
  /** DER-encode a GeneralSubtree SEQUENCE (base name only; min/max omitted per RFC 5280). */
481
637
  function encodeGeneralSubtree(e) {
482
- return p([encodeNameConstraintForm(e.base)]);
638
+ return h([encodeNameConstraintForm(e.base)]);
483
639
  }
484
640
  /**
485
641
  * RFC 5280 §4.2.1.13: cRLIssuer, when present, only contains the CRL issuer's
@@ -490,20 +646,20 @@ function encodeGeneralSubtree(e) {
490
646
  * arrives through `crlDistributionPoints` or through `customExtensions`.
491
647
  */
492
648
  function assertCrlIssuerDistinguishedNames(e) {
493
- e.crlIssuer !== void 0 && (e.crlIssuer.some((e) => e.type !== "directoryName") && w("distribution_point_crl_issuer_not_directory_name", "DistributionPoint cRLIssuer must only contain directoryName entries"), e.distributionPoint?.type === "relativeName" && e.crlIssuer.length > 1 && w("distribution_point_relative_name_multiple_crl_issuers", "DistributionPointName relativeName requires at most one cRLIssuer distinguished name"));
649
+ e.crlIssuer !== void 0 && (e.crlIssuer.some((e) => e.type !== "directoryName") && T("distribution_point_crl_issuer_not_directory_name", "DistributionPoint cRLIssuer must only contain directoryName entries"), e.distributionPoint?.type === "relativeName" && e.crlIssuer.length > 1 && T("distribution_point_relative_name_multiple_crl_issuers", "DistributionPointName relativeName requires at most one cRLIssuer distinguished name"));
494
650
  }
495
651
  /** DER-encode the fields of a single DistributionPoint, already profile-checked. */
496
652
  function encodeDistributionPoint(e) {
497
- let n = [];
498
- return e.distributionPoint !== void 0 && n.push(a(0, encodeDistributionPointName(e.distributionPoint))), e.reasons !== void 0 && e.reasons.length > 0 && n.push(o(1, T(e.reasons))), e.crlIssuer !== void 0 && n.push(a(2, t(e.crlIssuer.map(encodeSubjectAltName)))), n;
653
+ let t = [];
654
+ return e.distributionPoint !== void 0 && t.push(c(0, encodeDistributionPointName(e.distributionPoint))), e.reasons !== void 0 && e.reasons.length > 0 && t.push(l(1, E(e.reasons))), e.crlIssuer !== void 0 && t.push(c(2, a(e.crlIssuer.map(encodeSubjectAltName)))), t;
499
655
  }
500
656
  /** DER-encode a DistributionPointName (fullName or relativeName). */
501
657
  function encodeDistributionPointName(e) {
502
658
  switch (e.type) {
503
- case "fullName": return e.fullName.length === 0 && w("distribution_point_full_name_empty", "DistributionPointName fullName must not be empty"), a(0, t(e.fullName.map(encodeSubjectAltName)));
659
+ case "fullName": return e.fullName.length === 0 && T("distribution_point_full_name_empty", "DistributionPointName fullName must not be empty"), c(0, a(e.fullName.map(encodeSubjectAltName)));
504
660
  case "relativeName": {
505
- let t = M(e.relativeName), n = u(t);
506
- return a(1, t.slice(n.start, n.end));
661
+ let t = U(e.relativeName), n = f(t);
662
+ return c(1, t.slice(n.start, n.end));
507
663
  }
508
664
  default: throw Error(`Unhandled DistributionPointName type: ${String(e)}`);
509
665
  }
@@ -511,21 +667,22 @@ function encodeDistributionPointName(e) {
511
667
  /** DER-encode a NameConstraintForm as an implicit-tagged {@linkcode GeneralName}. */
512
668
  function encodeNameConstraintForm(e) {
513
669
  switch (e.type) {
514
- case "dns": return o(2, r(e.value));
515
- case "email": return o(1, r(e.value));
516
- case "uri": return o(6, r(e.value));
670
+ case "dns": return l(2, encodeIa5Content(toAsciiDnsName(e.value)));
671
+ case "email": return e.value.includes("@") && T("email_name_constraint_names_mailbox", "An rfc822Name constraint names a host or a domain, not a particular mailbox (RFC 9549 §2.2)"), l(1, encodeIa5Content(toAsciiMailbox(e.value)));
672
+ case "uri": return V(e.value) === void 0 && T("invalid_uri_name_constraint", "A uniformResourceIdentifier constraint is a fully qualified domain name, with a leading period for its subdomains (RFC 5280 §4.2.1.10)"), l(6, encodeIa5Content(e.value));
517
673
  case "ip": {
518
- let n = e.addressBytes.length + e.maskBytes.length;
519
- return (e.addressBytes.length !== e.maskBytes.length || n !== 8 && n !== 32) && w("invalid_ip_name_constraint", "IP name constraint must be 8 octets (IPv4) or 32 octets (IPv6)"), o(7, t([e.addressBytes, e.maskBytes]));
674
+ let t = e.addressBytes.length + e.maskBytes.length;
675
+ return (e.addressBytes.length !== e.maskBytes.length || t !== 8 && t !== 32) && T("invalid_ip_name_constraint", "IP name constraint must be 8 octets (IPv4) or 32 octets (IPv6)"), l(7, a([e.addressBytes, e.maskBytes]));
520
676
  }
521
- case "directoryName": return a(4, readDirectoryNameTlv(e.derHex));
677
+ case "directoryName": return c(4, readDirectoryNameTlv(e.derHex));
678
+ case "srv": return c(0, a([d(C.idOnDnsSrv), o(0, g(22, encodeIa5Content(toAsciiSrvNameConstraint(e.value))))]));
522
679
  default: throw Error(`Unhandled NameConstraintForm type: ${String(e)}`);
523
680
  }
524
681
  }
525
682
  /** Returns the complete Name TLV from a hex-encoded DER SEQUENCE, validating the root tag. */
526
683
  function readDirectoryNameTlv(e) {
527
- let t = y(e), n = d(t, { maxDepth: 64 });
528
- return n.tag !== 48 && w("directory_name_not_sequence", "directoryName derHex must encode a DER SEQUENCE"), t.slice(n.start - n.headerLength, n.end);
684
+ let t = x(e), n = p(t, { maxDepth: 64 });
685
+ return n.tag !== 48 && T("directory_name_not_sequence", "directoryName derHex must encode a DER SEQUENCE"), t.slice(n.start - n.headerLength, n.end);
529
686
  }
530
687
  /**
531
688
  * Resolve an {@linkcode ExtendedKeyUsage} to its dotted-decimal OID.
@@ -533,7 +690,7 @@ function readDirectoryNameTlv(e) {
533
690
  * @param usage Well-known string or custom OID object.
534
691
  */
535
692
  function getExtendedKeyUsageOid(e) {
536
- return typeof e == "string" ? q[e] : validateOid(e.value);
693
+ return typeof e == "string" ? de[e] : validateOid(e.value);
537
694
  }
538
695
  /**
539
696
  * Map a dotted-decimal OID to an {@linkcode ExtendedKeyUsage} value.
@@ -542,12 +699,12 @@ function getExtendedKeyUsageOid(e) {
542
699
  */
543
700
  function parseExtendedKeyUsageOid(e) {
544
701
  switch (e) {
545
- case x.serverAuth: return "serverAuth";
546
- case x.clientAuth: return "clientAuth";
547
- case x.codeSigning: return "codeSigning";
548
- case x.emailProtection: return "emailProtection";
549
- case x.timeStamping: return "timeStamping";
550
- case x.ocspSigning: return "ocspSigning";
702
+ case C.serverAuth: return "serverAuth";
703
+ case C.clientAuth: return "clientAuth";
704
+ case C.codeSigning: return "codeSigning";
705
+ case C.emailProtection: return "emailProtection";
706
+ case C.timeStamping: return "timeStamping";
707
+ case C.ocspSigning: return "ocspSigning";
551
708
  }
552
709
  return {
553
710
  type: "oid",
@@ -560,7 +717,7 @@ function parseExtendedKeyUsageOid(e) {
560
717
  * @param method Well-known string or custom OID object.
561
718
  */
562
719
  function getAuthorityInfoAccessMethodOid(e) {
563
- return typeof e == "string" ? J[e] : validateOid(e.value);
720
+ return typeof e == "string" ? fe[e] : validateOid(e.value);
564
721
  }
565
722
  /**
566
723
  * Map a dotted-decimal OID to an {@linkcode AuthorityInfoAccessMethod} value.
@@ -569,8 +726,8 @@ function getAuthorityInfoAccessMethodOid(e) {
569
726
  */
570
727
  function parseAuthorityInfoAccessMethodOid(e) {
571
728
  switch (e) {
572
- case x.ocspAccessMethod: return "ocsp";
573
- case x.caIssuersAccessMethod: return "caIssuers";
729
+ case C.ocspAccessMethod: return "ocsp";
730
+ case C.caIssuersAccessMethod: return "caIssuers";
574
731
  }
575
732
  return {
576
733
  type: "oid",
@@ -579,7 +736,7 @@ function parseAuthorityInfoAccessMethodOid(e) {
579
736
  }
580
737
  /** Parse a dotted-decimal/colon-hex IP string to raw address bytes. */
581
738
  function encodeIpAddress(e) {
582
- return A(e);
739
+ return M(e);
583
740
  }
584
741
  /**
585
742
  * Computes a key identifier from a DER `SubjectPublicKeyInfo` using method (1)
@@ -588,9 +745,19 @@ function encodeIpAddress(e) {
588
745
  * A parsed certificate carries the input as `subjectPublicKeyInfoDer`.
589
746
  */
590
747
  function buildSubjectKeyIdentifier(e) {
591
- let t = f(e)[1];
748
+ let t = m(e)[1];
592
749
  if (t === void 0 || t.tag !== 3) throw Error("SPKI missing subject public key bit string");
593
- return S(t.value.slice(1));
750
+ let n = t.value.slice(1);
751
+ return w(n);
752
+ }
753
+ /**
754
+ * The key identifier a certificate or CRL issued by `issuer` carries in its
755
+ * authority key identifier: the issuer's subject key identifier (RFC 5280
756
+ * §4.2.1.2, §5.2.1), or a method (1) identifier over its public key when it
757
+ * has none (§4.2.1.1).
758
+ */
759
+ function issuerKeyIdentifier(e) {
760
+ return e.subjectKeyIdentifier === void 0 ? buildSubjectKeyIdentifier(e.subjectPublicKeyInfoDer) : x(e.subjectKeyIdentifier);
594
761
  }
595
762
  /**
596
763
  * Throw if the string is not an encodable dotted-decimal OID, and return its
@@ -600,12 +767,12 @@ function buildSubjectKeyIdentifier(e) {
600
767
  * second to under 40 beneath arcs 0 and 1, so `3.1` and `1.40` parse as decimals
601
768
  * yet cannot be encoded.
602
769
  */
603
- function validateOid(e) {
604
- /^\d+(?:\.\d+)+$/.test(e) || w("invalid_oid", `Invalid OID: ${e}`);
770
+ function validateOid(t) {
771
+ /^\d+(?:\.\d+)+$/.test(t) || T("invalid_oid", `Invalid OID: ${t}`);
605
772
  try {
606
- return g(e);
607
- } catch {
608
- w("invalid_oid", `Invalid OID: ${e}`);
773
+ return y(t);
774
+ } catch (r) {
775
+ n(r, e), T("invalid_oid", `Invalid OID: ${t}`);
609
776
  }
610
777
  }
611
778
  /** Validate a policy OID and return its canonical spelling. */
@@ -621,9 +788,8 @@ function validatePolicyOid(e) {
621
788
  */
622
789
  function pushExtension(e, t, n, r, i = !1) {
623
790
  let a = validateOid(n);
624
- t.has(a) && w("duplicate_extension_oid", `Duplicate extension OID: ${n}`), t.add(a), e.push(encodeExtension(n, r, i));
791
+ t.has(a) && T("duplicate_extension_oid", `Duplicate extension OID: ${n}`), t.add(a), e.push(encodeExtension(n, r, i));
625
792
  }
626
- //#endregion
627
- export { D as allOnesMaskForIpAddress, assertAuthorityInfoAccessProfile, assertCrlDistributionPointsProfile, assertExtensionCriticality, assertNameConstraintsProfile, buildCertificateExtensions, buildRequestedExtensions, buildSubjectKeyIdentifier, O as decodeIpAddress, encodeAuthorityInfoAccess, encodeBasicConstraints, encodeCertificatePolicies, encodeCrlDistributionPoints, encodeExtendedKeyUsage, encodeExtension, encodeInhibitAnyPolicy, encodeKeyUsage, encodeNameConstraints, encodePolicyConstraints, encodePolicyMappings, encodeSubjectAltName, getAuthorityInfoAccessMethodOid, getExtendedKeyUsageOid, k as normalizeIpAddress, parseAuthorityInfoAccessMethodOid, parseExtendedKeyUsageOid, A as parseIpAddressToBytes };
793
+ export { k as allOnesMaskForIpAddress, assertAuthorityInfoAccessProfile, assertCrlDistributionPointsProfile, assertExtensionCriticality, assertNameConstraintsProfile, assertStoredSubjectAltName, buildCertificateExtensions, buildRequestedExtensions, buildSubjectKeyIdentifier, A as decodeIpAddress, encodeAuthorityInfoAccess, encodeBasicConstraints, encodeCertificatePolicies, encodeCrlDistributionPoints, encodeExtendedKeyUsage, encodeExtension, encodeInhibitAnyPolicy, encodeKeyUsage, encodeNameConstraints, encodePolicyConstraints, encodePolicyMappings, encodeSubjectAltName, getAuthorityInfoAccessMethodOid, getExtendedKeyUsageOid, issuerKeyIdentifier, j as normalizeIpAddress, parseAuthorityInfoAccessMethodOid, parseExtendedKeyUsageOid, M as parseIpAddressToBytes };
628
794
 
629
795
  //# sourceMappingURL=extensions.js.map