micro509 0.18.0 → 0.19.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 (99) hide show
  1. package/CHANGELOG.md +88 -1
  2. package/dist/crypto/crypto.d.ts +11 -2
  3. package/dist/crypto/crypto.js +30 -17
  4. package/dist/crypto/crypto.js.map +1 -1
  5. package/dist/crypto.d.ts +2 -2
  6. package/dist/der/der.js.map +1 -1
  7. package/dist/index.d.ts +6 -5
  8. package/dist/internal/asn1/asn1.js +10 -2
  9. package/dist/internal/asn1/asn1.js.map +1 -1
  10. package/dist/internal/asn1/ber.js.map +1 -1
  11. package/dist/internal/asn1/decode-refusal.js.map +1 -1
  12. package/dist/internal/asn1/der.js.map +1 -1
  13. package/dist/internal/asn1/oids.js.map +1 -1
  14. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  15. package/dist/internal/crypto/ecdsa.js.map +1 -1
  16. package/dist/internal/crypto/hash.js.map +1 -1
  17. package/dist/internal/crypto/pbes2.js.map +1 -1
  18. package/dist/internal/crypto/prime-ec.js.map +1 -1
  19. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  20. package/dist/internal/crypto/sig-verify.d.ts +40 -0
  21. package/dist/internal/crypto/sig-verify.js +152 -65
  22. package/dist/internal/crypto/sig-verify.js.map +1 -1
  23. package/dist/internal/crypto/signing.js.map +1 -1
  24. package/dist/internal/jose/base64url.js.map +1 -1
  25. package/dist/internal/jose/json-data.js.map +1 -1
  26. package/dist/internal/jose/strict-json.js.map +1 -1
  27. package/dist/internal/shared/base64.js.map +1 -1
  28. package/dist/internal/shared/dn.js.map +1 -1
  29. package/dist/internal/shared/idna.js.map +1 -1
  30. package/dist/internal/shared/ip.js.map +1 -1
  31. package/dist/internal/shared/mailbox.js.map +1 -1
  32. package/dist/internal/shared/punycode.js.map +1 -1
  33. package/dist/internal/shared/uri-host.js.map +1 -1
  34. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  35. package/dist/internal/verify/policy-engine.js.map +1 -1
  36. package/dist/internal/verify/spki-distrust.js.map +1 -1
  37. package/dist/internal/verify/verify-path.js +222 -116
  38. package/dist/internal/verify/verify-path.js.map +1 -1
  39. package/dist/internal/x509/directory-name.js.map +1 -1
  40. package/dist/internal/x509/extension-bits.js.map +1 -1
  41. package/dist/internal/x509/extension-errors.js.map +1 -1
  42. package/dist/internal/x509/extension-registry.js.map +1 -1
  43. package/dist/internal/x509/general-name-profile.js.map +1 -1
  44. package/dist/internal/x509/general-name.js.map +1 -1
  45. package/dist/internal/x509/name-fields.js.map +1 -1
  46. package/dist/internal/x509/or-address.js.map +1 -1
  47. package/dist/jose/base64url.js.map +1 -1
  48. package/dist/jose/errors.js.map +1 -1
  49. package/dist/jose/jwe.js.map +1 -1
  50. package/dist/jose/jwks.js.map +1 -1
  51. package/dist/jose/jws.js.map +1 -1
  52. package/dist/jose/jwt.js.map +1 -1
  53. package/dist/jose/remote-jwks.js.map +1 -1
  54. package/dist/kdf/argon2-arithmetic.js.map +1 -1
  55. package/dist/kdf/argon2-core.js.map +1 -1
  56. package/dist/kdf/argon2-memory.js.map +1 -1
  57. package/dist/kdf/argon2-portable.js.map +1 -1
  58. package/dist/kdf/argon2.js.map +1 -1
  59. package/dist/keys/keys.js.map +1 -1
  60. package/dist/pem/pem.js.map +1 -1
  61. package/dist/pkcs/pfx.js.map +1 -1
  62. package/dist/pkcs/pkcs12-mac.js +1 -1
  63. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  64. package/dist/pkcs/pkcs7.d.ts +10 -0
  65. package/dist/pkcs/pkcs7.js +106 -88
  66. package/dist/pkcs/pkcs7.js.map +1 -1
  67. package/dist/result/result.js.map +1 -1
  68. package/dist/revocation/chain.d.ts +67 -13
  69. package/dist/revocation/chain.js +429 -301
  70. package/dist/revocation/chain.js.map +1 -1
  71. package/dist/revocation/crl.d.ts +65 -11
  72. package/dist/revocation/crl.js +492 -202
  73. package/dist/revocation/crl.js.map +1 -1
  74. package/dist/revocation/ocsp.d.ts +79 -24
  75. package/dist/revocation/ocsp.js +417 -231
  76. package/dist/revocation/ocsp.js.map +1 -1
  77. package/dist/revocation/revocation.d.ts +68 -13
  78. package/dist/revocation/revocation.js +194 -73
  79. package/dist/revocation/revocation.js.map +1 -1
  80. package/dist/revocation.d.ts +4 -4
  81. package/dist/ssh/ssh.js.map +1 -1
  82. package/dist/ssh/wire.js.map +1 -1
  83. package/dist/verify/identity.d.ts +2 -2
  84. package/dist/verify/identity.js +2 -2
  85. package/dist/verify/identity.js.map +1 -1
  86. package/dist/verify/verify.d.ts +84 -32
  87. package/dist/verify/verify.js +221 -171
  88. package/dist/verify/verify.js.map +1 -1
  89. package/dist/verify.d.ts +3 -2
  90. package/dist/x509/certificate.js.map +1 -1
  91. package/dist/x509/csr.js.map +1 -1
  92. package/dist/x509/extensions.js.map +1 -1
  93. package/dist/x509/fingerprint.js.map +1 -1
  94. package/dist/x509/name-text.js.map +1 -1
  95. package/dist/x509/name.js.map +1 -1
  96. package/dist/x509/parse.d.ts +6 -2
  97. package/dist/x509/parse.js +121 -121
  98. package/dist/x509/parse.js.map +1 -1
  99. package/package.json +11 -11
@@ -1 +1 @@
1
- {"version":3,"file":"extensions.js","names":["_exhaustive","EXTENDED_KEY_USAGE_OIDS","OIDS","AUTHORITY_INFO_ACCESS_METHOD_OIDS","input","subjectIsEmpty","subjectPublicKeyInfo","extensions","seen","basicConstraints","BASIC_CONSTRAINTS_EXTENSION_DEFINITION","SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION","authorityKeyIdentifier","AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION","encoded","options","keyUsage","throwExtensionEncoderError","EDWARDS_END_ENTITY_KEY_USAGE","EDWARDS_FORBIDDEN_KEY_USAGE","MONTGOMERY_FORBIDDEN_KEY_USAGE","algorithm","asserted","flag","isCertificationAuthority","readSequenceChildren","oid","childrenOf","decodeObjectIdentifier","custom","extension","entry","AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION","conflict","candidate","known","canonicalizeOid","definition","getExtensionDefinition","context","value","critical","error","isResultError","submittedOid","KEY_USAGE_EXTENSION_DEFINITION","name","SUBJECT_ALT_NAME_EXTENSION_DEFINITION","includeBasicConstraints","NAME_CONSTRAINTS_EXTENSION_DEFINITION","sanCritical","EXTENDED_KEY_USAGE_EXTENSION_DEFINITION","CERTIFICATE_POLICIES_EXTENSION_DEFINITION","POLICY_MAPPINGS_EXTENSION_DEFINITION","POLICY_CONSTRAINTS_EXTENSION_DEFINITION","INHIBIT_ANY_POLICY_EXTENSION_DEFINITION","CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION","NO_REV_AVAIL_EXTENSION_DEFINITION","fields","objectIdentifier","bool","octetString","extnValue","sequence","integerFromNumber","encodeKeyUsageExtension","usages","ia5Bytes","at","localPart","domain","isMailboxDomain","character","isSmtpUtf8LocalPart","converted","domainToAscii","prefix","normalized","normalizeLabelSeparators","dot","ascii","parsePresentedSrvName","parseSrvNameRestriction","unit","field","tlv","octets","rest","explicitContext","component","typeId","result","check","element","form","verdict","checkStrictDer","implicitPrimitiveContext","implicitConstructedContext","concatBytes","utf8String","typedOtherName","readRootElement","checkOrAddress","checkEdiPartyName","GENERAL_NAME_WIRE_TAGS","usage","entries","points","point","constraints","parts","required","label","permitted","excluded","policies","policy","key","mappings","issuerDomainPolicy","mapping","subjectDomainPolicy","qualifier","ia5String","encodedOid","canonicalOid","toHex","hasLoneSurrogate","length","text","type","codePoint","visibleString","bmpString","reference","noticeNumber","readElement","subtree","encodeDistributionPointReasonFlagsContent","relativeName","encodeRelativeDistinguishedName","relativeNameElement","parseUriNameConstraint","total","bytes","hexToBytes","derHex","method","parseIpAddressToBytes","subjectPublicKey","publicKeyBytes","sha1","issuer","rethrowDecodeRefusal","DECODE_REFUSAL_CODES","identity","allOnesMaskForIpAddress","decodeIpAddress","normalizeIpAddress"],"sources":["../../src/x509/extensions.ts"],"sourcesContent":["/**\n * Typed certificate and CSR extension model plus ASN.1 encoder helpers.\n *\n * Defines input types for every supported X.509v3 extension (RFC 5280) and\n * the DER encoders consumed by certificate and CSR builder flows.\n *\n * @module\n */\n\nimport {\n\tcanonicalizeOid,\n\tcheckStrictDer,\n\tchildrenOf,\n\tdecodeObjectIdentifier,\n\thexToBytes,\n\ttoHex,\n} from '#micro509/internal/asn1/asn1';\nimport { DECODE_REFUSAL_CODES, rethrowDecodeRefusal } from '#micro509/internal/asn1/decode-refusal';\nimport {\n\tbmpString,\n\tbool,\n\tconcatBytes,\n\tDEFAULT_MAX_DER_DEPTH,\n\texplicitContext,\n\thasLoneSurrogate,\n\tia5Bytes,\n\tia5String,\n\timplicitConstructedContext,\n\timplicitPrimitiveContext,\n\tintegerFromNumber,\n\tobjectIdentifier,\n\toctetString,\n\treadElement,\n\treadRootElement,\n\treadSequenceChildren,\n\tsequence,\n\ttlv,\n\tutf8String,\n\tvisibleString,\n} from '#micro509/internal/asn1/der';\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport { sha1 } from '#micro509/internal/crypto/hash';\nimport { domainToAscii } from '#micro509/internal/shared/idna';\nimport { parseIpAddressToBytes } from '#micro509/internal/shared/ip';\nimport { isMailboxDomain, isSmtpUtf8LocalPart } from '#micro509/internal/shared/mailbox';\nimport {\n\tencodeDistributionPointReasonFlagsContent,\n\tencodeKeyUsageExtension,\n} from '#micro509/internal/x509/extension-bits';\nimport { throwExtensionEncoderError } from '#micro509/internal/x509/extension-errors';\nimport type {\n\tExtensionDefinition,\n\tExtensionRegistryContext,\n} from '#micro509/internal/x509/extension-registry';\nimport {\n\tAUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION,\n\tAUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n\tBASIC_CONSTRAINTS_EXTENSION_DEFINITION,\n\tCERTIFICATE_POLICIES_EXTENSION_DEFINITION,\n\tCRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION,\n\tEXTENDED_KEY_USAGE_EXTENSION_DEFINITION,\n\tgetExtensionDefinition,\n\tINHIBIT_ANY_POLICY_EXTENSION_DEFINITION,\n\tKEY_USAGE_EXTENSION_DEFINITION,\n\tNAME_CONSTRAINTS_EXTENSION_DEFINITION,\n\tNO_REV_AVAIL_EXTENSION_DEFINITION,\n\tPOLICY_CONSTRAINTS_EXTENSION_DEFINITION,\n\tPOLICY_MAPPINGS_EXTENSION_DEFINITION,\n\tSUBJECT_ALT_NAME_EXTENSION_DEFINITION,\n\tSUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n} from '#micro509/internal/x509/extension-registry';\nimport { typedOtherName } from '#micro509/internal/x509/general-name';\nimport type { GeneralNameContentCheck } from '#micro509/internal/x509/general-name-profile';\nimport {\n\tcheckEdiPartyName,\n\tcheckOrAddress,\n\tnormalizeLabelSeparators,\n\tparsePresentedSrvName,\n\tparseSrvNameRestriction,\n\tparseUriNameConstraint,\n} from '#micro509/internal/x509/general-name-profile';\nimport { GENERAL_NAME_WIRE_TAGS } from '#micro509/internal/x509/general-name-tags';\nimport { isResultError } from '#micro509/result/result';\nimport type { RelativeDistinguishedNameInput } from '#micro509/x509/name';\nimport { encodeRelativeDistinguishedName } from '#micro509/x509/name';\nimport type { ParsedCertificate } from '#micro509/x509/parse';\n\nexport type { ExtensionEncoderErrorCode } from '#micro509/internal/x509/extension-errors';\nexport type {\n\tNameAttribute,\n\tNameFieldKey,\n\tRelativeDistinguishedNameInput,\n} from '#micro509/x509/name';\n\n/**\n * A decoded BIT STRING flag set.\n *\n * `flags` contains the recognized flag values with any non-zero padding bits\n * masked out. `nonZeroPadding` is `true` when the original BIT STRING encoding\n * had non-zero bits in positions that DER ({@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690 §11.2.1}) requires to be zero.\n * Extension flag decoding rejects such encodings, so parsed extension values\n * always report `false`.\n */\nexport interface ParsedBitFlags<T extends string> {\n\t/** Decoded flag values, padding bits masked. */\n\treadonly flags: readonly T[];\n\t/** `true` when the original encoding had non-zero padding bits (DER violation). */\n\treadonly nonZeroPadding: boolean;\n}\n\n/**\n * RFC 5280 §4.2.1.3 Key Usage bit flag.\n *\n * Each value corresponds to one bit in the KeyUsage BIT STRING.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.3 RFC 5280 §4.2.1.3}\n */\nexport type KeyUsage =\n\t| 'digitalSignature'\n\t| 'nonRepudiation'\n\t| 'keyEncipherment'\n\t| 'dataEncipherment'\n\t| 'keyAgreement'\n\t| 'keyCertSign'\n\t| 'cRLSign'\n\t| 'encipherOnly'\n\t| 'decipherOnly';\n\n/**\n * RFC 5280 §4.2.1.6 Subject Alternative Name / GeneralName.\n *\n * Discriminated union keyed on `type`.\n *\n * Every GeneralName alternative has a typed variant. Parsing never produces\n * `'unknown'`, which remains as raw builder input.\n */\nexport type SubjectAltName =\n\t| {\n\t\t\t/** DNS hostname (dNSName [2]). */\n\t\t\treadonly type: 'dns';\n\t\t\t/** Fully-qualified domain name, e.g. `\"example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** IP address (iPAddress [7]). */\n\t\t\treadonly type: 'ip';\n\t\t\t/** Dotted-decimal IPv4 or colon-hex IPv6 string. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** Email address (rfc822Name [1]). */\n\t\t\treadonly type: 'email';\n\t\t\t/** RFC 2821 §4.1.2 Mailbox (`Local-part@Domain`), e.g. `\"admin@example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** URI (uniformResourceIdentifier [6]). */\n\t\t\treadonly type: 'uri';\n\t\t\t/** Absolute URI string. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** SRV-ID otherName (id-on-dnsSRV). */\n\t\t\treadonly type: 'srv';\n\t\t\t/** SRV service name, e.g. `\"_imaps.example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** SmtpUTF8Mailbox otherName (id-on-SmtpUTF8Mailbox, RFC 9598 §3). */\n\t\t\treadonly type: 'smtpUtf8Mailbox';\n\t\t\t/** Internationalized mailbox whose domain is in A-labels, e.g. `\"用户@example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** User principal name otherName (szOID_NT_PRINCIPAL_NAME, [MS-WCCE] §2.2.2.7.5), a UTF8String. */\n\t\t\treadonly type: 'upn';\n\t\t\t/** User principal name, e.g. `\"user@example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** Kerberos principal name otherName (id-pkinit-san, RFC 4556 §3.2.2). */\n\t\t\treadonly type: 'krb5PrincipalName';\n\t\t\t/** Kerberos realm, e.g. `\"EXAMPLE.COM\"`. */\n\t\t\treadonly realm: string;\n\t\t\t/** RFC 4120 §6.2 name type, e.g. `1` for NT-PRINCIPAL. */\n\t\t\treadonly nameType: number;\n\t\t\t/** Principal name components, e.g. `[\"host\", \"www.example.com\"]`. */\n\t\t\treadonly nameString: readonly string[];\n\t }\n\t| {\n\t\t\t/** X.500 directory name (directoryName [4]). */\n\t\t\treadonly type: 'directoryName';\n\t\t\t/** Hex-encoded DER of the Name SEQUENCE. */\n\t\t\treadonly derHex: string;\n\t }\n\t| {\n\t\t\t/** otherName [0] of a type-id without a dedicated variant, or a UPN or KRB5PrincipalName value that does not fit its variant. */\n\t\t\treadonly type: 'otherName';\n\t\t\t/** Dotted-decimal type-id OID. */\n\t\t\treadonly typeId: string;\n\t\t\t/** DER of the single element inside `value [0] EXPLICIT`. */\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** X.400 O/R address (x400Address [3]). */\n\t\t\treadonly type: 'x400Address';\n\t\t\t/** Content octets of the ORAddress SEQUENCE. */\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** EDI party name (ediPartyName [5]). */\n\t\t\treadonly type: 'ediPartyName';\n\t\t\t/** Content octets of the EDIPartyName SEQUENCE. */\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** Registered identifier (registeredID [8]). */\n\t\t\treadonly type: 'registeredID';\n\t\t\t/** Dotted-decimal OID. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** Raw {@linkcode GeneralName} builder input, encoded under its wire tag. */\n\t\t\treadonly type: 'unknown';\n\t\t\t/** ASN.1 context tag number. */\n\t\t\treadonly tag: number;\n\t\t\t/** Raw content bytes of the element. */\n\t\t\treadonly value: Uint8Array;\n\t };\n\n/** Alias for {@linkcode SubjectAltName} — used where RFC 5280 says \"GeneralName\". */\nexport type GeneralName = SubjectAltName;\n\n/**\n * Revocation reason flags for CRL Distribution Points and Issuing Distribution Points\n * (RFC 5280 §4.2.1.13, §5.2.5).\n */\nexport type DistributionPointReason =\n\t| 'keyCompromise'\n\t| 'cACompromise'\n\t| 'affiliationChanged'\n\t| 'superseded'\n\t| 'cessationOfOperation'\n\t| 'certificateHold'\n\t| 'privilegeWithdrawn'\n\t| 'aACompromise';\n\n/**\n * Name component of a CRL Distribution Point, mirroring RFC 5280 §4.2.1.13\n * `DistributionPointName ::= CHOICE { fullName [0] GeneralNames,\n * nameRelativeToCRLIssuer [1] RelativeDistinguishedName }`.\n */\nexport type DistributionPointName =\n\t| {\n\t\t\t/** The `fullName [0]` alternative. */\n\t\t\treadonly type: 'fullName';\n\t\t\t/** Absolute {@linkcode GeneralName}(s) identifying the distribution point (usually a URI). */\n\t\t\treadonly fullName: readonly GeneralName[];\n\t }\n\t| {\n\t\t\t/** The `nameRelativeToCRLIssuer [1]` alternative. */\n\t\t\treadonly type: 'relativeName';\n\t\t\t/** Name relative to the issuer's DN. */\n\t\t\treadonly relativeName: RelativeDistinguishedNameInput;\n\t };\n\n/**\n * Input for a single CRL Distribution Point (RFC 5280 §4.2.1.13).\n *\n * At least one of `distributionPoint` or `crlIssuer` must be provided.\n * The union enforces this constraint at the type level.\n */\nexport type DistributionPoint =\n\t| {\n\t\t\t/** Where to fetch the CRL (fullName or relativeName). */\n\t\t\treadonly distributionPoint: DistributionPointName;\n\t\t\t/** Revocation reason subset. Absent means all reasons. */\n\t\t\treadonly reasons?: readonly DistributionPointReason[];\n\t\t\t/** Entity that signed the CRL, when different from the cert issuer. */\n\t\t\treadonly crlIssuer?: readonly GeneralName[];\n\t }\n\t| {\n\t\t\t/** Where to fetch the CRL. Optional when `crlIssuer` is present. */\n\t\t\treadonly distributionPoint?: DistributionPointName;\n\t\t\t/** Revocation reason subset. Absent means all reasons. */\n\t\t\treadonly reasons?: readonly DistributionPointReason[];\n\t\t\t/** Entity that signed the CRL. Required when `distributionPoint` is absent. */\n\t\t\treadonly crlIssuer: readonly GeneralName[];\n\t };\n\n/** Base shape for Issuing Distribution Point (RFC 5280 §5.2.5) — no scope restriction. */\nexport interface IssuingDistributionPointBase {\n\t/** Where to fetch this CRL. */\n\treadonly distributionPoint?: DistributionPointName;\n\t/** Limits the CRL to these revocation reasons. Absent means all reasons. */\n\treadonly onlySomeReasons?: readonly DistributionPointReason[];\n\t/** When true, the CRL may contain entries from other CAs. Default false. */\n\treadonly indirectCrl?: boolean;\n\t/** Must be absent or false in this variant (no user-cert-only restriction). */\n\treadonly onlyContainsUserCerts?: false;\n\t/** Must be absent or false in this variant (no CA-cert-only restriction). */\n\treadonly onlyContainsCACerts?: false;\n\t/** When true, the CRL only covers attribute certificates. Default false. */\n\treadonly onlyContainsAttributeCerts?: boolean;\n}\n\n/** IDP scoped to end-entity (user) certificates only. Mutually exclusive with CA / attribute scopes. */\nexport interface IssuingDistributionPointForUserCerts\n\textends Omit<IssuingDistributionPointBase, 'onlyContainsUserCerts'> {\n\t/** This variant only covers end-entity certificates. */\n\treadonly onlyContainsUserCerts: true;\n\t/** Must be absent or false when the CRL is not CA-only. */\n\treadonly onlyContainsCACerts?: false;\n\t/** Must be absent or false when the CRL is not attribute-cert-only. */\n\treadonly onlyContainsAttributeCerts?: false;\n}\n\n/** IDP scoped to CA certificates only. Mutually exclusive with user / attribute scopes. */\nexport interface IssuingDistributionPointForCaCerts\n\textends Omit<IssuingDistributionPointBase, 'onlyContainsCACerts'> {\n\t/** Must be absent or false when the CRL is not user-cert-only. */\n\treadonly onlyContainsUserCerts?: false;\n\t/** This variant only covers CA certificates. */\n\treadonly onlyContainsCACerts: true;\n\t/** Must be absent or false when the CRL is not attribute-cert-only. */\n\treadonly onlyContainsAttributeCerts?: false;\n}\n\n/** IDP scoped to attribute certificates only. Mutually exclusive with user / CA scopes. */\nexport interface IssuingDistributionPointForAttributeCerts\n\textends Omit<IssuingDistributionPointBase, 'onlyContainsAttributeCerts'> {\n\t/** Must be absent or false when the CRL is not user-cert-only. */\n\treadonly onlyContainsUserCerts?: false;\n\t/** Must be absent or false when the CRL is not CA-only. */\n\treadonly onlyContainsCACerts?: false;\n\t/** This variant only covers attribute certificates. */\n\treadonly onlyContainsAttributeCerts: true;\n}\n\n/**\n * Input for the Issuing Distribution Point CRL extension (RFC 5280 §5.2.5).\n *\n * The union enforces that at most one of the `onlyContains*` flags is true.\n */\nexport type IssuingDistributionPoint =\n\t| IssuingDistributionPointBase\n\t| IssuingDistributionPointForUserCerts\n\t| IssuingDistributionPointForCaCerts\n\t| IssuingDistributionPointForAttributeCerts;\n\n/**\n * RFC 5280 §4.2.1.9 Basic Constraints.\n *\n * A certificate with `ca: true` may issue other certificates; `pathLength`\n * limits how many additional CAs may appear below it in the chain.\n */\nexport type BasicConstraints =\n\t| {\n\t\t\t/** End-entity certificate: not a CA. */\n\t\t\treadonly ca: false;\n\t\t\t/** Never present on end-entity certificates. */\n\t\t\treadonly pathLength?: undefined;\n\t }\n\t| {\n\t\t\t/** CA certificate: may issue other certificates. */\n\t\t\treadonly ca: true;\n\t\t\t/** Maximum number of intermediate CA certificates allowed below this CA. */\n\t\t\treadonly pathLength?: number;\n\t };\n\n/** A single certificate policy: an OID plus optional qualifiers. */\nexport interface PolicyInformation {\n\t/** Dotted-decimal OID of the policy (e.g. `\"2.23.140.1.2.1\"` for DV). */\n\treadonly policyIdentifier: string;\n\t/** Optional CPS URIs or user notices attached to this policy. */\n\treadonly policyQualifiers?: readonly PolicyQualifierInfo[];\n}\n\n/** RFC 5280 §4.2.1.4 — array of policy OIDs with optional qualifiers. */\nexport type CertificatePolicies = readonly {\n\t/** Dotted-decimal OID of the policy (e.g. `\"2.23.140.1.2.1\"` for DV). */\n\treadonly policyIdentifier: string;\n\t/** Optional CPS URIs or user notices attached to this policy. */\n\treadonly policyQualifiers?: readonly (\n\t\t| {\n\t\t\t\treadonly type: 'cps';\n\t\t\t\treadonly uri: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'userNotice';\n\t\t\t\treadonly noticeRef?: {\n\t\t\t\t\treadonly organization: string;\n\t\t\t\t\treadonly noticeNumbers: readonly number[];\n\t\t\t\t\t/** Present when `organization` exceeds 200 characters; the builder emits no such notice. */\n\t\t\t\t\treadonly oversizedOrganization?: OversizedDisplayText;\n\t\t\t\t};\n\t\t\t\treadonly explicitText?: string;\n\t\t\t\treadonly explicitTextType?: DisplayTextType;\n\t\t\t\t/** Present when `explicitText` exceeds 200 characters; the builder emits no such notice. */\n\t\t\t\treadonly oversizedExplicitText?: OversizedDisplayText;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'oid';\n\t\t\t\treadonly oid: string;\n\t\t\t\treadonly qualifierDer: Uint8Array;\n\t\t }\n\t)[];\n}[];\n\n/** CPS (Certification Practice Statement) URI policy qualifier. */\nexport interface CpsPolicyQualifierInfo {\n\t/** Discriminant for the `'cps'` qualifier variant. */\n\treadonly type: 'cps';\n\t/** URL of the Certification Practice Statement document. */\n\treadonly uri: string;\n}\n\n/** Reference to a numbered notice within an organization's practice statement. */\nexport interface PolicyNoticeReference {\n\t/** Organization name that published the notice. */\n\treadonly organization: string;\n\t/** One-based notice numbers within that organization's documentation. */\n\treadonly noticeNumbers: readonly number[];\n}\n\n/** UserNotice policy qualifier — human-readable notice text and/or a notice reference. */\nexport interface UserNoticePolicyQualifierInfo {\n\t/** Discriminant for the `'userNotice'` qualifier variant. */\n\treadonly type: 'userNotice';\n\t/** Pointer to a numbered notice in an organization's practice statement. */\n\treadonly noticeRef?: PolicyNoticeReference;\n\t/** Free-form text to display to relying parties. */\n\treadonly explicitText?: string;\n\t/**\n\t * ASN.1 string type carrying `explicitText`. Parsing reports the received\n\t * type. The builder defaults to `'utf8String'`, accepts `'visibleString'`\n\t * and `'bmpString'`, and rejects `'ia5String'` (RFC 6818 §3).\n\t */\n\treadonly explicitTextType?: DisplayTextType;\n}\n\n/** The ASN.1 string types RFC 5280 §4.2.1.4 allows for a DisplayText. */\nexport type DisplayTextType = 'utf8String' | 'ia5String' | 'visibleString' | 'bmpString';\n\n/**\n * A user notice `explicitText` or `noticeRef` organization longer than the 200\n * characters RFC 5280 §4.2.1.4 allows a DisplayText. Parsing keeps the text\n * whole and reports its size here.\n */\nexport interface OversizedDisplayText {\n\t/** Characters the certificate carries. */\n\treadonly characters: number;\n\t/** The RFC 5280 §4.2.1.4 upper bound, 200. */\n\treadonly limit: number;\n}\n\n/** Opaque policy qualifier identified by a custom OID, carried as raw DER. */\nexport interface CustomPolicyQualifierInfo {\n\t/** Discriminant for the custom-OID qualifier variant. */\n\treadonly type: 'oid';\n\t/** Dotted-decimal OID of the qualifier. */\n\treadonly oid: string;\n\t/** DER-encoded qualifier payload. */\n\treadonly qualifierDer: Uint8Array;\n}\n\n/** Discriminated union of all supported policy qualifier types. */\nexport type PolicyQualifierInfo =\n\t| CpsPolicyQualifierInfo\n\t| UserNoticePolicyQualifierInfo\n\t| CustomPolicyQualifierInfo;\n\n/** Maps a policy OID in the issuer's domain to an equivalent OID in the subject's domain. */\nexport interface PolicyMapping {\n\t/** Policy OID as defined by the issuing CA. Must not be anyPolicy. */\n\treadonly issuerDomainPolicy: string;\n\t/** Equivalent policy OID in the subject CA's domain. Must not be anyPolicy. */\n\treadonly subjectDomainPolicy: string;\n}\n\n/** RFC 5280 §4.2.1.5 — array of issuer-to-subject policy OID pairs. */\nexport type PolicyMappings = readonly {\n\t/** Policy OID as defined by the issuing CA. Must not be anyPolicy. */\n\treadonly issuerDomainPolicy: string;\n\t/** Equivalent policy OID in the subject CA's domain. Must not be anyPolicy. */\n\treadonly subjectDomainPolicy: string;\n}[];\n\n/**\n * RFC 5280 §4.2.1.11 Policy Constraints.\n *\n * At least one field must be present. Values are certificate-count\n * thresholds measured from the current certificate toward the end entity.\n */\nexport interface PolicyConstraints {\n\t/** After this many certificates, an acceptable policy must be in the path. */\n\treadonly requireExplicitPolicy?: number;\n\t/** After this many certificates, policy mapping is no longer allowed. */\n\treadonly inhibitPolicyMapping?: number;\n}\n\n/**\n * RFC 5280 §4.2.1.14 Inhibit anyPolicy.\n *\n * After `skipCerts` additional non-self-issued certificates in the path, the\n * special anyPolicy OID is no longer considered a match, except when it\n * appears in an intermediate self-issued CA certificate.\n */\nexport interface InhibitAnyPolicy {\n\t/** Number of additional non-self-issued certificates before anyPolicy stops being valid. */\n\treadonly skipCerts: number;\n}\n\n/**\n * Input for `createCertificate`, `createSelfSignedCertificate`,\n * and `createCertificateSigningRequest`.\n *\n * Every field is optional. Omitted extensions are not encoded. Built-in\n * extensions (SKI, AKI, basicConstraints defaults) are handled automatically\n * by the builder.\n */\nexport interface CertificateExtensionsInput {\n\t/** Subject Alternative Names (dns, ip, email, uri, srv, directoryName). */\n\treadonly subjectAltNames?: readonly SubjectAltName[];\n\t/** Key Usage flags (digitalSignature, keyCertSign, etc.). */\n\treadonly keyUsage?: readonly KeyUsage[];\n\t/** Basic Constraints (CA flag + optional pathLength). Defaults to `{ ca: false }` for certs. */\n\treadonly basicConstraints?: BasicConstraints;\n\t/** Extended Key Usage purposes (serverAuth, clientAuth, etc.). */\n\treadonly extendedKeyUsage?: readonly ExtendedKeyUsage[];\n\t/** Name Constraints — permitted and/or excluded subtrees. */\n\treadonly nameConstraints?: NameConstraints;\n\t/** Certificate Policies with optional qualifiers. */\n\treadonly certificatePolicies?: CertificatePolicies;\n\t/** Policy Mappings between issuer and subject policy domains. */\n\treadonly policyMappings?: PolicyMappings;\n\t/** Policy Constraints (requireExplicitPolicy / inhibitPolicyMapping thresholds). */\n\treadonly policyConstraints?: PolicyConstraints;\n\t/** Inhibit anyPolicy skip-certs threshold. */\n\treadonly inhibitAnyPolicy?: InhibitAnyPolicy;\n\t/** Authority Information Access — OCSP responder and CA issuer locations. */\n\treadonly authorityInfoAccess?: readonly AuthorityInformationAccessInput[];\n\t/** CRL Distribution Points — where to check revocation status. */\n\treadonly crlDistributionPoints?: readonly DistributionPoint[];\n\t/**\n\t * Emit No Revocation Available (RFC 9608 §2): the CA publishes no revocation\n\t * information for this certificate. A certificate carrying it cannot be a CA\n\t * and cannot point at a CRL or an OCSP responder (RFC 9608 §3).\n\t */\n\treadonly noRevAvail?: boolean;\n\t/** Arbitrary extensions not covered by the built-in fields. */\n\treadonly customExtensions?: readonly CustomExtension[];\n}\n\n/** An extension not covered by the typed fields in {@linkcode CertificateExtensionsInput}. */\nexport interface CustomExtension {\n\t/** Dotted-decimal OID of the extension. */\n\treadonly oid: string;\n\t/** Pre-encoded DER content for the extnValue OCTET STRING. */\n\treadonly value: Uint8Array;\n\t/** Whether the extension is critical. Default `false`. */\n\treadonly critical?: boolean;\n}\n\n// Name constraints (RFC 5280 §4.2.1.10)\n\n/**\n * A name form used as a constraint base in namEConstraints.\n * Distinct from {@linkcode SubjectAltName} because IP constraints carry\n * address + mask bytes (8 for IPv4, 32 for IPv6) rather than bare addresses.\n */\nexport type NameConstraintForm =\n\t| {\n\t\t\t/** DNS domain constraint (dNSName [2]). */\n\t\t\treadonly type: 'dns';\n\t\t\t/** Domain suffix, e.g. `\".example.com\"` or `\"example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** Email constraint (rfc822Name [1]). */\n\t\t\treadonly type: 'email';\n\t\t\t/** Email domain or full address pattern. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** URI constraint (uniformResourceIdentifier [6]). */\n\t\t\treadonly type: 'uri';\n\t\t\t/** Host or domain component of a URI. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** IP range constraint (iPAddress [7]). */\n\t\t\treadonly type: 'ip';\n\t\t\t/** Network address bytes (4 for IPv4, 16 for IPv6). */\n\t\t\treadonly addressBytes: Uint8Array;\n\t\t\t/** Subnet mask bytes (same length as addressBytes). */\n\t\t\treadonly maskBytes: Uint8Array;\n\t }\n\t| {\n\t\t\t/** Directory name constraint (directoryName [4]). */\n\t\t\treadonly type: 'directoryName';\n\t\t\t/** Hex-encoded DER of the Name SEQUENCE. */\n\t\t\treadonly derHex: string;\n\t }\n\t| {\n\t\t\t/** SRVName constraint (otherName id-on-dnsSRV, RFC 4985 §4). */\n\t\t\treadonly type: 'srv';\n\t\t\t/** `_Service.Name`, `_Service`, or `Name`, e.g. `\"_mail.example.com\"`. */\n\t\t\treadonly value: string;\n\t };\n\n/**\n * Name constraint forms parsed from DER but not supported for encoding or\n * validation. Preserved for diagnostic round-tripping.\n */\nexport type UnsupportedNameConstraintForm =\n\t| {\n\t\t\t/** otherName [0] of a type-id without defined constraint semantics. */\n\t\t\treadonly type: 'otherName';\n\t\t\t/** Dotted-decimal type-id OID. */\n\t\t\treadonly typeId: string;\n\t\t\t/** DER of the single element inside `value [0] EXPLICIT`. */\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** x400Address [3] — raw bytes. */\n\t\t\treadonly type: 'x400Address';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** ediPartyName [5] — raw bytes. */\n\t\t\treadonly type: 'ediPartyName';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** registeredID [8] — decoded OID string. */\n\t\t\treadonly type: 'registeredID';\n\t\t\treadonly value: string;\n\t };\n\n/** Union of supported and unsupported name constraint forms as produced by parsing. */\nexport type ParsedNameConstraintForm =\n\t| {\n\t\t\treadonly type: 'dns';\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\treadonly type: 'email';\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\treadonly type: 'uri';\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\treadonly type: 'ip';\n\t\t\treadonly addressBytes: Uint8Array;\n\t\t\treadonly maskBytes: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'directoryName';\n\t\t\treadonly derHex: string;\n\t }\n\t| {\n\t\t\treadonly type: 'srv';\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\treadonly type: 'otherName';\n\t\t\treadonly typeId: string;\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'x400Address';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'ediPartyName';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'registeredID';\n\t\t\treadonly value: string;\n\t };\n\n/** A single subtree entry in a Name Constraints permitted/excluded list. */\nexport interface GeneralSubtree<\n\tTForm extends ParsedNameConstraintForm =\n\t\t| {\n\t\t\t\treadonly type: 'dns';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'email';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'uri';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'ip';\n\t\t\t\treadonly addressBytes: Uint8Array;\n\t\t\t\treadonly maskBytes: Uint8Array;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'directoryName';\n\t\t\t\treadonly derHex: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'srv';\n\t\t\t\treadonly value: string;\n\t\t },\n> {\n\t/** The name form that defines this constraint boundary. */\n\treadonly base: TForm;\n}\n\n/**\n * RFC 5280 §4.2.1.10 Name Constraints.\n *\n * A CA certificate may restrict the namespace of all subject names in\n * subsequent certificates in the path.\n */\nexport interface NameConstraints<\n\tTForm extends ParsedNameConstraintForm =\n\t\t| {\n\t\t\t\treadonly type: 'dns';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'email';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'uri';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'ip';\n\t\t\t\treadonly addressBytes: Uint8Array;\n\t\t\t\treadonly maskBytes: Uint8Array;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'directoryName';\n\t\t\t\treadonly derHex: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'srv';\n\t\t\t\treadonly value: string;\n\t\t },\n> {\n\t/** Names that MUST fall within these subtrees to be valid. */\n\treadonly permittedSubtrees?: readonly GeneralSubtree<TForm>[];\n\t/** Names that MUST NOT fall within these subtrees. Takes precedence over permitted. */\n\treadonly excludedSubtrees?: readonly GeneralSubtree<TForm>[];\n}\n\n/** Well-known AIA access methods: OCSP responder or CA issuer certificate. */\nexport type KnownAuthorityInfoAccessMethod = 'ocsp' | 'caIssuers';\n\n/** AIA access method identified by a custom OID not in the well-known set. */\nexport interface CustomAuthorityInfoAccessMethod {\n\t/** Discriminant for the custom-OID access method variant. */\n\treadonly type: 'oid';\n\t/** Dotted-decimal OID of the access method. */\n\treadonly value: string;\n}\n\n/** AIA access method — either a well-known string or a custom OID. */\nexport type AuthorityInfoAccessMethod =\n\t| KnownAuthorityInfoAccessMethod\n\t| CustomAuthorityInfoAccessMethod;\n\n/** A single entry in the Authority Information Access extension (RFC 5280 §4.2.2.1). */\nexport interface AuthorityInformationAccess {\n\t/** Access method (`'ocsp'`, `'caIssuers'`, or custom OID). */\n\treadonly method:\n\t\t| 'ocsp'\n\t\t| 'caIssuers'\n\t\t| {\n\t\t\t\treadonly type: 'oid';\n\t\t\t\treadonly value: string;\n\t\t };\n\t/** accessLocation GeneralName where the resource is available (usually a URI). */\n\treadonly location: GeneralName;\n}\n\n/**\n * Builder input for one Authority Information Access entry.\n *\n * Parsed AIA locations stay broad ({@linkcode AuthorityInformationAccess}), but\n * an `'ocsp'` entry must supply a URI location, since RFC 6960 §3.1 defines the\n * `id-ad-ocsp` location as a URI; `directoryName` is defined for `caIssuers`.\n */\nexport type AuthorityInformationAccessInput =\n\t| {\n\t\t\t/** OCSP responder access method. */\n\t\t\treadonly method: 'ocsp';\n\t\t\t/** OCSP responder URI (RFC 6960 §3.1). */\n\t\t\treadonly location: { readonly type: 'uri'; readonly value: string };\n\t }\n\t| {\n\t\t\t/** caIssuers or a custom access method. */\n\t\t\treadonly method: 'caIssuers' | CustomAuthorityInfoAccessMethod;\n\t\t\t/** Any accessLocation GeneralName. */\n\t\t\treadonly location: GeneralName;\n\t };\n\n/** Well-known Extended Key Usage purpose strings (RFC 5280 §4.2.1.12). */\nexport type KnownExtendedKeyUsage =\n\t| 'serverAuth'\n\t| 'clientAuth'\n\t| 'codeSigning'\n\t| 'emailProtection'\n\t| 'timeStamping'\n\t| 'ocspSigning';\n\n/** Extended Key Usage purpose identified by a custom OID. */\nexport interface CustomExtendedKeyUsage {\n\t/** Discriminant for the custom-OID EKU variant. */\n\treadonly type: 'oid';\n\t/** Dotted-decimal OID of the usage purpose. */\n\treadonly value: string;\n}\n\n/** Extended Key Usage — either a well-known purpose string or a custom OID. */\nexport type ExtendedKeyUsage =\n\t| 'serverAuth'\n\t| 'clientAuth'\n\t| 'codeSigning'\n\t| 'emailProtection'\n\t| 'timeStamping'\n\t| 'ocspSigning'\n\t| {\n\t\t\treadonly type: 'oid';\n\t\t\treadonly value: string;\n\t };\n\n/** Map from well-known EKU names to their dotted-decimal OIDs. */\nconst EXTENDED_KEY_USAGE_OIDS: Record<KnownExtendedKeyUsage, string> = {\n\tserverAuth: OIDS.serverAuth,\n\tclientAuth: OIDS.clientAuth,\n\tcodeSigning: OIDS.codeSigning,\n\temailProtection: OIDS.emailProtection,\n\ttimeStamping: OIDS.timeStamping,\n\tocspSigning: OIDS.ocspSigning,\n};\n\n/** Map from well-known AIA method names to their dotted-decimal OIDs. */\nconst AUTHORITY_INFO_ACCESS_METHOD_OIDS: Record<KnownAuthorityInfoAccessMethod, string> = {\n\tocsp: OIDS.ocspAccessMethod,\n\tcaIssuers: OIDS.caIssuersAccessMethod,\n};\n\n/**\n * Build the v3 extensions block for a certificate.\n *\n * Automatically adds SKI, AKI (when a key identifier is given), and\n * basicConstraints (defaults to `{ ca: false }`). Additional extensions\n * come from the caller's {@linkcode CertificateExtensionsInput}.\n *\n * @param subjectPublicKeyInfo DER-encoded SPKI of the subject.\n * @param authorityKeyIdentifier Key identifier for the AKI, or `undefined` to omit it.\n * @param input Optional extension configuration.\n * @param subjectIsEmpty Whether the certificate subject DN is empty. When `true`, a\n * subjectAltName extension is required and marked critical per RFC 5280 §4.2.1.6.\n * @returns Array of DER-encoded Extension SEQUENCEs.\n */\nexport function buildCertificateExtensions(\n\tsubjectPublicKeyInfo: Uint8Array,\n\tauthorityKeyIdentifier: Uint8Array | undefined,\n\tinput: CertificateExtensionsInput | undefined,\n\tsubjectIsEmpty = false,\n): Uint8Array[] {\n\tassertCustomExtensionsValid(input, 'certificate');\n\tif (subjectIsEmpty) {\n\t\tassertEmptySubjectHasCriticalSubjectAltName(input);\n\t}\n\tassertPathLengthKeyUsage(input);\n\tassertSafeCurveKeyUsage(subjectPublicKeyInfo, input);\n\tassertNoRevAvailProfile(input);\n\tconst extensions: Uint8Array[] = [];\n\tconst seen = new Set<string>();\n\tconst basicConstraints = input?.basicConstraints ?? { ca: false };\n\tpushKnownExtension(extensions, seen, BASIC_CONSTRAINTS_EXTENSION_DEFINITION, basicConstraints);\n\tpushKnownExtension(\n\t\textensions,\n\t\tseen,\n\t\tSUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n\t\tbuildSubjectKeyIdentifier(subjectPublicKeyInfo),\n\t);\n\tif (authorityKeyIdentifier !== undefined) {\n\t\tpushKnownExtension(\n\t\t\textensions,\n\t\t\tseen,\n\t\t\tAUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n\t\t\tauthorityKeyIdentifier,\n\t\t);\n\t}\n\tappendConfiguredExtensions(extensions, seen, input, {\n\t\tincludeBasicConstraints: false,\n\t\tsubjectIsEmpty,\n\t});\n\treturn extensions;\n}\n\n/**\n * Build the extensions for a CSR's extensionRequest attribute.\n *\n * Unlike {@linkcode buildCertificateExtensions}, SKI/AKI are not auto-generated.\n *\n * @param input Optional extension configuration.\n * @returns Array of DER-encoded Extension SEQUENCEs.\n */\nexport function buildRequestedExtensions(\n\tinput: CertificateExtensionsInput | undefined,\n): Uint8Array[] {\n\tassertCustomExtensionsValid(input, 'csr');\n\tconst extensions: Uint8Array[] = [];\n\tconst seen = new Set<string>();\n\tappendConfiguredExtensions(extensions, seen, input, { includeBasicConstraints: true });\n\treturn extensions;\n}\n\n/** Encode and push each configured extension from the input, enforcing no duplicates. */\nfunction appendConfiguredExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput | undefined,\n\toptions: {\n\t\treadonly includeBasicConstraints: boolean;\n\t\t/** When true, SAN is marked critical per RFC 5280 §4.2.1.6. */\n\t\treadonly subjectIsEmpty?: boolean;\n\t},\n): void {\n\tif (input === undefined) {\n\t\treturn;\n\t}\n\tappendConstraintExtensions(encoded, seen, input, options.includeBasicConstraints);\n\tappendIdentityExtensions(encoded, seen, input, options.subjectIsEmpty === true);\n\tappendPolicyExtensions(encoded, seen, input);\n\tappendAccessExtensions(encoded, seen, input);\n\tappendCustomExtensions(encoded, seen, input);\n}\n\n/**\n * RFC 5280 §4.2.1.9: pathLenConstraint requires the keyUsage extension to assert keyCertSign.\n * Absent, empty, or keyCertSign-less keyUsage is rejected. Known extensions supplied through\n * customExtensions participate in the effective view.\n */\nfunction assertPathLengthKeyUsage(input: CertificateExtensionsInput | undefined): void {\n\tconst basicConstraints = resolveEffectiveBasicConstraints(input);\n\tif (basicConstraints?.pathLength === undefined) {\n\t\treturn;\n\t}\n\tconst keyUsage = resolveEffectiveKeyUsage(input);\n\tif (keyUsage === undefined || keyUsage.length === 0 || !keyUsage.includes('keyCertSign')) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'path_length_requires_key_cert_sign',\n\t\t\t'basicConstraints pathLength requires the keyUsage keyCertSign bit',\n\t\t);\n\t}\n}\n\n/** RFC 9295 §3: an end-entity id-Ed25519 or id-Ed448 certificate needs one of these. */\nconst EDWARDS_END_ENTITY_KEY_USAGE = ['nonRepudiation', 'digitalSignature', 'cRLSign'] as const;\n\n/** RFC 9295 §3: bits an id-Ed25519 or id-Ed448 certificate must never assert. */\nconst EDWARDS_FORBIDDEN_KEY_USAGE = [\n\t'keyEncipherment',\n\t'dataEncipherment',\n\t'keyAgreement',\n\t'encipherOnly',\n\t'decipherOnly',\n] as const;\n\n/** RFC 9295 §3: bits an id-X25519 or id-X448 certificate must never assert. */\nconst MONTGOMERY_FORBIDDEN_KEY_USAGE = [\n\t'digitalSignature',\n\t'nonRepudiation',\n\t'keyEncipherment',\n\t'dataEncipherment',\n\t'keyCertSign',\n\t'cRLSign',\n] as const;\n\n/**\n * RFC 9295 §3, which replaces RFC 8410 §5, constrains a keyUsage extension on a\n * certificate whose subject key names one of the four 1.3.101 curves.\n *\n * id-X25519 and id-X448 require `keyAgreement`, admit one of `encipherOnly` and\n * `decipherOnly`, and forbid the rest.\n *\n * id-Ed25519 and id-Ed448 split on whether the certificate is a certification\n * authority. A CA MUST assert `keyCertSign` and MAY add `nonRepudiation`,\n * `digitalSignature`, or `cRLSign`. Any other certificate MUST assert at least\n * one of those three and MUST NOT assert `keyCertSign`. Both forbid the key\n * agreement and encipherment bits. A CRL issuer is the case where `cRLSign` is\n * the bit chosen, and a CRL issuer that is also a CA is the CA case, so the two\n * branches cover the section's four paragraphs.\n *\n * The rule binds only a keyUsage that reaches the wire, so an absent one, and an\n * empty one the builder therefore omits, leave the key unconstrained.\n */\nfunction assertSafeCurveKeyUsage(\n\tsubjectPublicKeyInfo: Uint8Array,\n\tinput: CertificateExtensionsInput | undefined,\n): void {\n\tconst keyUsage = resolveEffectiveKeyUsage(input);\n\tif (keyUsage === undefined || keyUsage.length === 0) {\n\t\treturn;\n\t}\n\tconst algorithm = readSubjectKeyAlgorithmOid(subjectPublicKeyInfo);\n\tif (algorithm === undefined) {\n\t\treturn;\n\t}\n\tif (oidEquals(algorithm, OIDS.x25519) || oidEquals(algorithm, OIDS.x448)) {\n\t\tassertMontgomeryKeyUsage(keyUsage);\n\t\treturn;\n\t}\n\tif (oidEquals(algorithm, OIDS.ed25519) || oidEquals(algorithm, OIDS.ed448)) {\n\t\tassertEdwardsKeyUsage(keyUsage, resolveEffectiveBasicConstraints(input)?.ca === true);\n\t}\n}\n\n/** The X25519 and X448 half of RFC 9295 §3. */\nfunction assertMontgomeryKeyUsage(keyUsage: readonly KeyUsage[]): void {\n\tif (!keyUsage.includes('keyAgreement')) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'montgomery_key_usage_requires_key_agreement',\n\t\t\t'keyUsage on an X25519 or X448 certificate must set keyAgreement',\n\t\t);\n\t}\n\tconst asserted = MONTGOMERY_FORBIDDEN_KEY_USAGE.filter((flag: KeyUsage) =>\n\t\tkeyUsage.includes(flag),\n\t);\n\tif (asserted.length > 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'montgomery_key_usage_forbids_signature_bit',\n\t\t\t`keyUsage on an X25519 or X448 certificate must not set ${asserted.join(', ')}`,\n\t\t);\n\t}\n\tif (keyUsage.includes('encipherOnly') && keyUsage.includes('decipherOnly')) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'montgomery_key_usage_forbids_both_cipher_bits',\n\t\t\t'keyUsage on an X25519 or X448 certificate must not set both encipherOnly and decipherOnly',\n\t\t);\n\t}\n}\n\n/** The Ed25519 and Ed448 half of RFC 9295 §3. */\nfunction assertEdwardsKeyUsage(\n\tkeyUsage: readonly KeyUsage[],\n\tisCertificationAuthority: boolean,\n): void {\n\tif (isCertificationAuthority) {\n\t\tif (!keyUsage.includes('keyCertSign')) {\n\t\t\tthrowExtensionEncoderError(\n\t\t\t\t'edwards_key_usage_requires_key_cert_sign',\n\t\t\t\t'keyUsage on an Ed25519 or Ed448 certification authority certificate must set keyCertSign',\n\t\t\t);\n\t\t}\n\t} else if (!EDWARDS_END_ENTITY_KEY_USAGE.some((flag: KeyUsage) => keyUsage.includes(flag))) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'edwards_key_usage_requires_signing_bit',\n\t\t\t`keyUsage on an Ed25519 or Ed448 certificate must set one of ${EDWARDS_END_ENTITY_KEY_USAGE.join(', ')}`,\n\t\t);\n\t}\n\tconst asserted = EDWARDS_FORBIDDEN_KEY_USAGE.filter((flag: KeyUsage) => keyUsage.includes(flag));\n\tif (asserted.length > 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'edwards_key_usage_forbids_agreement_bit',\n\t\t\t`keyUsage on an Ed25519 or Ed448 certificate must not set ${asserted.join(', ')}`,\n\t\t);\n\t}\n\tif (!isCertificationAuthority && keyUsage.includes('keyCertSign')) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'edwards_key_usage_forbids_key_cert_sign',\n\t\t\t'keyUsage on an Ed25519 or Ed448 end-entity certificate must not set keyCertSign',\n\t\t);\n\t}\n}\n\n/** The algorithm OID of a SubjectPublicKeyInfo, or `undefined` when the field is not an OID. */\nfunction readSubjectKeyAlgorithmOid(subjectPublicKeyInfo: Uint8Array): string | undefined {\n\tconst algorithm = readSequenceChildren(subjectPublicKeyInfo)[0];\n\tif (algorithm === undefined || algorithm.tag !== 0x30) {\n\t\treturn undefined;\n\t}\n\tconst oid = childrenOf(subjectPublicKeyInfo, algorithm)[0];\n\treturn oid?.tag === 0x06 ? decodeObjectIdentifier(oid.value) : undefined;\n}\n\n/**\n * RFC 5280 §4.2.1.9: basicConstraints is critical in a CA certificate whose key\n * validates signatures on certificates. Both conjuncts live in other extensions,\n * so the rule sits here rather than in the basicConstraints profile hook.\n *\n * §4.2.1.3 restricts a key only through a keyUsage extension that reaches the\n * wire, so an absent keyUsage, and an empty one the builder therefore omits,\n * leave the key free to validate certificate signatures. Only an emitted keyUsage\n * without keyCertSign takes the certificate out of the clause's scope.\n *\n * Only a custom extension can carry the wrong criticality; the typed field is\n * always emitted with the registry default.\n */\nfunction assertCaBasicConstraintsCritical(input: CertificateExtensionsInput | undefined): void {\n\tconst custom = input?.customExtensions?.find((extension) =>\n\t\toidEquals(extension.oid, OIDS.basicConstraints),\n\t);\n\tif (custom === undefined || custom.critical === true) {\n\t\treturn;\n\t}\n\tconst basicConstraints = BASIC_CONSTRAINTS_EXTENSION_DEFINITION.decode(\n\t\tnew Uint8Array(custom.value),\n\t);\n\tif (!basicConstraints.ca) {\n\t\treturn;\n\t}\n\tconst keyUsage = resolveEffectiveKeyUsage(input);\n\tconst mayValidateCertificates =\n\t\tkeyUsage === undefined || keyUsage.length === 0 || keyUsage.includes('keyCertSign');\n\tif (mayValidateCertificates) {\n\t\tassertExtensionCriticality('basicConstraints', true, false);\n\t}\n}\n\n/**\n * RFC 9608 §2 and §3: a certificate carrying noRevAvail is not a CA certificate\n * and carries no cRLDistributionPoints, no freshestCRL, and no id-ad-ocsp\n * authorityInfoAccess entry. Known extensions supplied through customExtensions\n * participate in the effective view.\n */\nfunction assertNoRevAvailProfile(input: CertificateExtensionsInput | undefined): void {\n\tif (\n\t\tinput?.noRevAvail !== true &&\n\t\tfindCustomExtensionValue(input, OIDS.noRevAvail) === undefined\n\t) {\n\t\treturn;\n\t}\n\tif (resolveEffectiveBasicConstraints(input)?.ca === true) {\n\t\tthrowNoRevAvailConflict('basicConstraints with cA TRUE');\n\t}\n\tif (\n\t\t(input?.crlDistributionPoints?.length ?? 0) > 0 ||\n\t\tfindCustomExtensionValue(input, OIDS.cRLDistributionPoints) !== undefined\n\t) {\n\t\tthrowNoRevAvailConflict('cRLDistributionPoints');\n\t}\n\tif (findCustomExtensionValue(input, OIDS.freshestCRL) !== undefined) {\n\t\tthrowNoRevAvailConflict('freshestCRL');\n\t}\n\tif (\n\t\tresolveEffectiveAuthorityInfoAccess(input).some(\n\t\t\t(entry) => getAuthorityInfoAccessMethodOid(entry.method) === OIDS.ocspAccessMethod,\n\t\t)\n\t) {\n\t\tthrowNoRevAvailConflict('an id-ad-ocsp authorityInfoAccess entry');\n\t}\n}\n\n/** The authorityInfoAccess entries the builder will emit: the typed list when non-empty, otherwise a custom-known extension. */\nfunction resolveEffectiveAuthorityInfoAccess(\n\tinput: CertificateExtensionsInput | undefined,\n): readonly (AuthorityInformationAccess | AuthorityInformationAccessInput)[] {\n\tif (input?.authorityInfoAccess !== undefined && input.authorityInfoAccess.length > 0) {\n\t\treturn input.authorityInfoAccess;\n\t}\n\tconst custom = findCustomExtensionValue(input, OIDS.authorityInfoAccess);\n\treturn custom === undefined ? [] : AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION.decode(custom);\n}\n\nfunction throwNoRevAvailConflict(conflict: string): never {\n\tthrowExtensionEncoderError(\n\t\t'no_rev_avail_conflict',\n\t\t`A certificate carrying noRevAvail must not also carry ${conflict}`,\n\t);\n}\n\n/**\n * RFC 5280 §4.2.1.6: an empty subject DN requires a subjectAltName extension\n * present, marked critical, and carrying at least one non-empty GeneralName.\n */\nfunction assertEmptySubjectHasCriticalSubjectAltName(\n\tinput: CertificateExtensionsInput | undefined,\n): void {\n\tif (input?.subjectAltNames?.some(subjectAltNameHasIdentity) === true) {\n\t\treturn;\n\t}\n\tconst criticalCustomSan = input?.customExtensions?.some(\n\t\t(extension) =>\n\t\t\toidEquals(extension.oid, OIDS.subjectAltName) &&\n\t\t\textension.critical === true &&\n\t\t\tcustomSubjectAltNameHasIdentity(extension.value),\n\t);\n\tif (criticalCustomSan === true) {\n\t\treturn;\n\t}\n\tthrowExtensionEncoderError(\n\t\t'empty_subject_requires_subject_alt_name',\n\t\t'An empty subject requires a critical subjectAltName extension',\n\t);\n}\n\n/**\n * Canonical OID equality: matches even when arcs carry redundant leading zeros.\n *\n * Both sides must be encodable. Callers run after `assertCustomExtensionsValid`,\n * which rejects an OID that cannot be canonicalized.\n */\nfunction oidEquals(candidate: string, known: string): boolean {\n\treturn candidate === known || canonicalizeOid(candidate) === canonicalizeOid(known);\n}\n\n/** First customExtensions value whose OID canonically matches `oid`. */\nfunction findCustomExtensionValue(\n\tinput: CertificateExtensionsInput | undefined,\n\toid: string,\n): Uint8Array | undefined {\n\treturn input?.customExtensions?.find((extension) => oidEquals(extension.oid, oid))?.value;\n}\n\n/** The subset of a DistributionPointName the RFC 5280 §4.2.1.13 rules read. */\ntype ProfileDistributionPointName<TRelativeName> =\n\t| { readonly type: 'fullName'; readonly fullName: readonly GeneralName[] }\n\t| { readonly type: 'relativeName'; readonly relativeName: TRelativeName };\n\n/** The subset of a distribution point the RFC 5280 §4.2.1.13 rules read. */\ninterface ProfileDistributionPoint<TRelativeName> {\n\t/** Where to fetch the CRL. */\n\treadonly distributionPoint?: ProfileDistributionPointName<TRelativeName>;\n\t/** Entity that signed the CRL, when different from the certificate issuer. */\n\treadonly crlIssuer?: readonly GeneralName[];\n}\n\n/**\n * Rejects a custom extension carrying a known OID whose payload is not the DER\n * that OID's schema defines, and a known extension offered in the wrong context.\n *\n * Runs before every cross-field guard so the effective-value resolvers below can\n * decode a custom payload without having to tolerate failure.\n */\nfunction assertCustomExtensionsValid(\n\tinput: CertificateExtensionsInput | undefined,\n\tcontext: ExtensionRegistryContext,\n): void {\n\tfor (const extension of input?.customExtensions ?? []) {\n\t\tconst oid = validateOid(extension.oid);\n\t\tconst definition = getExtensionDefinition(oid);\n\t\tif (definition === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (!definition.contexts.includes(context)) {\n\t\t\tthrowExtensionEncoderError(\n\t\t\t\t'extension_not_supported_in_context',\n\t\t\t\t`Extension ${extension.oid} is not supported in ${context} context`,\n\t\t\t);\n\t\t}\n\t\tassertKnownExtensionPayload(\n\t\t\tdefinition,\n\t\t\tnew Uint8Array(extension.value),\n\t\t\textension.critical ?? false,\n\t\t\textension.oid,\n\t\t);\n\t}\n}\n\n/**\n * Decode a custom payload once through its known OID's definition and apply that\n * extension's profile rules to the decoded value and its criticality.\n *\n * A profile violation already carries its own code and propagates unchanged; a\n * decode failure means the payload is not the DER the OID's schema defines.\n */\nfunction assertKnownExtensionPayload(\n\tdefinition: {\n\t\treadonly oid: string;\n\t\tassertDerProfile(valueDer: Uint8Array, critical: boolean): void;\n\t},\n\tvalue: Uint8Array,\n\tcritical: boolean,\n\tsubmittedOid: string,\n): void {\n\ttry {\n\t\tdefinition.assertDerProfile(value, critical);\n\t} catch (error) {\n\t\tif (isResultError(error)) {\n\t\t\tthrow error;\n\t\t}\n\t\tthrowExtensionEncoderError(\n\t\t\t'malformed_known_extension_value',\n\t\t\t`Custom extension ${submittedOid} does not decode as ${definition.oid}`,\n\t\t);\n\t}\n}\n\n/** Effective basicConstraints across the typed field and any custom-known extension. */\nfunction resolveEffectiveBasicConstraints(\n\tinput: CertificateExtensionsInput | undefined,\n): BasicConstraints | undefined {\n\tif (input?.basicConstraints !== undefined) {\n\t\treturn input.basicConstraints;\n\t}\n\tconst custom = findCustomExtensionValue(input, OIDS.basicConstraints);\n\treturn custom === undefined ? undefined : BASIC_CONSTRAINTS_EXTENSION_DEFINITION.decode(custom);\n}\n\n/** Effective keyUsage flags across the typed field and any custom-known extension. */\nfunction resolveEffectiveKeyUsage(\n\tinput: CertificateExtensionsInput | undefined,\n): readonly KeyUsage[] | undefined {\n\tif (input?.keyUsage !== undefined) {\n\t\treturn input.keyUsage;\n\t}\n\tconst custom = findCustomExtensionValue(input, OIDS.keyUsage);\n\treturn custom === undefined ? undefined : KEY_USAGE_EXTENSION_DEFINITION.decode(custom).flags;\n}\n\n/** Whether a typed GeneralName carries a non-empty identity value. */\nfunction subjectAltNameHasIdentity(name: SubjectAltName): boolean {\n\tswitch (name.type) {\n\t\tcase 'directoryName':\n\t\t\treturn name.derHex.length > 0;\n\t\tcase 'krb5PrincipalName':\n\t\t\treturn name.realm.length > 0 || name.nameString.length > 0;\n\t\tdefault:\n\t\t\treturn name.value.length > 0;\n\t}\n}\n\n/** Whether a custom subjectAltName value decodes to at least one non-empty GeneralName. */\nfunction customSubjectAltNameHasIdentity(value: Uint8Array): boolean {\n\treturn SUBJECT_ALT_NAME_EXTENSION_DEFINITION.decode(value).some(subjectAltNameHasIdentity);\n}\n\nfunction appendConstraintExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n\tincludeBasicConstraints: boolean,\n): void {\n\tassertPathLengthKeyUsage(input);\n\tassertCaBasicConstraintsCritical(input);\n\tif (includeBasicConstraints && input.basicConstraints !== undefined) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tBASIC_CONSTRAINTS_EXTENSION_DEFINITION,\n\t\t\tinput.basicConstraints,\n\t\t);\n\t}\n\tif (input.keyUsage !== undefined && input.keyUsage.length > 0) {\n\t\tpushKnownExtension(encoded, seen, KEY_USAGE_EXTENSION_DEFINITION, input.keyUsage);\n\t}\n\tif (input.nameConstraints !== undefined) {\n\t\tpushKnownExtension(encoded, seen, NAME_CONSTRAINTS_EXTENSION_DEFINITION, input.nameConstraints);\n\t}\n}\n\nfunction appendIdentityExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n\tsubjectIsEmpty: boolean,\n): void {\n\tif (input.subjectAltNames !== undefined && input.subjectAltNames.length > 0) {\n\t\t// RFC 5280 §4.2.1.6: SAN MUST be critical when subject DN is empty.\n\t\tconst sanCritical = subjectIsEmpty ? true : undefined;\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tSUBJECT_ALT_NAME_EXTENSION_DEFINITION,\n\t\t\tinput.subjectAltNames,\n\t\t\tsanCritical,\n\t\t);\n\t}\n\tif (input.extendedKeyUsage !== undefined && input.extendedKeyUsage.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tEXTENDED_KEY_USAGE_EXTENSION_DEFINITION,\n\t\t\tinput.extendedKeyUsage,\n\t\t);\n\t}\n}\n\n/** Appends configured certificate-policy extensions while enforcing unique OIDs. */\nfunction appendPolicyExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n): void {\n\tif (input.certificatePolicies !== undefined && input.certificatePolicies.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tCERTIFICATE_POLICIES_EXTENSION_DEFINITION,\n\t\t\tinput.certificatePolicies,\n\t\t);\n\t}\n\tif (input.policyMappings !== undefined && input.policyMappings.length > 0) {\n\t\tpushKnownExtension(encoded, seen, POLICY_MAPPINGS_EXTENSION_DEFINITION, input.policyMappings);\n\t}\n\tif (input.policyConstraints !== undefined) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tPOLICY_CONSTRAINTS_EXTENSION_DEFINITION,\n\t\t\tinput.policyConstraints,\n\t\t);\n\t}\n\tif (input.inhibitAnyPolicy !== undefined) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tINHIBIT_ANY_POLICY_EXTENSION_DEFINITION,\n\t\t\tinput.inhibitAnyPolicy,\n\t\t);\n\t}\n}\n\nfunction appendAccessExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n): void {\n\tif (input.authorityInfoAccess !== undefined && input.authorityInfoAccess.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tAUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION,\n\t\t\tinput.authorityInfoAccess,\n\t\t);\n\t}\n\tif (input.crlDistributionPoints !== undefined && input.crlDistributionPoints.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tCRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION,\n\t\t\tinput.crlDistributionPoints,\n\t\t);\n\t}\n\tif (input.noRevAvail === true) {\n\t\tpushKnownExtension(encoded, seen, NO_REV_AVAIL_EXTENSION_DEFINITION, true);\n\t}\n}\n\n/** Push each custom extension. Context and payload were checked by `assertCustomExtensionsValid`. */\nfunction appendCustomExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n): void {\n\tfor (const extension of input.customExtensions ?? []) {\n\t\tpushExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\textension.oid,\n\t\t\tnew Uint8Array(extension.value),\n\t\t\textension.critical ?? false,\n\t\t);\n\t}\n}\n\n/** Encode a known extension via its registry definition and push it. */\nfunction pushKnownExtension<TParsed, TInput>(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tdefinition: ExtensionDefinition<TParsed, TInput>,\n\tvalue: TInput,\n\tcritical = definition.defaultCritical,\n): void {\n\tpushExtension(encoded, seen, definition.oid, definition.encode(value), critical);\n}\n\n/**\n * Encode a single X.509 Extension SEQUENCE (OID + optional critical BOOLEAN + OCTET STRING).\n *\n * @param oid Dotted-decimal extension OID.\n * @param extnValue DER-encoded extension payload.\n * @param critical Whether to mark the extension as critical. Default `false`.\n */\nexport function encodeExtension(oid: string, extnValue: Uint8Array, critical = false): Uint8Array {\n\tvalidateOid(oid);\n\tconst fields = [objectIdentifier(oid)];\n\tif (critical) {\n\t\tfields.push(bool(true));\n\t}\n\tfields.push(octetString(extnValue));\n\treturn sequence(fields);\n}\n\n/**\n * DER-encode a {@linkcode BasicConstraints} value.\n *\n * @param input CA flag and optional pathLength.\n * @returns DER SEQUENCE suitable for wrapping in an Extension OCTET STRING.\n */\nexport function encodeBasicConstraints(input: BasicConstraints): Uint8Array {\n\tconst fields: Uint8Array[] = [];\n\tif (input.ca) {\n\t\tfields.push(bool(true));\n\t}\n\tif (input.pathLength !== undefined) {\n\t\tif (!input.ca) {\n\t\t\tthrowExtensionEncoderError(\n\t\t\t\t'path_length_requires_ca',\n\t\t\t\t'basicConstraints pathLength requires ca = true',\n\t\t\t);\n\t\t}\n\t\tfields.push(integerFromNumber(input.pathLength));\n\t}\n\treturn sequence(fields);\n}\n\n/**\n * DER-encode a Key Usage BIT STRING from an array of {@linkcode KeyUsage} flags.\n *\n * @param usages Flags to set in the bit string.\n */\nexport function encodeKeyUsage(usages: readonly KeyUsage[]): Uint8Array {\n\treturn encodeKeyUsageExtension(usages);\n}\n\nfunction encodeIa5Content(value: string): Uint8Array {\n\ttry {\n\t\treturn ia5Bytes(value);\n\t} catch {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_ia5_string',\n\t\t\t'Invalid IA5String: contains non-ASCII characters',\n\t\t);\n\t}\n}\n\n/** RFC 5280 §4.2.1.6: reject an empty GeneralName string value (empty dNSName, rfc822Name, URI, or SRV name). */\nfunction requireNonEmptyName(value: string): string {\n\tif (value.length === 0) {\n\t\tthrowExtensionEncoderError('empty_general_name_value', 'GeneralName value must not be empty');\n\t}\n\treturn value;\n}\n\n/**\n * RFC 9598 §3: a SmtpUTF8Mailbox carries no Byte Order Mark, is used only when\n * the Local-part holds a non-ASCII character, and stores its domain as\n * lowercase A-labels and NR-LDH labels.\n */\nfunction assertSmtpUtf8Mailbox(value: string): string {\n\tconst at = requireNonEmptyName(value).lastIndexOf('@');\n\tconst localPart = at > 0 ? value.slice(0, at) : '';\n\tconst domain = toAsciiDomain(value.slice(at + 1));\n\tif (\n\t\tlocalPart.length === 0 ||\n\t\tvalue.includes('\\ufeff') ||\n\t\t!isMailboxDomain(domain, 'registration')\n\t) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_smtp_utf8_mailbox',\n\t\t\t'SmtpUTF8Mailbox must be Local-part@Domain with no Byte Order Mark and a domain of lowercase A-labels and NR-LDH labels',\n\t\t);\n\t}\n\tif (![...localPart].some((character) => (character.codePointAt(0) ?? 0) > 0x7f)) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'smtp_utf8_mailbox_ascii_local_part',\n\t\t\t'A mailbox with an ASCII Local-part must use rfc822Name (type email)',\n\t\t);\n\t}\n\tif (!isSmtpUtf8LocalPart(localPart)) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_smtp_utf8_mailbox',\n\t\t\t'SmtpUTF8Mailbox Local-part must be an RFC 6531 Dot-string or Quoted-string',\n\t\t);\n\t}\n\treturn `${localPart}@${domain}`;\n}\n\n/**\n * @internal A decoded SAN or IAN entry of a custom extension, which is emitted\n * as given: the typed builder's rules, with a SmtpUTF8Mailbox domain already\n * stored in A-labels.\n */\nexport function assertStoredSubjectAltName(name: SubjectAltName): void {\n\tencodeSubjectAltName(name);\n\tif (name.type === 'smtpUtf8Mailbox' && assertSmtpUtf8Mailbox(name.value) !== name.value) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_smtp_utf8_mailbox',\n\t\t\t'SmtpUTF8Mailbox domain must be stored as lowercase A-labels and NR-LDH labels',\n\t\t);\n\t}\n}\n\n/** RFC 5891 §4: the domain with each U-label converted to its A-label and each A-label checked. */\nfunction toAsciiDomain(domain: string): string {\n\tconst converted = domainToAscii(domain, 'registration');\n\tif (!converted.ok) {\n\t\treturn throwExtensionEncoderError(\n\t\t\t'invalid_idn',\n\t\t\t`Domain name is not valid IDNA2008 (${converted.reason})`,\n\t\t);\n\t}\n\treturn converted.value;\n}\n\n/** 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. */\nfunction requireRelativeDomain(domain: string): string {\n\tif (domain.endsWith('.')) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'domain_trailing_dot',\n\t\t\t'A dNSName or rfc822Name domain must not end in \".\" (RFC 5280 §4.2.1.6)',\n\t\t);\n\t}\n\treturn domain;\n}\n\n/** A dNSName or dNSName constraint with its leading `*.` or `.` kept and its domain in A-labels. */\nfunction toAsciiDnsName(value: string): string {\n\tconst prefix = value.startsWith('*.') ? '*.' : value.startsWith('.') ? '.' : '';\n\treturn `${prefix}${toAsciiDomain(requireRelativeDomain(value.slice(prefix.length)))}`;\n}\n\n/**\n * RFC 4985 §3: a SRVName or SRVName restriction with its label separators\n * normalized, its `_Service` label kept, and its Name in A-labels.\n */\nfunction toAsciiSrvComponents(value: string): string {\n\tconst normalized = normalizeLabelSeparators(value);\n\tconst dot = normalized.indexOf('.');\n\tif (!normalized.startsWith('_')) {\n\t\treturn toAsciiDomain(normalized);\n\t}\n\tif (dot < 0) {\n\t\treturn normalized;\n\t}\n\tconst name = normalized.slice(dot + 1);\n\treturn `${normalized.slice(0, dot + 1)}${name.length === 0 ? '' : toAsciiDomain(name)}`;\n}\n\n/** RFC 4985 §2 and RFC 6335 §5.1: a presented SRVName is `_Service.Name`. */\nfunction toAsciiSrvName(value: string): string {\n\tconst ascii = toAsciiSrvComponents(value);\n\tif (parsePresentedSrvName(ascii) === undefined) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_srv_name',\n\t\t\t'A SRVName is _Service.Name with an RFC 6335 service and an LDH Name (RFC 4985 §2)',\n\t\t);\n\t}\n\treturn ascii;\n}\n\n/** RFC 4985 §4: a SRVName constraint is `_Service.Name`, `_Service`, or `Name`. */\nfunction toAsciiSrvNameConstraint(value: string): string {\n\tconst ascii = toAsciiSrvComponents(value);\n\tif (parseSrvNameRestriction(ascii) === undefined) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_srv_name_constraint',\n\t\t\t'A SRVName constraint is _Service.Name, _Service, or Name (RFC 4985 §4)',\n\t\t);\n\t}\n\treturn ascii;\n}\n\n/** RFC 4120 §5.2.1 KerberosString content: IA5String characters in a GeneralString, without code-extension controls. */\nfunction kerberosString(value: string, field: string): Uint8Array {\n\tconst outside = (unit: number) => unit > 0x7f || unit === 0x0e || unit === 0x0f || unit === 0x1b;\n\tif ([...value].some((character) => outside(character.codePointAt(0) ?? 0))) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_krb5_principal_name',\n\t\t\t`KRB5PrincipalName ${field} must hold IA5String characters other than SO, SI and ESC (RFC 4120 §5.2.1)`,\n\t\t);\n\t}\n\treturn tlv(0x1b, new TextEncoder().encode(value));\n}\n\n/** RFC 4120 §5.2.4 Int32 as a DER-minimal two's-complement INTEGER. */\nfunction int32(value: number): Uint8Array {\n\tif (!Number.isInteger(value) || value < -2147483648 || value > 2147483647) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_krb5_principal_name',\n\t\t\t'KRB5PrincipalName nameType must be an Int32 (RFC 4120 §5.2.4)',\n\t\t);\n\t}\n\tconst octets: number[] = [];\n\tlet rest = value;\n\tdo {\n\t\toctets.unshift(rest & 0xff);\n\t\trest >>= 8;\n\t} while (!(rest === 0 && (octets[0] ?? 0) < 0x80) && !(rest === -1 && (octets[0] ?? 0) >= 0x80));\n\treturn tlv(0x02, Uint8Array.from(octets));\n}\n\n/** RFC 4556 §3.2.2 KRB5PrincipalName in the EXPLICIT tagging of RFC 4120's module. */\nfunction encodeKrb5PrincipalName(\n\tname: Extract<SubjectAltName, { readonly type: 'krb5PrincipalName' }>,\n): Uint8Array {\n\tif (name.realm.includes('\\0')) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_krb5_principal_name',\n\t\t\t'KRB5PrincipalName realm must not contain NUL (RFC 4120 §5.2.2)',\n\t\t);\n\t}\n\treturn sequence([\n\t\texplicitContext(0, kerberosString(name.realm, 'realm')),\n\t\texplicitContext(\n\t\t\t1,\n\t\t\tsequence([\n\t\t\t\texplicitContext(0, int32(name.nameType)),\n\t\t\t\texplicitContext(\n\t\t\t\t\t1,\n\t\t\t\t\tsequence(name.nameString.map((component) => kerberosString(component, 'nameString'))),\n\t\t\t\t),\n\t\t\t]),\n\t\t),\n\t]);\n}\n\n/** An otherName type-id that has no dedicated {@linkcode SubjectAltName} variant. */\nfunction validateOtherNameTypeId(typeId: string): string {\n\tconst oid = validateOid(typeId);\n\tif (oid === OIDS.idOnDnsSrv || oid === OIDS.idOnSmtpUtf8Mailbox) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'other_name_type_id_has_variant',\n\t\t\t`otherName type-id ${oid} is encoded through its dedicated SubjectAltName variant`,\n\t\t);\n\t}\n\treturn oid;\n}\n\nfunction requireGeneralNameContent(\n\telement: Uint8Array,\n\tform: 'x400Address' | 'ediPartyName',\n\tcheck: (element: Uint8Array) => GeneralNameContentCheck,\n): Uint8Array {\n\tconst result = check(element);\n\tif (!result.ok) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_general_name_content',\n\t\t\tresult.reason === 'unsupported'\n\t\t\t\t? `${form} contents use an encoding micro509 cannot validate`\n\t\t\t\t: `${form} contents do not match the ${form === 'x400Address' ? 'ORAddress' : 'EDIPartyName'} ASN.1 (RFC 5280)`,\n\t\t);\n\t}\n\treturn element;\n}\n\nfunction requireSingleDerElement(value: Uint8Array): Uint8Array {\n\tconst verdict = checkStrictDer(value);\n\tif (verdict !== 'valid') {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_other_name_value',\n\t\t\tverdict === 'unsupported'\n\t\t\t\t? 'otherName value uses an encoding micro509 cannot validate'\n\t\t\t\t: 'otherName value must be exactly one DER element',\n\t\t);\n\t}\n\treturn value;\n}\n\n/** RFC 9549 §2.5: an rfc822Name or rfc822Name constraint with its host in A-labels. */\nfunction toAsciiMailbox(value: string): string {\n\tconst at = value.lastIndexOf('@');\n\treturn at < 0\n\t\t? toAsciiDnsName(value)\n\t\t: `${value.slice(0, at + 1)}${toAsciiDomain(requireRelativeDomain(value.slice(at + 1)))}`;\n}\n\n/**\n * DER-encode a single {@linkcode SubjectAltName} GeneralName element.\n *\n * @param value The SAN entry to encode.\n */\nexport function encodeSubjectAltName(value: SubjectAltName): Uint8Array {\n\tswitch (value.type) {\n\t\tcase 'dns':\n\t\t\treturn implicitPrimitiveContext(\n\t\t\t\t2,\n\t\t\t\tencodeIa5Content(toAsciiDnsName(requireNonEmptyName(value.value))),\n\t\t\t);\n\t\tcase 'email':\n\t\t\treturn implicitPrimitiveContext(\n\t\t\t\t1,\n\t\t\t\tencodeIa5Content(toAsciiMailbox(requireNonEmptyName(value.value))),\n\t\t\t);\n\t\tcase 'uri':\n\t\t\treturn implicitPrimitiveContext(6, encodeIa5Content(requireNonEmptyName(value.value)));\n\t\tcase 'srv':\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes([\n\t\t\t\t\tobjectIdentifier(OIDS.idOnDnsSrv),\n\t\t\t\t\texplicitContext(\n\t\t\t\t\t\t0,\n\t\t\t\t\t\ttlv(0x16, encodeIa5Content(toAsciiSrvName(requireNonEmptyName(value.value)))),\n\t\t\t\t\t),\n\t\t\t\t]),\n\t\t\t);\n\t\tcase 'smtpUtf8Mailbox':\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes([\n\t\t\t\t\tobjectIdentifier(OIDS.idOnSmtpUtf8Mailbox),\n\t\t\t\t\texplicitContext(0, utf8String(assertSmtpUtf8Mailbox(value.value))),\n\t\t\t\t]),\n\t\t\t);\n\t\tcase 'upn':\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes([\n\t\t\t\t\tobjectIdentifier(OIDS.ntPrincipalName),\n\t\t\t\t\texplicitContext(0, utf8String(requireNonEmptyName(value.value))),\n\t\t\t\t]),\n\t\t\t);\n\t\tcase 'krb5PrincipalName':\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes([\n\t\t\t\t\tobjectIdentifier(OIDS.idPkinitSan),\n\t\t\t\t\texplicitContext(0, encodeKrb5PrincipalName(value)),\n\t\t\t\t]),\n\t\t\t);\n\t\tcase 'ip':\n\t\t\treturn implicitPrimitiveContext(7, encodeIpAddress(value.value));\n\t\tcase 'directoryName':\n\t\t\treturn implicitConstructedContext(4, readDirectoryNameTlv(value.derHex));\n\t\tcase 'otherName': {\n\t\t\tconst typeId = validateOtherNameTypeId(value.typeId);\n\t\t\tconst element = requireSingleDerElement(value.value);\n\t\t\tif (typedOtherName(typeId, element, readRootElement(element)) !== undefined) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'other_name_type_id_has_variant',\n\t\t\t\t\t`otherName type-id ${typeId} with this value is encoded through its dedicated SubjectAltName variant`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes([objectIdentifier(typeId), explicitContext(0, element)]),\n\t\t\t);\n\t\t}\n\t\tcase 'x400Address':\n\t\t\treturn requireGeneralNameContent(\n\t\t\t\timplicitConstructedContext(3, value.value),\n\t\t\t\t'x400Address',\n\t\t\t\tcheckOrAddress,\n\t\t\t);\n\t\tcase 'ediPartyName':\n\t\t\treturn requireGeneralNameContent(\n\t\t\t\timplicitConstructedContext(5, value.value),\n\t\t\t\t'ediPartyName',\n\t\t\t\tcheckEdiPartyName,\n\t\t\t);\n\t\tcase 'registeredID':\n\t\t\treturn implicitPrimitiveContext(\n\t\t\t\t8,\n\t\t\t\treadRootElement(objectIdentifier(validateOid(value.value))).value,\n\t\t\t);\n\t\tcase 'unknown':\n\t\t\tif (!GENERAL_NAME_WIRE_TAGS.has(value.tag)) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'invalid_general_name_tag',\n\t\t\t\t\t`Invalid GeneralName tag: ${value.tag}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn tlv(value.tag, value.value);\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = value;\n\t\t\tthrow new Error(`Unhandled SubjectAltName type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/**\n * DER-encode an Extended Key Usage SEQUENCE OF OIDs.\n *\n * @param usages EKU purposes to encode.\n */\nexport function encodeExtendedKeyUsage(usages: readonly ExtendedKeyUsage[]): Uint8Array {\n\tif (usages.length === 0) {\n\t\tthrowExtensionEncoderError('extended_key_usage_empty', 'extendedKeyUsage must not be empty');\n\t}\n\treturn sequence(usages.map((usage) => objectIdentifier(getExtendedKeyUsageOid(usage))));\n}\n\n/**\n * DER-encode an Authority Information Access SEQUENCE.\n *\n * @param entries AIA entries (OCSP, caIssuers, or custom) to encode.\n */\nexport function encodeAuthorityInfoAccess(\n\tentries: readonly AuthorityInformationAccessInput[],\n): Uint8Array {\n\tassertAuthorityInfoAccessProfile(entries);\n\treturn sequence(\n\t\tentries.map((entry) =>\n\t\t\tsequence([\n\t\t\t\tobjectIdentifier(getAuthorityInfoAccessMethodOid(entry.method)),\n\t\t\t\tencodeSubjectAltName(entry.location),\n\t\t\t]),\n\t\t),\n\t);\n}\n\n/**\n * @internal RFC 5280 §4.2.2.1 and RFC 6960 §3.1 rules for Authority Information\n * Access: at least one entry, and an id-ad-ocsp location that is a URI.\n *\n * The method OID is resolved before the URI check so a custom-OID wrapper cannot\n * smuggle a non-URI OCSP location past the input union.\n */\nexport function assertAuthorityInfoAccessProfile(\n\tentries: readonly AuthorityInformationAccess[],\n): void {\n\tif (entries.length === 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'authority_info_access_empty',\n\t\t\t'authorityInfoAccess must not be empty',\n\t\t);\n\t}\n\tfor (const entry of entries) {\n\t\tconst methodOid = getAuthorityInfoAccessMethodOid(entry.method);\n\t\tif (methodOid === OIDS.ocspAccessMethod && entry.location.type !== 'uri') {\n\t\t\tthrowExtensionEncoderError(\n\t\t\t\t'authority_info_access_ocsp_not_uri',\n\t\t\t\t'authorityInfoAccess OCSP location must be a URI',\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * DER-encode a CRL Distribution Points SEQUENCE.\n *\n * @param points Distribution points to encode.\n */\nexport function encodeCrlDistributionPoints(points: readonly DistributionPoint[]): Uint8Array {\n\tassertCrlDistributionPointsProfile(points);\n\treturn sequence(points.map((point) => sequence(encodeDistributionPoint(point))));\n}\n\n/**\n * @internal RFC 5280 §4.2.1.13 profile rules for a CRLDistributionPoints value,\n * stated over the fields a typed {@linkcode DistributionPoint} and a decoded\n * `ParsedDistributionPoint` share.\n *\n * `TRelativeName` differs between the two: builder input carries an unencoded RDN,\n * a decoded point carries the parsed one. The rules only read its presence.\n */\nexport function assertCrlDistributionPointsProfile<TRelativeName>(\n\tpoints: readonly ProfileDistributionPoint<TRelativeName>[],\n): void {\n\tif (points.length === 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'crl_distribution_points_empty',\n\t\t\t'cRLDistributionPoints must not be empty',\n\t\t);\n\t}\n\tfor (const point of points) {\n\t\tassertDistributionPointProfile(point);\n\t}\n}\n\n/** RFC 5280 §4.2.1.13 rules for one distribution point. */\nfunction assertDistributionPointProfile<TRelativeName>(\n\tpoint: ProfileDistributionPoint<TRelativeName>,\n): void {\n\tif (point.crlIssuer !== undefined && point.crlIssuer.length === 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'distribution_point_crl_issuer_empty',\n\t\t\t'DistributionPoint crlIssuer must not be empty',\n\t\t);\n\t}\n\tif (point.distributionPoint === undefined && point.crlIssuer === undefined) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'distribution_point_empty',\n\t\t\t'DistributionPoint must contain distributionPoint or crlIssuer',\n\t\t);\n\t}\n\tassertCrlIssuerDistinguishedNames(point);\n\tif (\n\t\tpoint.distributionPoint?.type === 'fullName' &&\n\t\tpoint.distributionPoint.fullName.length === 0\n\t) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'distribution_point_full_name_empty',\n\t\t\t'DistributionPointName fullName must not be empty',\n\t\t);\n\t}\n}\n\n/**\n * DER-encode a Name Constraints extension value.\n *\n * @param constraints Permitted and/or excluded subtrees.\n */\nexport function encodeNameConstraints(constraints: NameConstraints): Uint8Array {\n\tassertNameConstraintsProfile(constraints);\n\tconst parts: Uint8Array[] = [];\n\tif (constraints.permittedSubtrees !== undefined && constraints.permittedSubtrees.length > 0) {\n\t\tparts.push(\n\t\t\timplicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes(constraints.permittedSubtrees.map(encodeGeneralSubtree)),\n\t\t\t),\n\t\t);\n\t}\n\tif (constraints.excludedSubtrees !== undefined && constraints.excludedSubtrees.length > 0) {\n\t\tparts.push(\n\t\t\timplicitConstructedContext(\n\t\t\t\t1,\n\t\t\t\tconcatBytes(constraints.excludedSubtrees.map(encodeGeneralSubtree)),\n\t\t\t),\n\t\t);\n\t}\n\treturn sequence(parts);\n}\n\n/**\n * @internal RFC 5280 fixes the criticality of several extensions: nameConstraints\n * (§4.2.1.10), policyConstraints (§4.2.1.11), and inhibitAnyPolicy (§4.2.1.14) are\n * critical; authorityKeyIdentifier (§4.2.1.1), subjectKeyIdentifier (§4.2.1.2),\n * and authorityInfoAccess (§4.2.2.1) are not.\n *\n * @param label Extension name quoted in the diagnostic.\n * @param required The criticality RFC 5280 mandates.\n * @param critical The criticality the caller asked for.\n */\nexport function assertExtensionCriticality(\n\tlabel: string,\n\trequired: boolean,\n\tcritical: boolean,\n): void {\n\tif (critical === required) {\n\t\treturn;\n\t}\n\tthrowExtensionEncoderError(\n\t\trequired ? 'extension_must_be_critical' : 'extension_must_be_non_critical',\n\t\t`The ${label} extension must be marked ${required ? 'critical' : 'non-critical'}`,\n\t);\n}\n\n/**\n * @internal RFC 5280 §4.2.1.10: a nameConstraints extension states at least one\n * of permittedSubtrees and excludedSubtrees, and neither may be an empty set.\n */\nexport function assertNameConstraintsProfile(constraints: {\n\treadonly permittedSubtrees?: readonly unknown[];\n\treadonly excludedSubtrees?: readonly unknown[];\n}): void {\n\tconst permitted = constraints.permittedSubtrees?.length ?? 0;\n\tconst excluded = constraints.excludedSubtrees?.length ?? 0;\n\tif (permitted === 0 && excluded === 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'name_constraints_empty',\n\t\t\t'nameConstraints must set permittedSubtrees or excludedSubtrees',\n\t\t);\n\t}\n}\n\n/**\n * DER-encode a Certificate Policies extension value.\n *\n * @param policies Non-empty array of policy information entries.\n */\nexport function encodeCertificatePolicies(policies: CertificatePolicies): Uint8Array {\n\tif (policies.length === 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'certificate_policies_empty',\n\t\t\t'certificatePolicies must not be empty',\n\t\t);\n\t}\n\tconst seen = new Set<string>();\n\tfor (const policy of policies) {\n\t\tconst key = validatePolicyOid(policy.policyIdentifier);\n\t\tif (seen.has(key)) {\n\t\t\tthrowExtensionEncoderError(\n\t\t\t\t'duplicate_policy_oid',\n\t\t\t\t`Duplicate certificate policy OID: ${policy.policyIdentifier}`,\n\t\t\t);\n\t\t}\n\t\tseen.add(key);\n\t}\n\treturn sequence(policies.map(encodePolicyInformation));\n}\n\n/**\n * DER-encode a Policy Mappings extension value.\n *\n * @param mappings Non-empty array of issuer-to-subject policy pairs. Neither OID may be anyPolicy.\n */\nexport function encodePolicyMappings(mappings: PolicyMappings): Uint8Array {\n\tif (mappings.length === 0) {\n\t\tthrowExtensionEncoderError('policy_mappings_empty', 'policyMappings must not be empty');\n\t}\n\treturn sequence(\n\t\tmappings.map((mapping) => {\n\t\t\tconst issuerDomainPolicy = validatePolicyOid(mapping.issuerDomainPolicy);\n\t\t\tconst subjectDomainPolicy = validatePolicyOid(mapping.subjectDomainPolicy);\n\t\t\tif (issuerDomainPolicy === OIDS.anyPolicy || subjectDomainPolicy === OIDS.anyPolicy) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'policy_mappings_any_policy',\n\t\t\t\t\t'policyMappings must not use anyPolicy',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn sequence([\n\t\t\t\tobjectIdentifier(mapping.issuerDomainPolicy),\n\t\t\t\tobjectIdentifier(mapping.subjectDomainPolicy),\n\t\t\t]);\n\t\t}),\n\t);\n}\n\n/**\n * DER-encode a Policy Constraints extension value.\n *\n * @param constraints At least one of `requireExplicitPolicy` or `inhibitPolicyMapping` must be set.\n */\nexport function encodePolicyConstraints(constraints: PolicyConstraints): Uint8Array {\n\tconst fields: Uint8Array[] = [];\n\tif (constraints.requireExplicitPolicy !== undefined) {\n\t\tfields.push(\n\t\t\timplicitPrimitiveContext(0, encodeIntegerContent(constraints.requireExplicitPolicy)),\n\t\t);\n\t}\n\tif (constraints.inhibitPolicyMapping !== undefined) {\n\t\tfields.push(\n\t\t\timplicitPrimitiveContext(1, encodeIntegerContent(constraints.inhibitPolicyMapping)),\n\t\t);\n\t}\n\tif (fields.length === 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'policy_constraints_empty',\n\t\t\t'policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping',\n\t\t);\n\t}\n\treturn sequence(fields);\n}\n\n/**\n * DER-encode an Inhibit anyPolicy extension value (single INTEGER).\n *\n * @param input The skipCerts threshold.\n */\nexport function encodeInhibitAnyPolicy(input: InhibitAnyPolicy): Uint8Array {\n\treturn integerFromNumber(input.skipCerts);\n}\n\n/** DER-encode a single PolicyInformation SEQUENCE. */\nfunction encodePolicyInformation(policy: PolicyInformation): Uint8Array {\n\tvalidatePolicyOid(policy.policyIdentifier);\n\tconst fields = [objectIdentifier(policy.policyIdentifier)];\n\tif (policy.policyQualifiers !== undefined && policy.policyQualifiers.length > 0) {\n\t\tfields.push(sequence(policy.policyQualifiers.map(encodePolicyQualifierInfo)));\n\t}\n\treturn sequence(fields);\n}\n\n/** DER-encode a single PolicyQualifierInfo SEQUENCE. */\nfunction encodePolicyQualifierInfo(qualifier: PolicyQualifierInfo): Uint8Array {\n\tswitch (qualifier.type) {\n\t\tcase 'cps':\n\t\t\treturn sequence([objectIdentifier(OIDS.cpsPolicyQualifier), ia5String(qualifier.uri)]);\n\t\tcase 'userNotice':\n\t\t\treturn sequence([\n\t\t\t\tobjectIdentifier(OIDS.userNoticePolicyQualifier),\n\t\t\t\tencodeUserNoticePolicyQualifierInfo(qualifier),\n\t\t\t]);\n\t\tcase 'oid': {\n\t\t\tvalidateOid(qualifier.oid);\n\t\t\tconst encodedOid = objectIdentifier(qualifier.oid);\n\t\t\tconst canonicalOid = toHex(encodedOid);\n\t\t\tif (\n\t\t\t\tcanonicalOid === toHex(objectIdentifier(OIDS.cpsPolicyQualifier)) ||\n\t\t\t\tcanonicalOid === toHex(objectIdentifier(OIDS.userNoticePolicyQualifier))\n\t\t\t) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'reserved_policy_qualifier_oid',\n\t\t\t\t\t'Policy qualifier must use the typed cps or userNotice variant, not a built-in OID',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn sequence([encodedOid, new Uint8Array(qualifier.qualifierDer)]);\n\t\t}\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = qualifier;\n\t\t\tthrow new Error(`Unhandled PolicyQualifierInfo type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/** DER-encode a UserNotice qualifier SEQUENCE. */\nfunction assertDisplayText(value: string): void {\n\tif (hasLoneSurrogate(value)) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'display_text_lone_surrogate',\n\t\t\t'DisplayText must not hold a lone UTF-16 surrogate',\n\t\t);\n\t}\n\tconst length = [...value].length;\n\tif (length === 0 || length > 200) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'display_text_out_of_range',\n\t\t\t'DisplayText must be 1 to 200 characters',\n\t\t);\n\t}\n}\n\nfunction encodeUserNoticePolicyQualifierInfo(qualifier: UserNoticePolicyQualifierInfo): Uint8Array {\n\tconst fields: Uint8Array[] = [];\n\tif (qualifier.noticeRef !== undefined) {\n\t\tfields.push(encodePolicyNoticeReference(qualifier.noticeRef));\n\t}\n\tif (qualifier.explicitText !== undefined) {\n\t\tassertDisplayText(qualifier.explicitText);\n\t\tfields.push(encodeExplicitText(qualifier.explicitText, qualifier.explicitTextType));\n\t}\n\treturn sequence(fields);\n}\n\n/**\n * RFC 6818 §3, replacing the explicitText paragraph of RFC 5280 §4.2.1.4:\n * UTF8String is preferred, VisibleString and BMPString are acceptable,\n * IA5String is forbidden, control characters should not appear, and UTF8String\n * and BMPString text should be in Unicode normalization form C.\n */\nfunction encodeExplicitText(text: string, type: DisplayTextType = 'utf8String'): Uint8Array {\n\tif ([...text].some(isControlCharacter)) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'display_text_control_character',\n\t\t\t'explicitText must not contain control characters',\n\t\t);\n\t}\n\tswitch (type) {\n\t\tcase 'utf8String':\n\t\t\tassertNormalizationFormC(text);\n\t\t\treturn utf8String(text);\n\t\tcase 'bmpString':\n\t\t\tassertNormalizationFormC(text);\n\t\t\treturn encodeBmpDisplayText(text);\n\t\tcase 'visibleString':\n\t\t\treturn encodeVisibleDisplayText(text);\n\t\tcase 'ia5String':\n\t\t\treturn throwExtensionEncoderError(\n\t\t\t\t'display_text_ia5_string',\n\t\t\t\t'explicitText must not be encoded as IA5String',\n\t\t\t);\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = type;\n\t\t\tthrow new Error(`Unhandled DisplayText type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\nfunction isControlCharacter(character: string): boolean {\n\tconst codePoint = character.codePointAt(0) ?? 0;\n\treturn codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f);\n}\n\nfunction assertNormalizationFormC(text: string): void {\n\tif (text.normalize('NFC') !== text) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'display_text_not_nfc',\n\t\t\t'explicitText must be in Unicode normalization form C',\n\t\t);\n\t}\n}\n\nfunction encodeVisibleDisplayText(text: string): Uint8Array {\n\ttry {\n\t\treturn visibleString(text);\n\t} catch {\n\t\treturn throwExtensionEncoderError(\n\t\t\t'invalid_visible_string',\n\t\t\t'VisibleString explicitText must be printable ASCII',\n\t\t);\n\t}\n}\n\nfunction encodeBmpDisplayText(text: string): Uint8Array {\n\ttry {\n\t\treturn bmpString(text);\n\t} catch {\n\t\treturn throwExtensionEncoderError(\n\t\t\t'invalid_bmp_string',\n\t\t\t'BMPString explicitText must hold Basic Multilingual Plane characters other than surrogates, U+FFFE and U+FFFF',\n\t\t);\n\t}\n}\n\n/** DER-encode a NoticeReference SEQUENCE. */\nfunction encodePolicyNoticeReference(reference: PolicyNoticeReference): Uint8Array {\n\tassertDisplayText(reference.organization);\n\treturn sequence([\n\t\tutf8String(reference.organization),\n\t\tsequence(reference.noticeNumbers.map((noticeNumber) => integerFromNumber(noticeNumber))),\n\t]);\n}\n\n/** Encode an INTEGER and return only the content bytes (no TLV wrapper). */\nfunction encodeIntegerContent(value: number): Uint8Array {\n\treturn readElement(integerFromNumber(value)).value;\n}\n\n/** DER-encode a GeneralSubtree SEQUENCE (base name only; min/max omitted per RFC 5280). */\nfunction encodeGeneralSubtree(subtree: GeneralSubtree): Uint8Array {\n\treturn sequence([encodeNameConstraintForm(subtree.base)]);\n}\n\n/**\n * RFC 5280 §4.2.1.13: cRLIssuer, when present, only contains the CRL issuer's\n * distinguished name; nameRelativeToCRLIssuer additionally requires exactly one.\n *\n * Applies to a typed {@linkcode DistributionPoint} and to a decoded\n * {@linkcode ParsedDistributionPoint} alike, so the rule holds whether the value\n * arrives through `crlDistributionPoints` or through `customExtensions`.\n */\nfunction assertCrlIssuerDistinguishedNames<TRelativeName>(\n\tpoint: ProfileDistributionPoint<TRelativeName>,\n): void {\n\tif (point.crlIssuer === undefined) {\n\t\treturn;\n\t}\n\tif (point.crlIssuer.some((name) => name.type !== 'directoryName')) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'distribution_point_crl_issuer_not_directory_name',\n\t\t\t'DistributionPoint cRLIssuer must only contain directoryName entries',\n\t\t);\n\t}\n\tif (point.distributionPoint?.type === 'relativeName' && point.crlIssuer.length > 1) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'distribution_point_relative_name_multiple_crl_issuers',\n\t\t\t'DistributionPointName relativeName requires at most one cRLIssuer distinguished name',\n\t\t);\n\t}\n}\n\n/** DER-encode the fields of a single DistributionPoint, already profile-checked. */\nfunction encodeDistributionPoint(point: DistributionPoint): Uint8Array[] {\n\tconst fields: Uint8Array[] = [];\n\tif (point.distributionPoint !== undefined) {\n\t\tfields.push(\n\t\t\timplicitConstructedContext(0, encodeDistributionPointName(point.distributionPoint)),\n\t\t);\n\t}\n\tif (point.reasons !== undefined && point.reasons.length > 0) {\n\t\tfields.push(\n\t\t\timplicitPrimitiveContext(1, encodeDistributionPointReasonFlagsContent(point.reasons)),\n\t\t);\n\t}\n\tif (point.crlIssuer !== undefined) {\n\t\tfields.push(\n\t\t\timplicitConstructedContext(2, concatBytes(point.crlIssuer.map(encodeSubjectAltName))),\n\t\t);\n\t}\n\treturn fields;\n}\n\n/** DER-encode a DistributionPointName (fullName or relativeName). */\nfunction encodeDistributionPointName(name: DistributionPointName): Uint8Array {\n\tswitch (name.type) {\n\t\tcase 'fullName': {\n\t\t\tif (name.fullName.length === 0) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'distribution_point_full_name_empty',\n\t\t\t\t\t'DistributionPointName fullName must not be empty',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn implicitConstructedContext(0, concatBytes(name.fullName.map(encodeSubjectAltName)));\n\t\t}\n\t\tcase 'relativeName': {\n\t\t\tconst relativeName = encodeRelativeDistinguishedName(name.relativeName);\n\t\t\tconst relativeNameElement = readElement(relativeName);\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t1,\n\t\t\t\trelativeName.slice(relativeNameElement.start, relativeNameElement.end),\n\t\t\t);\n\t\t}\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = name;\n\t\t\tthrow new Error(`Unhandled DistributionPointName type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/** DER-encode a NameConstraintForm as an implicit-tagged {@linkcode GeneralName}. */\nfunction encodeNameConstraintForm(form: NameConstraintForm): Uint8Array {\n\tswitch (form.type) {\n\t\tcase 'dns':\n\t\t\treturn implicitPrimitiveContext(2, encodeIa5Content(toAsciiDnsName(form.value)));\n\t\tcase 'email':\n\t\t\tif (form.value.includes('@')) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'email_name_constraint_names_mailbox',\n\t\t\t\t\t'An rfc822Name constraint names a host or a domain, not a particular mailbox (RFC 9549 §2.2)',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn implicitPrimitiveContext(1, encodeIa5Content(toAsciiMailbox(form.value)));\n\t\tcase 'uri':\n\t\t\tif (parseUriNameConstraint(form.value) === undefined) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'invalid_uri_name_constraint',\n\t\t\t\t\t'A uniformResourceIdentifier constraint is a fully qualified domain name, with a leading period for its subdomains (RFC 5280 §4.2.1.10)',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn implicitPrimitiveContext(6, encodeIa5Content(form.value));\n\t\tcase 'ip': {\n\t\t\tconst total = form.addressBytes.length + form.maskBytes.length;\n\t\t\tif (form.addressBytes.length !== form.maskBytes.length || (total !== 8 && total !== 32)) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'invalid_ip_name_constraint',\n\t\t\t\t\t'IP name constraint must be 8 octets (IPv4) or 32 octets (IPv6)',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn implicitPrimitiveContext(7, concatBytes([form.addressBytes, form.maskBytes]));\n\t\t}\n\t\tcase 'directoryName':\n\t\t\treturn implicitConstructedContext(4, readDirectoryNameTlv(form.derHex));\n\t\tcase 'srv':\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes([\n\t\t\t\t\tobjectIdentifier(OIDS.idOnDnsSrv),\n\t\t\t\t\texplicitContext(0, tlv(0x16, encodeIa5Content(toAsciiSrvNameConstraint(form.value)))),\n\t\t\t\t]),\n\t\t\t);\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = form;\n\t\t\tthrow new Error(`Unhandled NameConstraintForm type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/** Returns the complete Name TLV from a hex-encoded DER SEQUENCE, validating the root tag. */\nfunction readDirectoryNameTlv(derHex: string): Uint8Array {\n\tconst bytes = hexToBytes(derHex);\n\tconst element = readRootElement(bytes, { maxDepth: DEFAULT_MAX_DER_DEPTH });\n\tif (element.tag !== 0x30) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'directory_name_not_sequence',\n\t\t\t'directoryName derHex must encode a DER SEQUENCE',\n\t\t);\n\t}\n\treturn bytes.slice(element.start - element.headerLength, element.end);\n}\n\n/**\n * Resolve an {@linkcode ExtendedKeyUsage} to its dotted-decimal OID.\n *\n * @param usage Well-known string or custom OID object.\n */\nexport function getExtendedKeyUsageOid(usage: ExtendedKeyUsage): string {\n\tif (typeof usage === 'string') {\n\t\treturn EXTENDED_KEY_USAGE_OIDS[usage];\n\t}\n\treturn validateOid(usage.value);\n}\n\n/**\n * Map a dotted-decimal OID to an {@linkcode ExtendedKeyUsage} value.\n *\n * Returns a well-known string for recognized OIDs, or `{ type: 'oid', value }` otherwise.\n */\nexport function parseExtendedKeyUsageOid(oid: string): ExtendedKeyUsage {\n\tswitch (oid) {\n\t\tcase OIDS.serverAuth:\n\t\t\treturn 'serverAuth';\n\t\tcase OIDS.clientAuth:\n\t\t\treturn 'clientAuth';\n\t\tcase OIDS.codeSigning:\n\t\t\treturn 'codeSigning';\n\t\tcase OIDS.emailProtection:\n\t\t\treturn 'emailProtection';\n\t\tcase OIDS.timeStamping:\n\t\t\treturn 'timeStamping';\n\t\tcase OIDS.ocspSigning:\n\t\t\treturn 'ocspSigning';\n\t}\n\treturn { type: 'oid', value: oid };\n}\n\n/**\n * Resolve an {@linkcode AuthorityInfoAccessMethod} to its dotted-decimal OID.\n *\n * @param method Well-known string or custom OID object.\n */\nexport function getAuthorityInfoAccessMethodOid(method: AuthorityInfoAccessMethod): string {\n\tif (typeof method === 'string') {\n\t\treturn AUTHORITY_INFO_ACCESS_METHOD_OIDS[method];\n\t}\n\treturn validateOid(method.value);\n}\n\n/**\n * Map a dotted-decimal OID to an {@linkcode AuthorityInfoAccessMethod} value.\n *\n * Returns `'ocsp'` or `'caIssuers'` for recognized OIDs, or `{ type: 'oid', value }` otherwise.\n */\nexport function parseAuthorityInfoAccessMethodOid(oid: string): AuthorityInfoAccessMethod {\n\tswitch (oid) {\n\t\tcase OIDS.ocspAccessMethod:\n\t\t\treturn 'ocsp';\n\t\tcase OIDS.caIssuersAccessMethod:\n\t\t\treturn 'caIssuers';\n\t}\n\treturn { type: 'oid', value: oid };\n}\n\n/** Parse a dotted-decimal/colon-hex IP string to raw address bytes. */\nfunction encodeIpAddress(input: string): Uint8Array {\n\treturn parseIpAddressToBytes(input);\n}\n\n/**\n * Computes a key identifier from a DER `SubjectPublicKeyInfo` using method (1)\n * of RFC 5280 §4.2.1.2: \"the 160-bit SHA-1 hash of the value of the BIT STRING\n * subjectPublicKey (excluding the tag, length, and number of unused bits)\".\n * A parsed certificate carries the input as `subjectPublicKeyInfoDer`.\n */\nexport function buildSubjectKeyIdentifier(subjectPublicKeyInfo: Uint8Array): Uint8Array {\n\tconst topLevel = readSequenceChildren(subjectPublicKeyInfo);\n\tconst subjectPublicKey = topLevel[1];\n\tif (subjectPublicKey === undefined || subjectPublicKey.tag !== 0x03) {\n\t\tthrow new Error('SPKI missing subject public key bit string');\n\t}\n\tconst publicKeyBytes = subjectPublicKey.value.slice(1);\n\treturn sha1(publicKeyBytes);\n}\n\n/**\n * The key identifier a certificate or CRL issued by `issuer` carries in its\n * authority key identifier: the issuer's subject key identifier (RFC 5280\n * §4.2.1.2, §5.2.1), or a method (1) identifier over its public key when it\n * has none (§4.2.1.1).\n */\nexport function issuerKeyIdentifier(issuer: ParsedCertificate): Uint8Array {\n\treturn issuer.subjectKeyIdentifier === undefined\n\t\t? buildSubjectKeyIdentifier(issuer.subjectPublicKeyInfoDer)\n\t\t: hexToBytes(issuer.subjectKeyIdentifier);\n}\n\n/**\n * Throw if the string is not an encodable dotted-decimal OID, and return its\n * canonical spelling.\n *\n * Syntax alone is not enough. X.660 bounds the first arc to 0, 1, or 2 and the\n * second to under 40 beneath arcs 0 and 1, so `3.1` and `1.40` parse as decimals\n * yet cannot be encoded.\n */\nfunction validateOid(oid: string): string {\n\tif (!/^\\d+(?:\\.\\d+)+$/.test(oid)) {\n\t\tthrowExtensionEncoderError('invalid_oid', `Invalid OID: ${oid}`);\n\t}\n\ttry {\n\t\treturn canonicalizeOid(oid);\n\t} catch (error) {\n\t\trethrowDecodeRefusal(error, DECODE_REFUSAL_CODES);\n\t\tthrowExtensionEncoderError('invalid_oid', `Invalid OID: ${oid}`);\n\t}\n}\n\n/** Validate a policy OID and return its canonical spelling. */\nfunction validatePolicyOid(oid: string): string {\n\treturn validateOid(oid);\n}\n\n/**\n * Encode and push an extension, rejecting duplicate OIDs.\n *\n * Duplicate identity is the canonical OID, because two spellings that differ only\n * by leading zeros in an arc encode to the same wire bytes. The diagnostic quotes\n * the OID as submitted, which is the string the caller can find in their input.\n */\nfunction pushExtension(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\toid: string,\n\tvalue: Uint8Array,\n\tcritical = false,\n): void {\n\tconst identity = validateOid(oid);\n\tif (seen.has(identity)) {\n\t\tthrowExtensionEncoderError('duplicate_extension_oid', `Duplicate extension OID: ${oid}`);\n\t}\n\tseen.add(identity);\n\tencoded.push(encodeExtension(oid, value, critical));\n}\n\nexport {\n\tallOnesMaskForIpAddress,\n\tdecodeIpAddress,\n\tnormalizeIpAddress,\n\tparseIpAddressToBytes,\n} from '#micro509/internal/shared/ip';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAw0BA,MAAMC,KAAiE;CACtE,YAAYC,EAAK;CACjB,YAAYA,EAAK;CACjB,aAAaA,EAAK;CAClB,iBAAiBA,EAAK;CACtB,cAAcA,EAAK;CACnB,aAAaA,EAAK;AACnB,GAGMC,KAAoF;CACzF,MAAMD,EAAK;CACX,WAAWA,EAAK;AACjB;;;;;;;;;;;;;;;AAgBA,SAAgB,2BACf,GACA,GACA,GACA,IAAiB,IACF;CAOf,AANA,4BAA4BE,GAAO,aAAa,GAC5CC,KACH,4CAA4CD,CAAK,GAElD,yBAAyBA,CAAK,GAC9B,wBAAwBE,GAAsBF,CAAK,GACnD,wBAAwBA,CAAK;CA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AO;EAAE,MAAM;EAAO,OAAOwB;CAAI;AAClC;;AAGA,SAAS,gBAAgB,GAA2B;CACnD,OAAO2H,EAAsBjJ,CAAK;AACnC;;;;;;;AAQA,SAAgB,0BAA0B,GAA8C;CAEvF,IAAMkJ,IADW7H,EAAqBnB,CACN,CAAC,CAAC;CAClC,IAAIgJ,MAAqB,KAAA,KAAaA,EAAiB,QAAQ,GAC9D,MAAU,MAAM,4CAA4C;CAE7D,IAAMC,IAAiBD,EAAiB,MAAM,MAAM,CAAC;CACrD,OAAOE,GAAKD,CAAc;AAC3B;;;;;;;AAQA,SAAgB,oBAAoB,GAAuC;CAC1E,OAAOE,EAAO,yBAAyB,KAAA,IACpC,0BAA0BA,EAAO,uBAAuB,IACxDP,EAAWO,EAAO,oBAAoB;AAC1C;;;;;;;;;AAUA,SAAS,YAAY,GAAqB;CACzC,AAAK,kBAAkB,KAAK/H,CAAG,KAC9BT,EAA2B,eAAe,gBAAgBS,GAAK;CAEhE,IAAI;EACH,OAAOU,EAAgBV,CAAG;CAC3B,SAASgB,GAAO;EAEf,AADAgH,EAAqBhH,GAAOiH,EAAoB,GAChD1I,EAA2B,eAAe,gBAAgBS,GAAK;CAChE;AACD;;AAGA,SAAS,kBAAkB,GAAqB;CAC/C,OAAO,YAAYA,CAAG;AACvB;;;;;;;;AASA,SAAS,cACR,GACA,GACA,GACA,GACA,IAAW,IACJ;CACP,IAAMkI,IAAW,YAAYlI,CAAG;CAKhC,AAJIlB,EAAK,IAAIoJ,CAAQ,KACpB3I,EAA2B,2BAA2B,4BAA4BS,GAAK,GAExFlB,EAAK,IAAIoJ,CAAQ,GACjB9I,EAAQ,KAAK,gBAAgBY,GAAKc,GAAOC,CAAQ,CAAC;AACnD"}
1
+ {"version":3,"file":"extensions.js","names":["_exhaustive","canonicalizeOid","checkStrictDer","childrenOf","decodeObjectIdentifier","hexToBytes","toHex","rethrowDecodeRefusal","bmpString","bool","concatBytes","explicitContext","hasLoneSurrogate","ia5Bytes","ia5String","implicitConstructedContext","implicitPrimitiveContext","integerFromNumber","objectIdentifier","octetString","readElement","readRootElement","readSequenceChildren","sequence","tlv","utf8String","visibleString","OIDS","sha1","domainToAscii","allOnesMaskForIpAddress","decodeIpAddress","normalizeIpAddress","parseIpAddressToBytes","isMailboxDomain","isSmtpUtf8LocalPart","encodeDistributionPointReasonFlagsContent","encodeKeyUsageExtension","throwExtensionEncoderError","AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION","AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION","BASIC_CONSTRAINTS_EXTENSION_DEFINITION","CERTIFICATE_POLICIES_EXTENSION_DEFINITION","CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION","EXTENDED_KEY_USAGE_EXTENSION_DEFINITION","INHIBIT_ANY_POLICY_EXTENSION_DEFINITION","KEY_USAGE_EXTENSION_DEFINITION","NAME_CONSTRAINTS_EXTENSION_DEFINITION","NO_REV_AVAIL_EXTENSION_DEFINITION","POLICY_CONSTRAINTS_EXTENSION_DEFINITION","POLICY_MAPPINGS_EXTENSION_DEFINITION","SUBJECT_ALT_NAME_EXTENSION_DEFINITION","SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION","getExtensionDefinition","typedOtherName","checkEdiPartyName","checkOrAddress","normalizeLabelSeparators","parsePresentedSrvName","parseSrvNameRestriction","parseUriNameConstraint","GENERAL_NAME_WIRE_TAGS","DECODE_REFUSAL_CODES","isResultError","encodeRelativeDistinguishedName","EXTENDED_KEY_USAGE_OIDS","AUTHORITY_INFO_ACCESS_METHOD_OIDS","subjectPublicKeyInfo","authorityKeyIdentifier","input","subjectIsEmpty","extensions","seen","basicConstraints","encoded","options","keyUsage","EDWARDS_END_ENTITY_KEY_USAGE","EDWARDS_FORBIDDEN_KEY_USAGE","MONTGOMERY_FORBIDDEN_KEY_USAGE","algorithm","asserted","flag","isCertificationAuthority","oid","custom","extension","entry","conflict","candidate","known","context","definition","value","critical","submittedOid","error","name","includeBasicConstraints","sanCritical","extnValue","fields","usages","at","localPart","domain","character","converted","prefix","normalized","dot","ascii","field","unit","octets","rest","component","typeId","element","form","check","result","verdict","usage","entries","points","point","constraints","parts","label","required","permitted","excluded","policies","policy","key","mappings","mapping","issuerDomainPolicy","subjectDomainPolicy","qualifier","encodedOid","canonicalOid","length","text","type","codePoint","reference","noticeNumber","subtree","relativeName","relativeNameElement","total","derHex","bytes","method","subjectPublicKey","publicKeyBytes","issuer","identity"],"sources":["../../src/x509/extensions.ts"],"sourcesContent":["/**\n * Typed certificate and CSR extension model plus ASN.1 encoder helpers.\n *\n * Defines input types for every supported X.509v3 extension (RFC 5280) and\n * the DER encoders consumed by certificate and CSR builder flows.\n *\n * @module\n */\n\nimport {\n\tcanonicalizeOid,\n\tcheckStrictDer,\n\tchildrenOf,\n\tdecodeObjectIdentifier,\n\thexToBytes,\n\ttoHex,\n} from '#micro509/internal/asn1/asn1';\nimport { DECODE_REFUSAL_CODES, rethrowDecodeRefusal } from '#micro509/internal/asn1/decode-refusal';\nimport {\n\tbmpString,\n\tbool,\n\tconcatBytes,\n\tDEFAULT_MAX_DER_DEPTH,\n\texplicitContext,\n\thasLoneSurrogate,\n\tia5Bytes,\n\tia5String,\n\timplicitConstructedContext,\n\timplicitPrimitiveContext,\n\tintegerFromNumber,\n\tobjectIdentifier,\n\toctetString,\n\treadElement,\n\treadRootElement,\n\treadSequenceChildren,\n\tsequence,\n\ttlv,\n\tutf8String,\n\tvisibleString,\n} from '#micro509/internal/asn1/der';\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport { sha1 } from '#micro509/internal/crypto/hash';\nimport { domainToAscii } from '#micro509/internal/shared/idna';\nimport { parseIpAddressToBytes } from '#micro509/internal/shared/ip';\nimport { isMailboxDomain, isSmtpUtf8LocalPart } from '#micro509/internal/shared/mailbox';\nimport {\n\tencodeDistributionPointReasonFlagsContent,\n\tencodeKeyUsageExtension,\n} from '#micro509/internal/x509/extension-bits';\nimport { throwExtensionEncoderError } from '#micro509/internal/x509/extension-errors';\nimport type {\n\tExtensionDefinition,\n\tExtensionRegistryContext,\n} from '#micro509/internal/x509/extension-registry';\nimport {\n\tAUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION,\n\tAUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n\tBASIC_CONSTRAINTS_EXTENSION_DEFINITION,\n\tCERTIFICATE_POLICIES_EXTENSION_DEFINITION,\n\tCRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION,\n\tEXTENDED_KEY_USAGE_EXTENSION_DEFINITION,\n\tgetExtensionDefinition,\n\tINHIBIT_ANY_POLICY_EXTENSION_DEFINITION,\n\tKEY_USAGE_EXTENSION_DEFINITION,\n\tNAME_CONSTRAINTS_EXTENSION_DEFINITION,\n\tNO_REV_AVAIL_EXTENSION_DEFINITION,\n\tPOLICY_CONSTRAINTS_EXTENSION_DEFINITION,\n\tPOLICY_MAPPINGS_EXTENSION_DEFINITION,\n\tSUBJECT_ALT_NAME_EXTENSION_DEFINITION,\n\tSUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n} from '#micro509/internal/x509/extension-registry';\nimport { typedOtherName } from '#micro509/internal/x509/general-name';\nimport type { GeneralNameContentCheck } from '#micro509/internal/x509/general-name-profile';\nimport {\n\tcheckEdiPartyName,\n\tcheckOrAddress,\n\tnormalizeLabelSeparators,\n\tparsePresentedSrvName,\n\tparseSrvNameRestriction,\n\tparseUriNameConstraint,\n} from '#micro509/internal/x509/general-name-profile';\nimport { GENERAL_NAME_WIRE_TAGS } from '#micro509/internal/x509/general-name-tags';\nimport { isResultError } from '#micro509/result/result';\nimport type { RelativeDistinguishedNameInput } from '#micro509/x509/name';\nimport { encodeRelativeDistinguishedName } from '#micro509/x509/name';\nimport type { ParsedCertificate } from '#micro509/x509/parse';\n\nexport type { ExtensionEncoderErrorCode } from '#micro509/internal/x509/extension-errors';\nexport type {\n\tNameAttribute,\n\tNameFieldKey,\n\tRelativeDistinguishedNameInput,\n} from '#micro509/x509/name';\n\n/**\n * A decoded BIT STRING flag set.\n *\n * `flags` contains the recognized flag values with any non-zero padding bits\n * masked out. `nonZeroPadding` is `true` when the original BIT STRING encoding\n * had non-zero bits in positions that DER ({@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690 §11.2.1}) requires to be zero.\n * Extension flag decoding rejects such encodings, so parsed extension values\n * always report `false`.\n */\nexport interface ParsedBitFlags<T extends string> {\n\t/** Decoded flag values, padding bits masked. */\n\treadonly flags: readonly T[];\n\t/** `true` when the original encoding had non-zero padding bits (DER violation). */\n\treadonly nonZeroPadding: boolean;\n}\n\n/**\n * RFC 5280 §4.2.1.3 Key Usage bit flag.\n *\n * Each value corresponds to one bit in the KeyUsage BIT STRING.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.3 RFC 5280 §4.2.1.3}\n */\nexport type KeyUsage =\n\t| 'digitalSignature'\n\t| 'nonRepudiation'\n\t| 'keyEncipherment'\n\t| 'dataEncipherment'\n\t| 'keyAgreement'\n\t| 'keyCertSign'\n\t| 'cRLSign'\n\t| 'encipherOnly'\n\t| 'decipherOnly';\n\n/**\n * RFC 5280 §4.2.1.6 Subject Alternative Name / GeneralName.\n *\n * Discriminated union keyed on `type`.\n *\n * Every GeneralName alternative has a typed variant. Parsing never produces\n * `'unknown'`, which remains as raw builder input.\n */\nexport type SubjectAltName =\n\t| {\n\t\t\t/** DNS hostname (dNSName [2]). */\n\t\t\treadonly type: 'dns';\n\t\t\t/** Fully-qualified domain name, e.g. `\"example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** IP address (iPAddress [7]). */\n\t\t\treadonly type: 'ip';\n\t\t\t/** Dotted-decimal IPv4 or colon-hex IPv6 string. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** Email address (rfc822Name [1]). */\n\t\t\treadonly type: 'email';\n\t\t\t/** RFC 2821 §4.1.2 Mailbox (`Local-part@Domain`), e.g. `\"admin@example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** URI (uniformResourceIdentifier [6]). */\n\t\t\treadonly type: 'uri';\n\t\t\t/** Absolute URI string. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** SRV-ID otherName (id-on-dnsSRV). */\n\t\t\treadonly type: 'srv';\n\t\t\t/** SRV service name, e.g. `\"_imaps.example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** SmtpUTF8Mailbox otherName (id-on-SmtpUTF8Mailbox, RFC 9598 §3). */\n\t\t\treadonly type: 'smtpUtf8Mailbox';\n\t\t\t/** Internationalized mailbox whose domain is in A-labels, e.g. `\"用户@example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** User principal name otherName (szOID_NT_PRINCIPAL_NAME, [MS-WCCE] §2.2.2.7.5), a UTF8String. */\n\t\t\treadonly type: 'upn';\n\t\t\t/** User principal name, e.g. `\"user@example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** Kerberos principal name otherName (id-pkinit-san, RFC 4556 §3.2.2). */\n\t\t\treadonly type: 'krb5PrincipalName';\n\t\t\t/** Kerberos realm, e.g. `\"EXAMPLE.COM\"`. */\n\t\t\treadonly realm: string;\n\t\t\t/** RFC 4120 §6.2 name type, e.g. `1` for NT-PRINCIPAL. */\n\t\t\treadonly nameType: number;\n\t\t\t/** Principal name components, e.g. `[\"host\", \"www.example.com\"]`. */\n\t\t\treadonly nameString: readonly string[];\n\t }\n\t| {\n\t\t\t/** X.500 directory name (directoryName [4]). */\n\t\t\treadonly type: 'directoryName';\n\t\t\t/** Hex-encoded DER of the Name SEQUENCE. */\n\t\t\treadonly derHex: string;\n\t }\n\t| {\n\t\t\t/** otherName [0] of a type-id without a dedicated variant, or a UPN or KRB5PrincipalName value that does not fit its variant. */\n\t\t\treadonly type: 'otherName';\n\t\t\t/** Dotted-decimal type-id OID. */\n\t\t\treadonly typeId: string;\n\t\t\t/** DER of the single element inside `value [0] EXPLICIT`. */\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** X.400 O/R address (x400Address [3]). */\n\t\t\treadonly type: 'x400Address';\n\t\t\t/** Content octets of the ORAddress SEQUENCE. */\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** EDI party name (ediPartyName [5]). */\n\t\t\treadonly type: 'ediPartyName';\n\t\t\t/** Content octets of the EDIPartyName SEQUENCE. */\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** Registered identifier (registeredID [8]). */\n\t\t\treadonly type: 'registeredID';\n\t\t\t/** Dotted-decimal OID. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** Raw {@linkcode GeneralName} builder input, encoded under its wire tag. */\n\t\t\treadonly type: 'unknown';\n\t\t\t/** ASN.1 context tag number. */\n\t\t\treadonly tag: number;\n\t\t\t/** Raw content bytes of the element. */\n\t\t\treadonly value: Uint8Array;\n\t };\n\n/** Alias for {@linkcode SubjectAltName} — used where RFC 5280 says \"GeneralName\". */\nexport type GeneralName = SubjectAltName;\n\n/**\n * Revocation reason flags for CRL Distribution Points and Issuing Distribution Points\n * (RFC 5280 §4.2.1.13, §5.2.5).\n */\nexport type DistributionPointReason =\n\t| 'keyCompromise'\n\t| 'cACompromise'\n\t| 'affiliationChanged'\n\t| 'superseded'\n\t| 'cessationOfOperation'\n\t| 'certificateHold'\n\t| 'privilegeWithdrawn'\n\t| 'aACompromise';\n\n/**\n * Name component of a CRL Distribution Point, mirroring RFC 5280 §4.2.1.13\n * `DistributionPointName ::= CHOICE { fullName [0] GeneralNames,\n * nameRelativeToCRLIssuer [1] RelativeDistinguishedName }`.\n */\nexport type DistributionPointName =\n\t| {\n\t\t\t/** The `fullName [0]` alternative. */\n\t\t\treadonly type: 'fullName';\n\t\t\t/** Absolute {@linkcode GeneralName}(s) identifying the distribution point (usually a URI). */\n\t\t\treadonly fullName: readonly GeneralName[];\n\t }\n\t| {\n\t\t\t/** The `nameRelativeToCRLIssuer [1]` alternative. */\n\t\t\treadonly type: 'relativeName';\n\t\t\t/** Name relative to the issuer's DN. */\n\t\t\treadonly relativeName: RelativeDistinguishedNameInput;\n\t };\n\n/**\n * Input for a single CRL Distribution Point (RFC 5280 §4.2.1.13).\n *\n * At least one of `distributionPoint` or `crlIssuer` must be provided.\n * The union enforces this constraint at the type level.\n */\nexport type DistributionPoint =\n\t| {\n\t\t\t/** Where to fetch the CRL (fullName or relativeName). */\n\t\t\treadonly distributionPoint: DistributionPointName;\n\t\t\t/** Revocation reason subset. Absent means all reasons. */\n\t\t\treadonly reasons?: readonly DistributionPointReason[];\n\t\t\t/** Entity that signed the CRL, when different from the cert issuer. */\n\t\t\treadonly crlIssuer?: readonly GeneralName[];\n\t }\n\t| {\n\t\t\t/** Where to fetch the CRL. Optional when `crlIssuer` is present. */\n\t\t\treadonly distributionPoint?: DistributionPointName;\n\t\t\t/** Revocation reason subset. Absent means all reasons. */\n\t\t\treadonly reasons?: readonly DistributionPointReason[];\n\t\t\t/** Entity that signed the CRL. Required when `distributionPoint` is absent. */\n\t\t\treadonly crlIssuer: readonly GeneralName[];\n\t };\n\n/** Base shape for Issuing Distribution Point (RFC 5280 §5.2.5) — no scope restriction. */\nexport interface IssuingDistributionPointBase {\n\t/** Where to fetch this CRL. */\n\treadonly distributionPoint?: DistributionPointName;\n\t/** Limits the CRL to these revocation reasons. Absent means all reasons. */\n\treadonly onlySomeReasons?: readonly DistributionPointReason[];\n\t/** When true, the CRL may contain entries from other CAs. Default false. */\n\treadonly indirectCrl?: boolean;\n\t/** Must be absent or false in this variant (no user-cert-only restriction). */\n\treadonly onlyContainsUserCerts?: false;\n\t/** Must be absent or false in this variant (no CA-cert-only restriction). */\n\treadonly onlyContainsCACerts?: false;\n\t/** When true, the CRL only covers attribute certificates. Default false. */\n\treadonly onlyContainsAttributeCerts?: boolean;\n}\n\n/** IDP scoped to end-entity (user) certificates only. Mutually exclusive with CA / attribute scopes. */\nexport interface IssuingDistributionPointForUserCerts\n\textends Omit<IssuingDistributionPointBase, 'onlyContainsUserCerts'> {\n\t/** This variant only covers end-entity certificates. */\n\treadonly onlyContainsUserCerts: true;\n\t/** Must be absent or false when the CRL is not CA-only. */\n\treadonly onlyContainsCACerts?: false;\n\t/** Must be absent or false when the CRL is not attribute-cert-only. */\n\treadonly onlyContainsAttributeCerts?: false;\n}\n\n/** IDP scoped to CA certificates only. Mutually exclusive with user / attribute scopes. */\nexport interface IssuingDistributionPointForCaCerts\n\textends Omit<IssuingDistributionPointBase, 'onlyContainsCACerts'> {\n\t/** Must be absent or false when the CRL is not user-cert-only. */\n\treadonly onlyContainsUserCerts?: false;\n\t/** This variant only covers CA certificates. */\n\treadonly onlyContainsCACerts: true;\n\t/** Must be absent or false when the CRL is not attribute-cert-only. */\n\treadonly onlyContainsAttributeCerts?: false;\n}\n\n/** IDP scoped to attribute certificates only. Mutually exclusive with user / CA scopes. */\nexport interface IssuingDistributionPointForAttributeCerts\n\textends Omit<IssuingDistributionPointBase, 'onlyContainsAttributeCerts'> {\n\t/** Must be absent or false when the CRL is not user-cert-only. */\n\treadonly onlyContainsUserCerts?: false;\n\t/** Must be absent or false when the CRL is not CA-only. */\n\treadonly onlyContainsCACerts?: false;\n\t/** This variant only covers attribute certificates. */\n\treadonly onlyContainsAttributeCerts: true;\n}\n\n/**\n * Input for the Issuing Distribution Point CRL extension (RFC 5280 §5.2.5).\n *\n * The union enforces that at most one of the `onlyContains*` flags is true.\n */\nexport type IssuingDistributionPoint =\n\t| IssuingDistributionPointBase\n\t| IssuingDistributionPointForUserCerts\n\t| IssuingDistributionPointForCaCerts\n\t| IssuingDistributionPointForAttributeCerts;\n\n/**\n * RFC 5280 §4.2.1.9 Basic Constraints.\n *\n * A certificate with `ca: true` may issue other certificates; `pathLength`\n * limits how many additional CAs may appear below it in the chain.\n */\nexport type BasicConstraints =\n\t| {\n\t\t\t/** End-entity certificate: not a CA. */\n\t\t\treadonly ca: false;\n\t\t\t/** Never present on end-entity certificates. */\n\t\t\treadonly pathLength?: undefined;\n\t }\n\t| {\n\t\t\t/** CA certificate: may issue other certificates. */\n\t\t\treadonly ca: true;\n\t\t\t/** Maximum number of intermediate CA certificates allowed below this CA. */\n\t\t\treadonly pathLength?: number;\n\t };\n\n/** A single certificate policy: an OID plus optional qualifiers. */\nexport interface PolicyInformation {\n\t/** Dotted-decimal OID of the policy (e.g. `\"2.23.140.1.2.1\"` for DV). */\n\treadonly policyIdentifier: string;\n\t/** Optional CPS URIs or user notices attached to this policy. */\n\treadonly policyQualifiers?: readonly PolicyQualifierInfo[];\n}\n\n/** RFC 5280 §4.2.1.4 — array of policy OIDs with optional qualifiers. */\nexport type CertificatePolicies = readonly {\n\t/** Dotted-decimal OID of the policy (e.g. `\"2.23.140.1.2.1\"` for DV). */\n\treadonly policyIdentifier: string;\n\t/** Optional CPS URIs or user notices attached to this policy. */\n\treadonly policyQualifiers?: readonly (\n\t\t| {\n\t\t\t\treadonly type: 'cps';\n\t\t\t\treadonly uri: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'userNotice';\n\t\t\t\treadonly noticeRef?: {\n\t\t\t\t\treadonly organization: string;\n\t\t\t\t\treadonly noticeNumbers: readonly number[];\n\t\t\t\t\t/** Present when `organization` exceeds 200 characters; the builder emits no such notice. */\n\t\t\t\t\treadonly oversizedOrganization?: OversizedDisplayText;\n\t\t\t\t};\n\t\t\t\treadonly explicitText?: string;\n\t\t\t\treadonly explicitTextType?: DisplayTextType;\n\t\t\t\t/** Present when `explicitText` exceeds 200 characters; the builder emits no such notice. */\n\t\t\t\treadonly oversizedExplicitText?: OversizedDisplayText;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'oid';\n\t\t\t\treadonly oid: string;\n\t\t\t\treadonly qualifierDer: Uint8Array;\n\t\t }\n\t)[];\n}[];\n\n/** CPS (Certification Practice Statement) URI policy qualifier. */\nexport interface CpsPolicyQualifierInfo {\n\t/** Discriminant for the `'cps'` qualifier variant. */\n\treadonly type: 'cps';\n\t/** URL of the Certification Practice Statement document. */\n\treadonly uri: string;\n}\n\n/** Reference to a numbered notice within an organization's practice statement. */\nexport interface PolicyNoticeReference {\n\t/** Organization name that published the notice. */\n\treadonly organization: string;\n\t/** One-based notice numbers within that organization's documentation. */\n\treadonly noticeNumbers: readonly number[];\n}\n\n/** UserNotice policy qualifier — human-readable notice text and/or a notice reference. */\nexport interface UserNoticePolicyQualifierInfo {\n\t/** Discriminant for the `'userNotice'` qualifier variant. */\n\treadonly type: 'userNotice';\n\t/** Pointer to a numbered notice in an organization's practice statement. */\n\treadonly noticeRef?: PolicyNoticeReference;\n\t/** Free-form text to display to relying parties. */\n\treadonly explicitText?: string;\n\t/**\n\t * ASN.1 string type carrying `explicitText`. Parsing reports the received\n\t * type. The builder defaults to `'utf8String'`, accepts `'visibleString'`\n\t * and `'bmpString'`, and rejects `'ia5String'` (RFC 6818 §3).\n\t */\n\treadonly explicitTextType?: DisplayTextType;\n}\n\n/** The ASN.1 string types RFC 5280 §4.2.1.4 allows for a DisplayText. */\nexport type DisplayTextType = 'utf8String' | 'ia5String' | 'visibleString' | 'bmpString';\n\n/**\n * A user notice `explicitText` or `noticeRef` organization longer than the 200\n * characters RFC 5280 §4.2.1.4 allows a DisplayText. Parsing keeps the text\n * whole and reports its size here.\n */\nexport interface OversizedDisplayText {\n\t/** Characters the certificate carries. */\n\treadonly characters: number;\n\t/** The RFC 5280 §4.2.1.4 upper bound, 200. */\n\treadonly limit: number;\n}\n\n/** Opaque policy qualifier identified by a custom OID, carried as raw DER. */\nexport interface CustomPolicyQualifierInfo {\n\t/** Discriminant for the custom-OID qualifier variant. */\n\treadonly type: 'oid';\n\t/** Dotted-decimal OID of the qualifier. */\n\treadonly oid: string;\n\t/** DER-encoded qualifier payload. */\n\treadonly qualifierDer: Uint8Array;\n}\n\n/** Discriminated union of all supported policy qualifier types. */\nexport type PolicyQualifierInfo =\n\t| CpsPolicyQualifierInfo\n\t| UserNoticePolicyQualifierInfo\n\t| CustomPolicyQualifierInfo;\n\n/** Maps a policy OID in the issuer's domain to an equivalent OID in the subject's domain. */\nexport interface PolicyMapping {\n\t/** Policy OID as defined by the issuing CA. Must not be anyPolicy. */\n\treadonly issuerDomainPolicy: string;\n\t/** Equivalent policy OID in the subject CA's domain. Must not be anyPolicy. */\n\treadonly subjectDomainPolicy: string;\n}\n\n/** RFC 5280 §4.2.1.5 — array of issuer-to-subject policy OID pairs. */\nexport type PolicyMappings = readonly {\n\t/** Policy OID as defined by the issuing CA. Must not be anyPolicy. */\n\treadonly issuerDomainPolicy: string;\n\t/** Equivalent policy OID in the subject CA's domain. Must not be anyPolicy. */\n\treadonly subjectDomainPolicy: string;\n}[];\n\n/**\n * RFC 5280 §4.2.1.11 Policy Constraints.\n *\n * At least one field must be present. Values are certificate-count\n * thresholds measured from the current certificate toward the end entity.\n */\nexport interface PolicyConstraints {\n\t/** After this many certificates, an acceptable policy must be in the path. */\n\treadonly requireExplicitPolicy?: number;\n\t/** After this many certificates, policy mapping is no longer allowed. */\n\treadonly inhibitPolicyMapping?: number;\n}\n\n/**\n * RFC 5280 §4.2.1.14 Inhibit anyPolicy.\n *\n * After `skipCerts` additional non-self-issued certificates in the path, the\n * special anyPolicy OID is no longer considered a match, except when it\n * appears in an intermediate self-issued CA certificate.\n */\nexport interface InhibitAnyPolicy {\n\t/** Number of additional non-self-issued certificates before anyPolicy stops being valid. */\n\treadonly skipCerts: number;\n}\n\n/**\n * Input for `createCertificate`, `createSelfSignedCertificate`,\n * and `createCertificateSigningRequest`.\n *\n * Every field is optional. Omitted extensions are not encoded. Built-in\n * extensions (SKI, AKI, basicConstraints defaults) are handled automatically\n * by the builder.\n */\nexport interface CertificateExtensionsInput {\n\t/** Subject Alternative Names (dns, ip, email, uri, srv, directoryName). */\n\treadonly subjectAltNames?: readonly SubjectAltName[];\n\t/** Key Usage flags (digitalSignature, keyCertSign, etc.). */\n\treadonly keyUsage?: readonly KeyUsage[];\n\t/** Basic Constraints (CA flag + optional pathLength). Defaults to `{ ca: false }` for certs. */\n\treadonly basicConstraints?: BasicConstraints;\n\t/** Extended Key Usage purposes (serverAuth, clientAuth, etc.). */\n\treadonly extendedKeyUsage?: readonly ExtendedKeyUsage[];\n\t/** Name Constraints — permitted and/or excluded subtrees. */\n\treadonly nameConstraints?: NameConstraints;\n\t/** Certificate Policies with optional qualifiers. */\n\treadonly certificatePolicies?: CertificatePolicies;\n\t/** Policy Mappings between issuer and subject policy domains. */\n\treadonly policyMappings?: PolicyMappings;\n\t/** Policy Constraints (requireExplicitPolicy / inhibitPolicyMapping thresholds). */\n\treadonly policyConstraints?: PolicyConstraints;\n\t/** Inhibit anyPolicy skip-certs threshold. */\n\treadonly inhibitAnyPolicy?: InhibitAnyPolicy;\n\t/** Authority Information Access — OCSP responder and CA issuer locations. */\n\treadonly authorityInfoAccess?: readonly AuthorityInformationAccessInput[];\n\t/** CRL Distribution Points — where to check revocation status. */\n\treadonly crlDistributionPoints?: readonly DistributionPoint[];\n\t/**\n\t * Emit No Revocation Available (RFC 9608 §2): the CA publishes no revocation\n\t * information for this certificate. A certificate carrying it cannot be a CA\n\t * and cannot point at a CRL or an OCSP responder (RFC 9608 §3).\n\t */\n\treadonly noRevAvail?: boolean;\n\t/** Arbitrary extensions not covered by the built-in fields. */\n\treadonly customExtensions?: readonly CustomExtension[];\n}\n\n/** An extension not covered by the typed fields in {@linkcode CertificateExtensionsInput}. */\nexport interface CustomExtension {\n\t/** Dotted-decimal OID of the extension. */\n\treadonly oid: string;\n\t/** Pre-encoded DER content for the extnValue OCTET STRING. */\n\treadonly value: Uint8Array;\n\t/** Whether the extension is critical. Default `false`. */\n\treadonly critical?: boolean;\n}\n\n// Name constraints (RFC 5280 §4.2.1.10)\n\n/**\n * A name form used as a constraint base in namEConstraints.\n * Distinct from {@linkcode SubjectAltName} because IP constraints carry\n * address + mask bytes (8 for IPv4, 32 for IPv6) rather than bare addresses.\n */\nexport type NameConstraintForm =\n\t| {\n\t\t\t/** DNS domain constraint (dNSName [2]). */\n\t\t\treadonly type: 'dns';\n\t\t\t/** Domain suffix, e.g. `\".example.com\"` or `\"example.com\"`. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** Email constraint (rfc822Name [1]). */\n\t\t\treadonly type: 'email';\n\t\t\t/** Email domain or full address pattern. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** URI constraint (uniformResourceIdentifier [6]). */\n\t\t\treadonly type: 'uri';\n\t\t\t/** Host or domain component of a URI. */\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\t/** IP range constraint (iPAddress [7]). */\n\t\t\treadonly type: 'ip';\n\t\t\t/** Network address bytes (4 for IPv4, 16 for IPv6). */\n\t\t\treadonly addressBytes: Uint8Array;\n\t\t\t/** Subnet mask bytes (same length as addressBytes). */\n\t\t\treadonly maskBytes: Uint8Array;\n\t }\n\t| {\n\t\t\t/** Directory name constraint (directoryName [4]). */\n\t\t\treadonly type: 'directoryName';\n\t\t\t/** Hex-encoded DER of the Name SEQUENCE. */\n\t\t\treadonly derHex: string;\n\t }\n\t| {\n\t\t\t/** SRVName constraint (otherName id-on-dnsSRV, RFC 4985 §4). */\n\t\t\treadonly type: 'srv';\n\t\t\t/** `_Service.Name`, `_Service`, or `Name`, e.g. `\"_mail.example.com\"`. */\n\t\t\treadonly value: string;\n\t };\n\n/**\n * Name constraint forms parsed from DER but not supported for encoding or\n * validation. Preserved for diagnostic round-tripping.\n */\nexport type UnsupportedNameConstraintForm =\n\t| {\n\t\t\t/** otherName [0] of a type-id without defined constraint semantics. */\n\t\t\treadonly type: 'otherName';\n\t\t\t/** Dotted-decimal type-id OID. */\n\t\t\treadonly typeId: string;\n\t\t\t/** DER of the single element inside `value [0] EXPLICIT`. */\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** x400Address [3] — raw bytes. */\n\t\t\treadonly type: 'x400Address';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** ediPartyName [5] — raw bytes. */\n\t\t\treadonly type: 'ediPartyName';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\t/** registeredID [8] — decoded OID string. */\n\t\t\treadonly type: 'registeredID';\n\t\t\treadonly value: string;\n\t };\n\n/** Union of supported and unsupported name constraint forms as produced by parsing. */\nexport type ParsedNameConstraintForm =\n\t| {\n\t\t\treadonly type: 'dns';\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\treadonly type: 'email';\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\treadonly type: 'uri';\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\treadonly type: 'ip';\n\t\t\treadonly addressBytes: Uint8Array;\n\t\t\treadonly maskBytes: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'directoryName';\n\t\t\treadonly derHex: string;\n\t }\n\t| {\n\t\t\treadonly type: 'srv';\n\t\t\treadonly value: string;\n\t }\n\t| {\n\t\t\treadonly type: 'otherName';\n\t\t\treadonly typeId: string;\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'x400Address';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'ediPartyName';\n\t\t\treadonly value: Uint8Array;\n\t }\n\t| {\n\t\t\treadonly type: 'registeredID';\n\t\t\treadonly value: string;\n\t };\n\n/** A single subtree entry in a Name Constraints permitted/excluded list. */\nexport interface GeneralSubtree<\n\tTForm extends ParsedNameConstraintForm =\n\t\t| {\n\t\t\t\treadonly type: 'dns';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'email';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'uri';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'ip';\n\t\t\t\treadonly addressBytes: Uint8Array;\n\t\t\t\treadonly maskBytes: Uint8Array;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'directoryName';\n\t\t\t\treadonly derHex: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'srv';\n\t\t\t\treadonly value: string;\n\t\t },\n> {\n\t/** The name form that defines this constraint boundary. */\n\treadonly base: TForm;\n}\n\n/**\n * RFC 5280 §4.2.1.10 Name Constraints.\n *\n * A CA certificate may restrict the namespace of all subject names in\n * subsequent certificates in the path.\n */\nexport interface NameConstraints<\n\tTForm extends ParsedNameConstraintForm =\n\t\t| {\n\t\t\t\treadonly type: 'dns';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'email';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'uri';\n\t\t\t\treadonly value: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'ip';\n\t\t\t\treadonly addressBytes: Uint8Array;\n\t\t\t\treadonly maskBytes: Uint8Array;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'directoryName';\n\t\t\t\treadonly derHex: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: 'srv';\n\t\t\t\treadonly value: string;\n\t\t },\n> {\n\t/** Names that MUST fall within these subtrees to be valid. */\n\treadonly permittedSubtrees?: readonly GeneralSubtree<TForm>[];\n\t/** Names that MUST NOT fall within these subtrees. Takes precedence over permitted. */\n\treadonly excludedSubtrees?: readonly GeneralSubtree<TForm>[];\n}\n\n/** Well-known AIA access methods: OCSP responder or CA issuer certificate. */\nexport type KnownAuthorityInfoAccessMethod = 'ocsp' | 'caIssuers';\n\n/** AIA access method identified by a custom OID not in the well-known set. */\nexport interface CustomAuthorityInfoAccessMethod {\n\t/** Discriminant for the custom-OID access method variant. */\n\treadonly type: 'oid';\n\t/** Dotted-decimal OID of the access method. */\n\treadonly value: string;\n}\n\n/** AIA access method — either a well-known string or a custom OID. */\nexport type AuthorityInfoAccessMethod =\n\t| KnownAuthorityInfoAccessMethod\n\t| CustomAuthorityInfoAccessMethod;\n\n/** A single entry in the Authority Information Access extension (RFC 5280 §4.2.2.1). */\nexport interface AuthorityInformationAccess {\n\t/** Access method (`'ocsp'`, `'caIssuers'`, or custom OID). */\n\treadonly method:\n\t\t| 'ocsp'\n\t\t| 'caIssuers'\n\t\t| {\n\t\t\t\treadonly type: 'oid';\n\t\t\t\treadonly value: string;\n\t\t };\n\t/** accessLocation GeneralName where the resource is available (usually a URI). */\n\treadonly location: GeneralName;\n}\n\n/**\n * Builder input for one Authority Information Access entry.\n *\n * Parsed AIA locations stay broad ({@linkcode AuthorityInformationAccess}), but\n * an `'ocsp'` entry must supply a URI location, since RFC 6960 §3.1 defines the\n * `id-ad-ocsp` location as a URI; `directoryName` is defined for `caIssuers`.\n */\nexport type AuthorityInformationAccessInput =\n\t| {\n\t\t\t/** OCSP responder access method. */\n\t\t\treadonly method: 'ocsp';\n\t\t\t/** OCSP responder URI (RFC 6960 §3.1). */\n\t\t\treadonly location: { readonly type: 'uri'; readonly value: string };\n\t }\n\t| {\n\t\t\t/** caIssuers or a custom access method. */\n\t\t\treadonly method: 'caIssuers' | CustomAuthorityInfoAccessMethod;\n\t\t\t/** Any accessLocation GeneralName. */\n\t\t\treadonly location: GeneralName;\n\t };\n\n/** Well-known Extended Key Usage purpose strings (RFC 5280 §4.2.1.12). */\nexport type KnownExtendedKeyUsage =\n\t| 'serverAuth'\n\t| 'clientAuth'\n\t| 'codeSigning'\n\t| 'emailProtection'\n\t| 'timeStamping'\n\t| 'ocspSigning';\n\n/** Extended Key Usage purpose identified by a custom OID. */\nexport interface CustomExtendedKeyUsage {\n\t/** Discriminant for the custom-OID EKU variant. */\n\treadonly type: 'oid';\n\t/** Dotted-decimal OID of the usage purpose. */\n\treadonly value: string;\n}\n\n/** Extended Key Usage — either a well-known purpose string or a custom OID. */\nexport type ExtendedKeyUsage =\n\t| 'serverAuth'\n\t| 'clientAuth'\n\t| 'codeSigning'\n\t| 'emailProtection'\n\t| 'timeStamping'\n\t| 'ocspSigning'\n\t| {\n\t\t\treadonly type: 'oid';\n\t\t\treadonly value: string;\n\t };\n\n/** Map from well-known EKU names to their dotted-decimal OIDs. */\nconst EXTENDED_KEY_USAGE_OIDS: Record<KnownExtendedKeyUsage, string> = {\n\tserverAuth: OIDS.serverAuth,\n\tclientAuth: OIDS.clientAuth,\n\tcodeSigning: OIDS.codeSigning,\n\temailProtection: OIDS.emailProtection,\n\ttimeStamping: OIDS.timeStamping,\n\tocspSigning: OIDS.ocspSigning,\n};\n\n/** Map from well-known AIA method names to their dotted-decimal OIDs. */\nconst AUTHORITY_INFO_ACCESS_METHOD_OIDS: Record<KnownAuthorityInfoAccessMethod, string> = {\n\tocsp: OIDS.ocspAccessMethod,\n\tcaIssuers: OIDS.caIssuersAccessMethod,\n};\n\n/**\n * Build the v3 extensions block for a certificate.\n *\n * Automatically adds SKI, AKI (when a key identifier is given), and\n * basicConstraints (defaults to `{ ca: false }`). Additional extensions\n * come from the caller's {@linkcode CertificateExtensionsInput}.\n *\n * @param subjectPublicKeyInfo DER-encoded SPKI of the subject.\n * @param authorityKeyIdentifier Key identifier for the AKI, or `undefined` to omit it.\n * @param input Optional extension configuration.\n * @param subjectIsEmpty Whether the certificate subject DN is empty. When `true`, a\n * subjectAltName extension is required and marked critical per RFC 5280 §4.2.1.6.\n * @returns Array of DER-encoded Extension SEQUENCEs.\n */\nexport function buildCertificateExtensions(\n\tsubjectPublicKeyInfo: Uint8Array,\n\tauthorityKeyIdentifier: Uint8Array | undefined,\n\tinput: CertificateExtensionsInput | undefined,\n\tsubjectIsEmpty = false,\n): Uint8Array[] {\n\tassertCustomExtensionsValid(input, 'certificate');\n\tif (subjectIsEmpty) {\n\t\tassertEmptySubjectHasCriticalSubjectAltName(input);\n\t}\n\tassertPathLengthKeyUsage(input);\n\tassertSafeCurveKeyUsage(subjectPublicKeyInfo, input);\n\tassertNoRevAvailProfile(input);\n\tconst extensions: Uint8Array[] = [];\n\tconst seen = new Set<string>();\n\tconst basicConstraints = input?.basicConstraints ?? { ca: false };\n\tpushKnownExtension(extensions, seen, BASIC_CONSTRAINTS_EXTENSION_DEFINITION, basicConstraints);\n\tpushKnownExtension(\n\t\textensions,\n\t\tseen,\n\t\tSUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n\t\tbuildSubjectKeyIdentifier(subjectPublicKeyInfo),\n\t);\n\tif (authorityKeyIdentifier !== undefined) {\n\t\tpushKnownExtension(\n\t\t\textensions,\n\t\t\tseen,\n\t\t\tAUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n\t\t\tauthorityKeyIdentifier,\n\t\t);\n\t}\n\tappendConfiguredExtensions(extensions, seen, input, {\n\t\tincludeBasicConstraints: false,\n\t\tsubjectIsEmpty,\n\t});\n\treturn extensions;\n}\n\n/**\n * Build the extensions for a CSR's extensionRequest attribute.\n *\n * Unlike {@linkcode buildCertificateExtensions}, SKI/AKI are not auto-generated.\n *\n * @param input Optional extension configuration.\n * @returns Array of DER-encoded Extension SEQUENCEs.\n */\nexport function buildRequestedExtensions(\n\tinput: CertificateExtensionsInput | undefined,\n): Uint8Array[] {\n\tassertCustomExtensionsValid(input, 'csr');\n\tconst extensions: Uint8Array[] = [];\n\tconst seen = new Set<string>();\n\tappendConfiguredExtensions(extensions, seen, input, { includeBasicConstraints: true });\n\treturn extensions;\n}\n\n/** Encode and push each configured extension from the input, enforcing no duplicates. */\nfunction appendConfiguredExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput | undefined,\n\toptions: {\n\t\treadonly includeBasicConstraints: boolean;\n\t\t/** When true, SAN is marked critical per RFC 5280 §4.2.1.6. */\n\t\treadonly subjectIsEmpty?: boolean;\n\t},\n): void {\n\tif (input === undefined) {\n\t\treturn;\n\t}\n\tappendConstraintExtensions(encoded, seen, input, options.includeBasicConstraints);\n\tappendIdentityExtensions(encoded, seen, input, options.subjectIsEmpty === true);\n\tappendPolicyExtensions(encoded, seen, input);\n\tappendAccessExtensions(encoded, seen, input);\n\tappendCustomExtensions(encoded, seen, input);\n}\n\n/**\n * RFC 5280 §4.2.1.9: pathLenConstraint requires the keyUsage extension to assert keyCertSign.\n * Absent, empty, or keyCertSign-less keyUsage is rejected. Known extensions supplied through\n * customExtensions participate in the effective view.\n */\nfunction assertPathLengthKeyUsage(input: CertificateExtensionsInput | undefined): void {\n\tconst basicConstraints = resolveEffectiveBasicConstraints(input);\n\tif (basicConstraints?.pathLength === undefined) {\n\t\treturn;\n\t}\n\tconst keyUsage = resolveEffectiveKeyUsage(input);\n\tif (keyUsage === undefined || keyUsage.length === 0 || !keyUsage.includes('keyCertSign')) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'path_length_requires_key_cert_sign',\n\t\t\t'basicConstraints pathLength requires the keyUsage keyCertSign bit',\n\t\t);\n\t}\n}\n\n/** RFC 9295 §3: an end-entity id-Ed25519 or id-Ed448 certificate needs one of these. */\nconst EDWARDS_END_ENTITY_KEY_USAGE = ['nonRepudiation', 'digitalSignature', 'cRLSign'] as const;\n\n/** RFC 9295 §3: bits an id-Ed25519 or id-Ed448 certificate must never assert. */\nconst EDWARDS_FORBIDDEN_KEY_USAGE = [\n\t'keyEncipherment',\n\t'dataEncipherment',\n\t'keyAgreement',\n\t'encipherOnly',\n\t'decipherOnly',\n] as const;\n\n/** RFC 9295 §3: bits an id-X25519 or id-X448 certificate must never assert. */\nconst MONTGOMERY_FORBIDDEN_KEY_USAGE = [\n\t'digitalSignature',\n\t'nonRepudiation',\n\t'keyEncipherment',\n\t'dataEncipherment',\n\t'keyCertSign',\n\t'cRLSign',\n] as const;\n\n/**\n * RFC 9295 §3, which replaces RFC 8410 §5, constrains a keyUsage extension on a\n * certificate whose subject key names one of the four 1.3.101 curves.\n *\n * id-X25519 and id-X448 require `keyAgreement`, admit one of `encipherOnly` and\n * `decipherOnly`, and forbid the rest.\n *\n * id-Ed25519 and id-Ed448 split on whether the certificate is a certification\n * authority. A CA MUST assert `keyCertSign` and MAY add `nonRepudiation`,\n * `digitalSignature`, or `cRLSign`. Any other certificate MUST assert at least\n * one of those three and MUST NOT assert `keyCertSign`. Both forbid the key\n * agreement and encipherment bits. A CRL issuer is the case where `cRLSign` is\n * the bit chosen, and a CRL issuer that is also a CA is the CA case, so the two\n * branches cover the section's four paragraphs.\n *\n * The rule binds only a keyUsage that reaches the wire, so an absent one, and an\n * empty one the builder therefore omits, leave the key unconstrained.\n */\nfunction assertSafeCurveKeyUsage(\n\tsubjectPublicKeyInfo: Uint8Array,\n\tinput: CertificateExtensionsInput | undefined,\n): void {\n\tconst keyUsage = resolveEffectiveKeyUsage(input);\n\tif (keyUsage === undefined || keyUsage.length === 0) {\n\t\treturn;\n\t}\n\tconst algorithm = readSubjectKeyAlgorithmOid(subjectPublicKeyInfo);\n\tif (algorithm === undefined) {\n\t\treturn;\n\t}\n\tif (oidEquals(algorithm, OIDS.x25519) || oidEquals(algorithm, OIDS.x448)) {\n\t\tassertMontgomeryKeyUsage(keyUsage);\n\t\treturn;\n\t}\n\tif (oidEquals(algorithm, OIDS.ed25519) || oidEquals(algorithm, OIDS.ed448)) {\n\t\tassertEdwardsKeyUsage(keyUsage, resolveEffectiveBasicConstraints(input)?.ca === true);\n\t}\n}\n\n/** The X25519 and X448 half of RFC 9295 §3. */\nfunction assertMontgomeryKeyUsage(keyUsage: readonly KeyUsage[]): void {\n\tif (!keyUsage.includes('keyAgreement')) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'montgomery_key_usage_requires_key_agreement',\n\t\t\t'keyUsage on an X25519 or X448 certificate must set keyAgreement',\n\t\t);\n\t}\n\tconst asserted = MONTGOMERY_FORBIDDEN_KEY_USAGE.filter((flag: KeyUsage) =>\n\t\tkeyUsage.includes(flag),\n\t);\n\tif (asserted.length > 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'montgomery_key_usage_forbids_signature_bit',\n\t\t\t`keyUsage on an X25519 or X448 certificate must not set ${asserted.join(', ')}`,\n\t\t);\n\t}\n\tif (keyUsage.includes('encipherOnly') && keyUsage.includes('decipherOnly')) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'montgomery_key_usage_forbids_both_cipher_bits',\n\t\t\t'keyUsage on an X25519 or X448 certificate must not set both encipherOnly and decipherOnly',\n\t\t);\n\t}\n}\n\n/** The Ed25519 and Ed448 half of RFC 9295 §3. */\nfunction assertEdwardsKeyUsage(\n\tkeyUsage: readonly KeyUsage[],\n\tisCertificationAuthority: boolean,\n): void {\n\tif (isCertificationAuthority) {\n\t\tif (!keyUsage.includes('keyCertSign')) {\n\t\t\tthrowExtensionEncoderError(\n\t\t\t\t'edwards_key_usage_requires_key_cert_sign',\n\t\t\t\t'keyUsage on an Ed25519 or Ed448 certification authority certificate must set keyCertSign',\n\t\t\t);\n\t\t}\n\t} else if (!EDWARDS_END_ENTITY_KEY_USAGE.some((flag: KeyUsage) => keyUsage.includes(flag))) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'edwards_key_usage_requires_signing_bit',\n\t\t\t`keyUsage on an Ed25519 or Ed448 certificate must set one of ${EDWARDS_END_ENTITY_KEY_USAGE.join(', ')}`,\n\t\t);\n\t}\n\tconst asserted = EDWARDS_FORBIDDEN_KEY_USAGE.filter((flag: KeyUsage) => keyUsage.includes(flag));\n\tif (asserted.length > 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'edwards_key_usage_forbids_agreement_bit',\n\t\t\t`keyUsage on an Ed25519 or Ed448 certificate must not set ${asserted.join(', ')}`,\n\t\t);\n\t}\n\tif (!isCertificationAuthority && keyUsage.includes('keyCertSign')) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'edwards_key_usage_forbids_key_cert_sign',\n\t\t\t'keyUsage on an Ed25519 or Ed448 end-entity certificate must not set keyCertSign',\n\t\t);\n\t}\n}\n\n/** The algorithm OID of a SubjectPublicKeyInfo, or `undefined` when the field is not an OID. */\nfunction readSubjectKeyAlgorithmOid(subjectPublicKeyInfo: Uint8Array): string | undefined {\n\tconst algorithm = readSequenceChildren(subjectPublicKeyInfo)[0];\n\tif (algorithm === undefined || algorithm.tag !== 0x30) {\n\t\treturn undefined;\n\t}\n\tconst oid = childrenOf(subjectPublicKeyInfo, algorithm)[0];\n\treturn oid?.tag === 0x06 ? decodeObjectIdentifier(oid.value) : undefined;\n}\n\n/**\n * RFC 5280 §4.2.1.9: basicConstraints is critical in a CA certificate whose key\n * validates signatures on certificates. Both conjuncts live in other extensions,\n * so the rule sits here rather than in the basicConstraints profile hook.\n *\n * §4.2.1.3 restricts a key only through a keyUsage extension that reaches the\n * wire, so an absent keyUsage, and an empty one the builder therefore omits,\n * leave the key free to validate certificate signatures. Only an emitted keyUsage\n * without keyCertSign takes the certificate out of the clause's scope.\n *\n * Only a custom extension can carry the wrong criticality; the typed field is\n * always emitted with the registry default.\n */\nfunction assertCaBasicConstraintsCritical(input: CertificateExtensionsInput | undefined): void {\n\tconst custom = input?.customExtensions?.find((extension) =>\n\t\toidEquals(extension.oid, OIDS.basicConstraints),\n\t);\n\tif (custom === undefined || custom.critical === true) {\n\t\treturn;\n\t}\n\tconst basicConstraints = BASIC_CONSTRAINTS_EXTENSION_DEFINITION.decode(\n\t\tnew Uint8Array(custom.value),\n\t);\n\tif (!basicConstraints.ca) {\n\t\treturn;\n\t}\n\tconst keyUsage = resolveEffectiveKeyUsage(input);\n\tconst mayValidateCertificates =\n\t\tkeyUsage === undefined || keyUsage.length === 0 || keyUsage.includes('keyCertSign');\n\tif (mayValidateCertificates) {\n\t\tassertExtensionCriticality('basicConstraints', true, false);\n\t}\n}\n\n/**\n * RFC 9608 §2 and §3: a certificate carrying noRevAvail is not a CA certificate\n * and carries no cRLDistributionPoints, no freshestCRL, and no id-ad-ocsp\n * authorityInfoAccess entry. Known extensions supplied through customExtensions\n * participate in the effective view.\n */\nfunction assertNoRevAvailProfile(input: CertificateExtensionsInput | undefined): void {\n\tif (\n\t\tinput?.noRevAvail !== true &&\n\t\tfindCustomExtensionValue(input, OIDS.noRevAvail) === undefined\n\t) {\n\t\treturn;\n\t}\n\tif (resolveEffectiveBasicConstraints(input)?.ca === true) {\n\t\tthrowNoRevAvailConflict('basicConstraints with cA TRUE');\n\t}\n\tif (\n\t\t(input?.crlDistributionPoints?.length ?? 0) > 0 ||\n\t\tfindCustomExtensionValue(input, OIDS.cRLDistributionPoints) !== undefined\n\t) {\n\t\tthrowNoRevAvailConflict('cRLDistributionPoints');\n\t}\n\tif (findCustomExtensionValue(input, OIDS.freshestCRL) !== undefined) {\n\t\tthrowNoRevAvailConflict('freshestCRL');\n\t}\n\tif (\n\t\tresolveEffectiveAuthorityInfoAccess(input).some(\n\t\t\t(entry) => getAuthorityInfoAccessMethodOid(entry.method) === OIDS.ocspAccessMethod,\n\t\t)\n\t) {\n\t\tthrowNoRevAvailConflict('an id-ad-ocsp authorityInfoAccess entry');\n\t}\n}\n\n/** The authorityInfoAccess entries the builder will emit: the typed list when non-empty, otherwise a custom-known extension. */\nfunction resolveEffectiveAuthorityInfoAccess(\n\tinput: CertificateExtensionsInput | undefined,\n): readonly (AuthorityInformationAccess | AuthorityInformationAccessInput)[] {\n\tif (input?.authorityInfoAccess !== undefined && input.authorityInfoAccess.length > 0) {\n\t\treturn input.authorityInfoAccess;\n\t}\n\tconst custom = findCustomExtensionValue(input, OIDS.authorityInfoAccess);\n\treturn custom === undefined ? [] : AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION.decode(custom);\n}\n\nfunction throwNoRevAvailConflict(conflict: string): never {\n\tthrowExtensionEncoderError(\n\t\t'no_rev_avail_conflict',\n\t\t`A certificate carrying noRevAvail must not also carry ${conflict}`,\n\t);\n}\n\n/**\n * RFC 5280 §4.2.1.6: an empty subject DN requires a subjectAltName extension\n * present, marked critical, and carrying at least one non-empty GeneralName.\n */\nfunction assertEmptySubjectHasCriticalSubjectAltName(\n\tinput: CertificateExtensionsInput | undefined,\n): void {\n\tif (input?.subjectAltNames?.some(subjectAltNameHasIdentity) === true) {\n\t\treturn;\n\t}\n\tconst criticalCustomSan = input?.customExtensions?.some(\n\t\t(extension) =>\n\t\t\toidEquals(extension.oid, OIDS.subjectAltName) &&\n\t\t\textension.critical === true &&\n\t\t\tcustomSubjectAltNameHasIdentity(extension.value),\n\t);\n\tif (criticalCustomSan === true) {\n\t\treturn;\n\t}\n\tthrowExtensionEncoderError(\n\t\t'empty_subject_requires_subject_alt_name',\n\t\t'An empty subject requires a critical subjectAltName extension',\n\t);\n}\n\n/**\n * Canonical OID equality: matches even when arcs carry redundant leading zeros.\n *\n * Both sides must be encodable. Callers run after `assertCustomExtensionsValid`,\n * which rejects an OID that cannot be canonicalized.\n */\nfunction oidEquals(candidate: string, known: string): boolean {\n\treturn candidate === known || canonicalizeOid(candidate) === canonicalizeOid(known);\n}\n\n/** First customExtensions value whose OID canonically matches `oid`. */\nfunction findCustomExtensionValue(\n\tinput: CertificateExtensionsInput | undefined,\n\toid: string,\n): Uint8Array | undefined {\n\treturn input?.customExtensions?.find((extension) => oidEquals(extension.oid, oid))?.value;\n}\n\n/** The subset of a DistributionPointName the RFC 5280 §4.2.1.13 rules read. */\ntype ProfileDistributionPointName<TRelativeName> =\n\t| { readonly type: 'fullName'; readonly fullName: readonly GeneralName[] }\n\t| { readonly type: 'relativeName'; readonly relativeName: TRelativeName };\n\n/** The subset of a distribution point the RFC 5280 §4.2.1.13 rules read. */\ninterface ProfileDistributionPoint<TRelativeName> {\n\t/** Where to fetch the CRL. */\n\treadonly distributionPoint?: ProfileDistributionPointName<TRelativeName>;\n\t/** Entity that signed the CRL, when different from the certificate issuer. */\n\treadonly crlIssuer?: readonly GeneralName[];\n}\n\n/**\n * Rejects a custom extension carrying a known OID whose payload is not the DER\n * that OID's schema defines, and a known extension offered in the wrong context.\n *\n * Runs before every cross-field guard so the effective-value resolvers below can\n * decode a custom payload without having to tolerate failure.\n */\nfunction assertCustomExtensionsValid(\n\tinput: CertificateExtensionsInput | undefined,\n\tcontext: ExtensionRegistryContext,\n): void {\n\tfor (const extension of input?.customExtensions ?? []) {\n\t\tconst oid = validateOid(extension.oid);\n\t\tconst definition = getExtensionDefinition(oid);\n\t\tif (definition === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (!definition.contexts.includes(context)) {\n\t\t\tthrowExtensionEncoderError(\n\t\t\t\t'extension_not_supported_in_context',\n\t\t\t\t`Extension ${extension.oid} is not supported in ${context} context`,\n\t\t\t);\n\t\t}\n\t\tassertKnownExtensionPayload(\n\t\t\tdefinition,\n\t\t\tnew Uint8Array(extension.value),\n\t\t\textension.critical ?? false,\n\t\t\textension.oid,\n\t\t);\n\t}\n}\n\n/**\n * Decode a custom payload once through its known OID's definition and apply that\n * extension's profile rules to the decoded value and its criticality.\n *\n * A profile violation already carries its own code and propagates unchanged; a\n * decode failure means the payload is not the DER the OID's schema defines.\n */\nfunction assertKnownExtensionPayload(\n\tdefinition: {\n\t\treadonly oid: string;\n\t\tassertDerProfile(valueDer: Uint8Array, critical: boolean): void;\n\t},\n\tvalue: Uint8Array,\n\tcritical: boolean,\n\tsubmittedOid: string,\n): void {\n\ttry {\n\t\tdefinition.assertDerProfile(value, critical);\n\t} catch (error) {\n\t\tif (isResultError(error)) {\n\t\t\tthrow error;\n\t\t}\n\t\tthrowExtensionEncoderError(\n\t\t\t'malformed_known_extension_value',\n\t\t\t`Custom extension ${submittedOid} does not decode as ${definition.oid}`,\n\t\t);\n\t}\n}\n\n/** Effective basicConstraints across the typed field and any custom-known extension. */\nfunction resolveEffectiveBasicConstraints(\n\tinput: CertificateExtensionsInput | undefined,\n): BasicConstraints | undefined {\n\tif (input?.basicConstraints !== undefined) {\n\t\treturn input.basicConstraints;\n\t}\n\tconst custom = findCustomExtensionValue(input, OIDS.basicConstraints);\n\treturn custom === undefined ? undefined : BASIC_CONSTRAINTS_EXTENSION_DEFINITION.decode(custom);\n}\n\n/** Effective keyUsage flags across the typed field and any custom-known extension. */\nfunction resolveEffectiveKeyUsage(\n\tinput: CertificateExtensionsInput | undefined,\n): readonly KeyUsage[] | undefined {\n\tif (input?.keyUsage !== undefined) {\n\t\treturn input.keyUsage;\n\t}\n\tconst custom = findCustomExtensionValue(input, OIDS.keyUsage);\n\treturn custom === undefined ? undefined : KEY_USAGE_EXTENSION_DEFINITION.decode(custom).flags;\n}\n\n/** Whether a typed GeneralName carries a non-empty identity value. */\nfunction subjectAltNameHasIdentity(name: SubjectAltName): boolean {\n\tswitch (name.type) {\n\t\tcase 'directoryName':\n\t\t\treturn name.derHex.length > 0;\n\t\tcase 'krb5PrincipalName':\n\t\t\treturn name.realm.length > 0 || name.nameString.length > 0;\n\t\tdefault:\n\t\t\treturn name.value.length > 0;\n\t}\n}\n\n/** Whether a custom subjectAltName value decodes to at least one non-empty GeneralName. */\nfunction customSubjectAltNameHasIdentity(value: Uint8Array): boolean {\n\treturn SUBJECT_ALT_NAME_EXTENSION_DEFINITION.decode(value).some(subjectAltNameHasIdentity);\n}\n\nfunction appendConstraintExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n\tincludeBasicConstraints: boolean,\n): void {\n\tassertPathLengthKeyUsage(input);\n\tassertCaBasicConstraintsCritical(input);\n\tif (includeBasicConstraints && input.basicConstraints !== undefined) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tBASIC_CONSTRAINTS_EXTENSION_DEFINITION,\n\t\t\tinput.basicConstraints,\n\t\t);\n\t}\n\tif (input.keyUsage !== undefined && input.keyUsage.length > 0) {\n\t\tpushKnownExtension(encoded, seen, KEY_USAGE_EXTENSION_DEFINITION, input.keyUsage);\n\t}\n\tif (input.nameConstraints !== undefined) {\n\t\tpushKnownExtension(encoded, seen, NAME_CONSTRAINTS_EXTENSION_DEFINITION, input.nameConstraints);\n\t}\n}\n\nfunction appendIdentityExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n\tsubjectIsEmpty: boolean,\n): void {\n\tif (input.subjectAltNames !== undefined && input.subjectAltNames.length > 0) {\n\t\t// RFC 5280 §4.2.1.6: SAN MUST be critical when subject DN is empty.\n\t\tconst sanCritical = subjectIsEmpty ? true : undefined;\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tSUBJECT_ALT_NAME_EXTENSION_DEFINITION,\n\t\t\tinput.subjectAltNames,\n\t\t\tsanCritical,\n\t\t);\n\t}\n\tif (input.extendedKeyUsage !== undefined && input.extendedKeyUsage.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tEXTENDED_KEY_USAGE_EXTENSION_DEFINITION,\n\t\t\tinput.extendedKeyUsage,\n\t\t);\n\t}\n}\n\n/** Appends configured certificate-policy extensions while enforcing unique OIDs. */\nfunction appendPolicyExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n): void {\n\tif (input.certificatePolicies !== undefined && input.certificatePolicies.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tCERTIFICATE_POLICIES_EXTENSION_DEFINITION,\n\t\t\tinput.certificatePolicies,\n\t\t);\n\t}\n\tif (input.policyMappings !== undefined && input.policyMappings.length > 0) {\n\t\tpushKnownExtension(encoded, seen, POLICY_MAPPINGS_EXTENSION_DEFINITION, input.policyMappings);\n\t}\n\tif (input.policyConstraints !== undefined) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tPOLICY_CONSTRAINTS_EXTENSION_DEFINITION,\n\t\t\tinput.policyConstraints,\n\t\t);\n\t}\n\tif (input.inhibitAnyPolicy !== undefined) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tINHIBIT_ANY_POLICY_EXTENSION_DEFINITION,\n\t\t\tinput.inhibitAnyPolicy,\n\t\t);\n\t}\n}\n\nfunction appendAccessExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n): void {\n\tif (input.authorityInfoAccess !== undefined && input.authorityInfoAccess.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tAUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION,\n\t\t\tinput.authorityInfoAccess,\n\t\t);\n\t}\n\tif (input.crlDistributionPoints !== undefined && input.crlDistributionPoints.length > 0) {\n\t\tpushKnownExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\tCRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION,\n\t\t\tinput.crlDistributionPoints,\n\t\t);\n\t}\n\tif (input.noRevAvail === true) {\n\t\tpushKnownExtension(encoded, seen, NO_REV_AVAIL_EXTENSION_DEFINITION, true);\n\t}\n}\n\n/** Push each custom extension. Context and payload were checked by `assertCustomExtensionsValid`. */\nfunction appendCustomExtensions(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tinput: CertificateExtensionsInput,\n): void {\n\tfor (const extension of input.customExtensions ?? []) {\n\t\tpushExtension(\n\t\t\tencoded,\n\t\t\tseen,\n\t\t\textension.oid,\n\t\t\tnew Uint8Array(extension.value),\n\t\t\textension.critical ?? false,\n\t\t);\n\t}\n}\n\n/** Encode a known extension via its registry definition and push it. */\nfunction pushKnownExtension<TParsed, TInput>(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\tdefinition: ExtensionDefinition<TParsed, TInput>,\n\tvalue: TInput,\n\tcritical = definition.defaultCritical,\n): void {\n\tpushExtension(encoded, seen, definition.oid, definition.encode(value), critical);\n}\n\n/**\n * Encode a single X.509 Extension SEQUENCE (OID + optional critical BOOLEAN + OCTET STRING).\n *\n * @param oid Dotted-decimal extension OID.\n * @param extnValue DER-encoded extension payload.\n * @param critical Whether to mark the extension as critical. Default `false`.\n */\nexport function encodeExtension(oid: string, extnValue: Uint8Array, critical = false): Uint8Array {\n\tvalidateOid(oid);\n\tconst fields = [objectIdentifier(oid)];\n\tif (critical) {\n\t\tfields.push(bool(true));\n\t}\n\tfields.push(octetString(extnValue));\n\treturn sequence(fields);\n}\n\n/**\n * DER-encode a {@linkcode BasicConstraints} value.\n *\n * @param input CA flag and optional pathLength.\n * @returns DER SEQUENCE suitable for wrapping in an Extension OCTET STRING.\n */\nexport function encodeBasicConstraints(input: BasicConstraints): Uint8Array {\n\tconst fields: Uint8Array[] = [];\n\tif (input.ca) {\n\t\tfields.push(bool(true));\n\t}\n\tif (input.pathLength !== undefined) {\n\t\tif (!input.ca) {\n\t\t\tthrowExtensionEncoderError(\n\t\t\t\t'path_length_requires_ca',\n\t\t\t\t'basicConstraints pathLength requires ca = true',\n\t\t\t);\n\t\t}\n\t\tfields.push(integerFromNumber(input.pathLength));\n\t}\n\treturn sequence(fields);\n}\n\n/**\n * DER-encode a Key Usage BIT STRING from an array of {@linkcode KeyUsage} flags.\n *\n * @param usages Flags to set in the bit string.\n */\nexport function encodeKeyUsage(usages: readonly KeyUsage[]): Uint8Array {\n\treturn encodeKeyUsageExtension(usages);\n}\n\nfunction encodeIa5Content(value: string): Uint8Array {\n\ttry {\n\t\treturn ia5Bytes(value);\n\t} catch {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_ia5_string',\n\t\t\t'Invalid IA5String: contains non-ASCII characters',\n\t\t);\n\t}\n}\n\n/** RFC 5280 §4.2.1.6: reject an empty GeneralName string value (empty dNSName, rfc822Name, URI, or SRV name). */\nfunction requireNonEmptyName(value: string): string {\n\tif (value.length === 0) {\n\t\tthrowExtensionEncoderError('empty_general_name_value', 'GeneralName value must not be empty');\n\t}\n\treturn value;\n}\n\n/**\n * RFC 9598 §3: a SmtpUTF8Mailbox carries no Byte Order Mark, is used only when\n * the Local-part holds a non-ASCII character, and stores its domain as\n * lowercase A-labels and NR-LDH labels.\n */\nfunction assertSmtpUtf8Mailbox(value: string): string {\n\tconst at = requireNonEmptyName(value).lastIndexOf('@');\n\tconst localPart = at > 0 ? value.slice(0, at) : '';\n\tconst domain = toAsciiDomain(value.slice(at + 1));\n\tif (\n\t\tlocalPart.length === 0 ||\n\t\tvalue.includes('\\ufeff') ||\n\t\t!isMailboxDomain(domain, 'registration')\n\t) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_smtp_utf8_mailbox',\n\t\t\t'SmtpUTF8Mailbox must be Local-part@Domain with no Byte Order Mark and a domain of lowercase A-labels and NR-LDH labels',\n\t\t);\n\t}\n\tif (![...localPart].some((character) => (character.codePointAt(0) ?? 0) > 0x7f)) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'smtp_utf8_mailbox_ascii_local_part',\n\t\t\t'A mailbox with an ASCII Local-part must use rfc822Name (type email)',\n\t\t);\n\t}\n\tif (!isSmtpUtf8LocalPart(localPart)) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_smtp_utf8_mailbox',\n\t\t\t'SmtpUTF8Mailbox Local-part must be an RFC 6531 Dot-string or Quoted-string',\n\t\t);\n\t}\n\treturn `${localPart}@${domain}`;\n}\n\n/**\n * @internal A decoded SAN or IAN entry of a custom extension, which is emitted\n * as given: the typed builder's rules, with a SmtpUTF8Mailbox domain already\n * stored in A-labels.\n */\nexport function assertStoredSubjectAltName(name: SubjectAltName): void {\n\tencodeSubjectAltName(name);\n\tif (name.type === 'smtpUtf8Mailbox' && assertSmtpUtf8Mailbox(name.value) !== name.value) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_smtp_utf8_mailbox',\n\t\t\t'SmtpUTF8Mailbox domain must be stored as lowercase A-labels and NR-LDH labels',\n\t\t);\n\t}\n}\n\n/** RFC 5891 §4: the domain with each U-label converted to its A-label and each A-label checked. */\nfunction toAsciiDomain(domain: string): string {\n\tconst converted = domainToAscii(domain, 'registration');\n\tif (!converted.ok) {\n\t\treturn throwExtensionEncoderError(\n\t\t\t'invalid_idn',\n\t\t\t`Domain name is not valid IDNA2008 (${converted.reason})`,\n\t\t);\n\t}\n\treturn converted.value;\n}\n\n/** 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. */\nfunction requireRelativeDomain(domain: string): string {\n\tif (domain.endsWith('.')) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'domain_trailing_dot',\n\t\t\t'A dNSName or rfc822Name domain must not end in \".\" (RFC 5280 §4.2.1.6)',\n\t\t);\n\t}\n\treturn domain;\n}\n\n/** A dNSName or dNSName constraint with its leading `*.` or `.` kept and its domain in A-labels. */\nfunction toAsciiDnsName(value: string): string {\n\tconst prefix = value.startsWith('*.') ? '*.' : value.startsWith('.') ? '.' : '';\n\treturn `${prefix}${toAsciiDomain(requireRelativeDomain(value.slice(prefix.length)))}`;\n}\n\n/**\n * RFC 4985 §3: a SRVName or SRVName restriction with its label separators\n * normalized, its `_Service` label kept, and its Name in A-labels.\n */\nfunction toAsciiSrvComponents(value: string): string {\n\tconst normalized = normalizeLabelSeparators(value);\n\tconst dot = normalized.indexOf('.');\n\tif (!normalized.startsWith('_')) {\n\t\treturn toAsciiDomain(normalized);\n\t}\n\tif (dot < 0) {\n\t\treturn normalized;\n\t}\n\tconst name = normalized.slice(dot + 1);\n\treturn `${normalized.slice(0, dot + 1)}${name.length === 0 ? '' : toAsciiDomain(name)}`;\n}\n\n/** RFC 4985 §2 and RFC 6335 §5.1: a presented SRVName is `_Service.Name`. */\nfunction toAsciiSrvName(value: string): string {\n\tconst ascii = toAsciiSrvComponents(value);\n\tif (parsePresentedSrvName(ascii) === undefined) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_srv_name',\n\t\t\t'A SRVName is _Service.Name with an RFC 6335 service and an LDH Name (RFC 4985 §2)',\n\t\t);\n\t}\n\treturn ascii;\n}\n\n/** RFC 4985 §4: a SRVName constraint is `_Service.Name`, `_Service`, or `Name`. */\nfunction toAsciiSrvNameConstraint(value: string): string {\n\tconst ascii = toAsciiSrvComponents(value);\n\tif (parseSrvNameRestriction(ascii) === undefined) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_srv_name_constraint',\n\t\t\t'A SRVName constraint is _Service.Name, _Service, or Name (RFC 4985 §4)',\n\t\t);\n\t}\n\treturn ascii;\n}\n\n/** RFC 4120 §5.2.1 KerberosString content: IA5String characters in a GeneralString, without code-extension controls. */\nfunction kerberosString(value: string, field: string): Uint8Array {\n\tconst outside = (unit: number) => unit > 0x7f || unit === 0x0e || unit === 0x0f || unit === 0x1b;\n\tif ([...value].some((character) => outside(character.codePointAt(0) ?? 0))) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_krb5_principal_name',\n\t\t\t`KRB5PrincipalName ${field} must hold IA5String characters other than SO, SI and ESC (RFC 4120 §5.2.1)`,\n\t\t);\n\t}\n\treturn tlv(0x1b, new TextEncoder().encode(value));\n}\n\n/** RFC 4120 §5.2.4 Int32 as a DER-minimal two's-complement INTEGER. */\nfunction int32(value: number): Uint8Array {\n\tif (!Number.isInteger(value) || value < -2147483648 || value > 2147483647) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_krb5_principal_name',\n\t\t\t'KRB5PrincipalName nameType must be an Int32 (RFC 4120 §5.2.4)',\n\t\t);\n\t}\n\tconst octets: number[] = [];\n\tlet rest = value;\n\tdo {\n\t\toctets.unshift(rest & 0xff);\n\t\trest >>= 8;\n\t} while (!(rest === 0 && (octets[0] ?? 0) < 0x80) && !(rest === -1 && (octets[0] ?? 0) >= 0x80));\n\treturn tlv(0x02, Uint8Array.from(octets));\n}\n\n/** RFC 4556 §3.2.2 KRB5PrincipalName in the EXPLICIT tagging of RFC 4120's module. */\nfunction encodeKrb5PrincipalName(\n\tname: Extract<SubjectAltName, { readonly type: 'krb5PrincipalName' }>,\n): Uint8Array {\n\tif (name.realm.includes('\\0')) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_krb5_principal_name',\n\t\t\t'KRB5PrincipalName realm must not contain NUL (RFC 4120 §5.2.2)',\n\t\t);\n\t}\n\treturn sequence([\n\t\texplicitContext(0, kerberosString(name.realm, 'realm')),\n\t\texplicitContext(\n\t\t\t1,\n\t\t\tsequence([\n\t\t\t\texplicitContext(0, int32(name.nameType)),\n\t\t\t\texplicitContext(\n\t\t\t\t\t1,\n\t\t\t\t\tsequence(name.nameString.map((component) => kerberosString(component, 'nameString'))),\n\t\t\t\t),\n\t\t\t]),\n\t\t),\n\t]);\n}\n\n/** An otherName type-id that has no dedicated {@linkcode SubjectAltName} variant. */\nfunction validateOtherNameTypeId(typeId: string): string {\n\tconst oid = validateOid(typeId);\n\tif (oid === OIDS.idOnDnsSrv || oid === OIDS.idOnSmtpUtf8Mailbox) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'other_name_type_id_has_variant',\n\t\t\t`otherName type-id ${oid} is encoded through its dedicated SubjectAltName variant`,\n\t\t);\n\t}\n\treturn oid;\n}\n\nfunction requireGeneralNameContent(\n\telement: Uint8Array,\n\tform: 'x400Address' | 'ediPartyName',\n\tcheck: (element: Uint8Array) => GeneralNameContentCheck,\n): Uint8Array {\n\tconst result = check(element);\n\tif (!result.ok) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_general_name_content',\n\t\t\tresult.reason === 'unsupported'\n\t\t\t\t? `${form} contents use an encoding micro509 cannot validate`\n\t\t\t\t: `${form} contents do not match the ${form === 'x400Address' ? 'ORAddress' : 'EDIPartyName'} ASN.1 (RFC 5280)`,\n\t\t);\n\t}\n\treturn element;\n}\n\nfunction requireSingleDerElement(value: Uint8Array): Uint8Array {\n\tconst verdict = checkStrictDer(value);\n\tif (verdict !== 'valid') {\n\t\tthrowExtensionEncoderError(\n\t\t\t'invalid_other_name_value',\n\t\t\tverdict === 'unsupported'\n\t\t\t\t? 'otherName value uses an encoding micro509 cannot validate'\n\t\t\t\t: 'otherName value must be exactly one DER element',\n\t\t);\n\t}\n\treturn value;\n}\n\n/** RFC 9549 §2.5: an rfc822Name or rfc822Name constraint with its host in A-labels. */\nfunction toAsciiMailbox(value: string): string {\n\tconst at = value.lastIndexOf('@');\n\treturn at < 0\n\t\t? toAsciiDnsName(value)\n\t\t: `${value.slice(0, at + 1)}${toAsciiDomain(requireRelativeDomain(value.slice(at + 1)))}`;\n}\n\n/**\n * DER-encode a single {@linkcode SubjectAltName} GeneralName element.\n *\n * @param value The SAN entry to encode.\n */\nexport function encodeSubjectAltName(value: SubjectAltName): Uint8Array {\n\tswitch (value.type) {\n\t\tcase 'dns':\n\t\t\treturn implicitPrimitiveContext(\n\t\t\t\t2,\n\t\t\t\tencodeIa5Content(toAsciiDnsName(requireNonEmptyName(value.value))),\n\t\t\t);\n\t\tcase 'email':\n\t\t\treturn implicitPrimitiveContext(\n\t\t\t\t1,\n\t\t\t\tencodeIa5Content(toAsciiMailbox(requireNonEmptyName(value.value))),\n\t\t\t);\n\t\tcase 'uri':\n\t\t\treturn implicitPrimitiveContext(6, encodeIa5Content(requireNonEmptyName(value.value)));\n\t\tcase 'srv':\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes([\n\t\t\t\t\tobjectIdentifier(OIDS.idOnDnsSrv),\n\t\t\t\t\texplicitContext(\n\t\t\t\t\t\t0,\n\t\t\t\t\t\ttlv(0x16, encodeIa5Content(toAsciiSrvName(requireNonEmptyName(value.value)))),\n\t\t\t\t\t),\n\t\t\t\t]),\n\t\t\t);\n\t\tcase 'smtpUtf8Mailbox':\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes([\n\t\t\t\t\tobjectIdentifier(OIDS.idOnSmtpUtf8Mailbox),\n\t\t\t\t\texplicitContext(0, utf8String(assertSmtpUtf8Mailbox(value.value))),\n\t\t\t\t]),\n\t\t\t);\n\t\tcase 'upn':\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes([\n\t\t\t\t\tobjectIdentifier(OIDS.ntPrincipalName),\n\t\t\t\t\texplicitContext(0, utf8String(requireNonEmptyName(value.value))),\n\t\t\t\t]),\n\t\t\t);\n\t\tcase 'krb5PrincipalName':\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes([\n\t\t\t\t\tobjectIdentifier(OIDS.idPkinitSan),\n\t\t\t\t\texplicitContext(0, encodeKrb5PrincipalName(value)),\n\t\t\t\t]),\n\t\t\t);\n\t\tcase 'ip':\n\t\t\treturn implicitPrimitiveContext(7, encodeIpAddress(value.value));\n\t\tcase 'directoryName':\n\t\t\treturn implicitConstructedContext(4, readDirectoryNameTlv(value.derHex));\n\t\tcase 'otherName': {\n\t\t\tconst typeId = validateOtherNameTypeId(value.typeId);\n\t\t\tconst element = requireSingleDerElement(value.value);\n\t\t\tif (typedOtherName(typeId, element, readRootElement(element)) !== undefined) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'other_name_type_id_has_variant',\n\t\t\t\t\t`otherName type-id ${typeId} with this value is encoded through its dedicated SubjectAltName variant`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes([objectIdentifier(typeId), explicitContext(0, element)]),\n\t\t\t);\n\t\t}\n\t\tcase 'x400Address':\n\t\t\treturn requireGeneralNameContent(\n\t\t\t\timplicitConstructedContext(3, value.value),\n\t\t\t\t'x400Address',\n\t\t\t\tcheckOrAddress,\n\t\t\t);\n\t\tcase 'ediPartyName':\n\t\t\treturn requireGeneralNameContent(\n\t\t\t\timplicitConstructedContext(5, value.value),\n\t\t\t\t'ediPartyName',\n\t\t\t\tcheckEdiPartyName,\n\t\t\t);\n\t\tcase 'registeredID':\n\t\t\treturn implicitPrimitiveContext(\n\t\t\t\t8,\n\t\t\t\treadRootElement(objectIdentifier(validateOid(value.value))).value,\n\t\t\t);\n\t\tcase 'unknown':\n\t\t\tif (!GENERAL_NAME_WIRE_TAGS.has(value.tag)) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'invalid_general_name_tag',\n\t\t\t\t\t`Invalid GeneralName tag: ${value.tag}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn tlv(value.tag, value.value);\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = value;\n\t\t\tthrow new Error(`Unhandled SubjectAltName type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/**\n * DER-encode an Extended Key Usage SEQUENCE OF OIDs.\n *\n * @param usages EKU purposes to encode.\n */\nexport function encodeExtendedKeyUsage(usages: readonly ExtendedKeyUsage[]): Uint8Array {\n\tif (usages.length === 0) {\n\t\tthrowExtensionEncoderError('extended_key_usage_empty', 'extendedKeyUsage must not be empty');\n\t}\n\treturn sequence(usages.map((usage) => objectIdentifier(getExtendedKeyUsageOid(usage))));\n}\n\n/**\n * DER-encode an Authority Information Access SEQUENCE.\n *\n * @param entries AIA entries (OCSP, caIssuers, or custom) to encode.\n */\nexport function encodeAuthorityInfoAccess(\n\tentries: readonly AuthorityInformationAccessInput[],\n): Uint8Array {\n\tassertAuthorityInfoAccessProfile(entries);\n\treturn sequence(\n\t\tentries.map((entry) =>\n\t\t\tsequence([\n\t\t\t\tobjectIdentifier(getAuthorityInfoAccessMethodOid(entry.method)),\n\t\t\t\tencodeSubjectAltName(entry.location),\n\t\t\t]),\n\t\t),\n\t);\n}\n\n/**\n * @internal RFC 5280 §4.2.2.1 and RFC 6960 §3.1 rules for Authority Information\n * Access: at least one entry, and an id-ad-ocsp location that is a URI.\n *\n * The method OID is resolved before the URI check so a custom-OID wrapper cannot\n * smuggle a non-URI OCSP location past the input union.\n */\nexport function assertAuthorityInfoAccessProfile(\n\tentries: readonly AuthorityInformationAccess[],\n): void {\n\tif (entries.length === 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'authority_info_access_empty',\n\t\t\t'authorityInfoAccess must not be empty',\n\t\t);\n\t}\n\tfor (const entry of entries) {\n\t\tconst methodOid = getAuthorityInfoAccessMethodOid(entry.method);\n\t\tif (methodOid === OIDS.ocspAccessMethod && entry.location.type !== 'uri') {\n\t\t\tthrowExtensionEncoderError(\n\t\t\t\t'authority_info_access_ocsp_not_uri',\n\t\t\t\t'authorityInfoAccess OCSP location must be a URI',\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * DER-encode a CRL Distribution Points SEQUENCE.\n *\n * @param points Distribution points to encode.\n */\nexport function encodeCrlDistributionPoints(points: readonly DistributionPoint[]): Uint8Array {\n\tassertCrlDistributionPointsProfile(points);\n\treturn sequence(points.map((point) => sequence(encodeDistributionPoint(point))));\n}\n\n/**\n * @internal RFC 5280 §4.2.1.13 profile rules for a CRLDistributionPoints value,\n * stated over the fields a typed {@linkcode DistributionPoint} and a decoded\n * `ParsedDistributionPoint` share.\n *\n * `TRelativeName` differs between the two: builder input carries an unencoded RDN,\n * a decoded point carries the parsed one. The rules only read its presence.\n */\nexport function assertCrlDistributionPointsProfile<TRelativeName>(\n\tpoints: readonly ProfileDistributionPoint<TRelativeName>[],\n): void {\n\tif (points.length === 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'crl_distribution_points_empty',\n\t\t\t'cRLDistributionPoints must not be empty',\n\t\t);\n\t}\n\tfor (const point of points) {\n\t\tassertDistributionPointProfile(point);\n\t}\n}\n\n/** RFC 5280 §4.2.1.13 rules for one distribution point. */\nfunction assertDistributionPointProfile<TRelativeName>(\n\tpoint: ProfileDistributionPoint<TRelativeName>,\n): void {\n\tif (point.crlIssuer !== undefined && point.crlIssuer.length === 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'distribution_point_crl_issuer_empty',\n\t\t\t'DistributionPoint crlIssuer must not be empty',\n\t\t);\n\t}\n\tif (point.distributionPoint === undefined && point.crlIssuer === undefined) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'distribution_point_empty',\n\t\t\t'DistributionPoint must contain distributionPoint or crlIssuer',\n\t\t);\n\t}\n\tassertCrlIssuerDistinguishedNames(point);\n\tif (\n\t\tpoint.distributionPoint?.type === 'fullName' &&\n\t\tpoint.distributionPoint.fullName.length === 0\n\t) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'distribution_point_full_name_empty',\n\t\t\t'DistributionPointName fullName must not be empty',\n\t\t);\n\t}\n}\n\n/**\n * DER-encode a Name Constraints extension value.\n *\n * @param constraints Permitted and/or excluded subtrees.\n */\nexport function encodeNameConstraints(constraints: NameConstraints): Uint8Array {\n\tassertNameConstraintsProfile(constraints);\n\tconst parts: Uint8Array[] = [];\n\tif (constraints.permittedSubtrees !== undefined && constraints.permittedSubtrees.length > 0) {\n\t\tparts.push(\n\t\t\timplicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes(constraints.permittedSubtrees.map(encodeGeneralSubtree)),\n\t\t\t),\n\t\t);\n\t}\n\tif (constraints.excludedSubtrees !== undefined && constraints.excludedSubtrees.length > 0) {\n\t\tparts.push(\n\t\t\timplicitConstructedContext(\n\t\t\t\t1,\n\t\t\t\tconcatBytes(constraints.excludedSubtrees.map(encodeGeneralSubtree)),\n\t\t\t),\n\t\t);\n\t}\n\treturn sequence(parts);\n}\n\n/**\n * @internal RFC 5280 fixes the criticality of several extensions: nameConstraints\n * (§4.2.1.10), policyConstraints (§4.2.1.11), and inhibitAnyPolicy (§4.2.1.14) are\n * critical; authorityKeyIdentifier (§4.2.1.1), subjectKeyIdentifier (§4.2.1.2),\n * and authorityInfoAccess (§4.2.2.1) are not.\n *\n * @param label Extension name quoted in the diagnostic.\n * @param required The criticality RFC 5280 mandates.\n * @param critical The criticality the caller asked for.\n */\nexport function assertExtensionCriticality(\n\tlabel: string,\n\trequired: boolean,\n\tcritical: boolean,\n): void {\n\tif (critical === required) {\n\t\treturn;\n\t}\n\tthrowExtensionEncoderError(\n\t\trequired ? 'extension_must_be_critical' : 'extension_must_be_non_critical',\n\t\t`The ${label} extension must be marked ${required ? 'critical' : 'non-critical'}`,\n\t);\n}\n\n/**\n * @internal RFC 5280 §4.2.1.10: a nameConstraints extension states at least one\n * of permittedSubtrees and excludedSubtrees, and neither may be an empty set.\n */\nexport function assertNameConstraintsProfile(constraints: {\n\treadonly permittedSubtrees?: readonly unknown[];\n\treadonly excludedSubtrees?: readonly unknown[];\n}): void {\n\tconst permitted = constraints.permittedSubtrees?.length ?? 0;\n\tconst excluded = constraints.excludedSubtrees?.length ?? 0;\n\tif (permitted === 0 && excluded === 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'name_constraints_empty',\n\t\t\t'nameConstraints must set permittedSubtrees or excludedSubtrees',\n\t\t);\n\t}\n}\n\n/**\n * DER-encode a Certificate Policies extension value.\n *\n * @param policies Non-empty array of policy information entries.\n */\nexport function encodeCertificatePolicies(policies: CertificatePolicies): Uint8Array {\n\tif (policies.length === 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'certificate_policies_empty',\n\t\t\t'certificatePolicies must not be empty',\n\t\t);\n\t}\n\tconst seen = new Set<string>();\n\tfor (const policy of policies) {\n\t\tconst key = validatePolicyOid(policy.policyIdentifier);\n\t\tif (seen.has(key)) {\n\t\t\tthrowExtensionEncoderError(\n\t\t\t\t'duplicate_policy_oid',\n\t\t\t\t`Duplicate certificate policy OID: ${policy.policyIdentifier}`,\n\t\t\t);\n\t\t}\n\t\tseen.add(key);\n\t}\n\treturn sequence(policies.map(encodePolicyInformation));\n}\n\n/**\n * DER-encode a Policy Mappings extension value.\n *\n * @param mappings Non-empty array of issuer-to-subject policy pairs. Neither OID may be anyPolicy.\n */\nexport function encodePolicyMappings(mappings: PolicyMappings): Uint8Array {\n\tif (mappings.length === 0) {\n\t\tthrowExtensionEncoderError('policy_mappings_empty', 'policyMappings must not be empty');\n\t}\n\treturn sequence(\n\t\tmappings.map((mapping) => {\n\t\t\tconst issuerDomainPolicy = validatePolicyOid(mapping.issuerDomainPolicy);\n\t\t\tconst subjectDomainPolicy = validatePolicyOid(mapping.subjectDomainPolicy);\n\t\t\tif (issuerDomainPolicy === OIDS.anyPolicy || subjectDomainPolicy === OIDS.anyPolicy) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'policy_mappings_any_policy',\n\t\t\t\t\t'policyMappings must not use anyPolicy',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn sequence([\n\t\t\t\tobjectIdentifier(mapping.issuerDomainPolicy),\n\t\t\t\tobjectIdentifier(mapping.subjectDomainPolicy),\n\t\t\t]);\n\t\t}),\n\t);\n}\n\n/**\n * DER-encode a Policy Constraints extension value.\n *\n * @param constraints At least one of `requireExplicitPolicy` or `inhibitPolicyMapping` must be set.\n */\nexport function encodePolicyConstraints(constraints: PolicyConstraints): Uint8Array {\n\tconst fields: Uint8Array[] = [];\n\tif (constraints.requireExplicitPolicy !== undefined) {\n\t\tfields.push(\n\t\t\timplicitPrimitiveContext(0, encodeIntegerContent(constraints.requireExplicitPolicy)),\n\t\t);\n\t}\n\tif (constraints.inhibitPolicyMapping !== undefined) {\n\t\tfields.push(\n\t\t\timplicitPrimitiveContext(1, encodeIntegerContent(constraints.inhibitPolicyMapping)),\n\t\t);\n\t}\n\tif (fields.length === 0) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'policy_constraints_empty',\n\t\t\t'policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping',\n\t\t);\n\t}\n\treturn sequence(fields);\n}\n\n/**\n * DER-encode an Inhibit anyPolicy extension value (single INTEGER).\n *\n * @param input The skipCerts threshold.\n */\nexport function encodeInhibitAnyPolicy(input: InhibitAnyPolicy): Uint8Array {\n\treturn integerFromNumber(input.skipCerts);\n}\n\n/** DER-encode a single PolicyInformation SEQUENCE. */\nfunction encodePolicyInformation(policy: PolicyInformation): Uint8Array {\n\tvalidatePolicyOid(policy.policyIdentifier);\n\tconst fields = [objectIdentifier(policy.policyIdentifier)];\n\tif (policy.policyQualifiers !== undefined && policy.policyQualifiers.length > 0) {\n\t\tfields.push(sequence(policy.policyQualifiers.map(encodePolicyQualifierInfo)));\n\t}\n\treturn sequence(fields);\n}\n\n/** DER-encode a single PolicyQualifierInfo SEQUENCE. */\nfunction encodePolicyQualifierInfo(qualifier: PolicyQualifierInfo): Uint8Array {\n\tswitch (qualifier.type) {\n\t\tcase 'cps':\n\t\t\treturn sequence([objectIdentifier(OIDS.cpsPolicyQualifier), ia5String(qualifier.uri)]);\n\t\tcase 'userNotice':\n\t\t\treturn sequence([\n\t\t\t\tobjectIdentifier(OIDS.userNoticePolicyQualifier),\n\t\t\t\tencodeUserNoticePolicyQualifierInfo(qualifier),\n\t\t\t]);\n\t\tcase 'oid': {\n\t\t\tvalidateOid(qualifier.oid);\n\t\t\tconst encodedOid = objectIdentifier(qualifier.oid);\n\t\t\tconst canonicalOid = toHex(encodedOid);\n\t\t\tif (\n\t\t\t\tcanonicalOid === toHex(objectIdentifier(OIDS.cpsPolicyQualifier)) ||\n\t\t\t\tcanonicalOid === toHex(objectIdentifier(OIDS.userNoticePolicyQualifier))\n\t\t\t) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'reserved_policy_qualifier_oid',\n\t\t\t\t\t'Policy qualifier must use the typed cps or userNotice variant, not a built-in OID',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn sequence([encodedOid, new Uint8Array(qualifier.qualifierDer)]);\n\t\t}\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = qualifier;\n\t\t\tthrow new Error(`Unhandled PolicyQualifierInfo type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/** DER-encode a UserNotice qualifier SEQUENCE. */\nfunction assertDisplayText(value: string): void {\n\tif (hasLoneSurrogate(value)) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'display_text_lone_surrogate',\n\t\t\t'DisplayText must not hold a lone UTF-16 surrogate',\n\t\t);\n\t}\n\tconst length = [...value].length;\n\tif (length === 0 || length > 200) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'display_text_out_of_range',\n\t\t\t'DisplayText must be 1 to 200 characters',\n\t\t);\n\t}\n}\n\nfunction encodeUserNoticePolicyQualifierInfo(qualifier: UserNoticePolicyQualifierInfo): Uint8Array {\n\tconst fields: Uint8Array[] = [];\n\tif (qualifier.noticeRef !== undefined) {\n\t\tfields.push(encodePolicyNoticeReference(qualifier.noticeRef));\n\t}\n\tif (qualifier.explicitText !== undefined) {\n\t\tassertDisplayText(qualifier.explicitText);\n\t\tfields.push(encodeExplicitText(qualifier.explicitText, qualifier.explicitTextType));\n\t}\n\treturn sequence(fields);\n}\n\n/**\n * RFC 6818 §3, replacing the explicitText paragraph of RFC 5280 §4.2.1.4:\n * UTF8String is preferred, VisibleString and BMPString are acceptable,\n * IA5String is forbidden, control characters should not appear, and UTF8String\n * and BMPString text should be in Unicode normalization form C.\n */\nfunction encodeExplicitText(text: string, type: DisplayTextType = 'utf8String'): Uint8Array {\n\tif ([...text].some(isControlCharacter)) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'display_text_control_character',\n\t\t\t'explicitText must not contain control characters',\n\t\t);\n\t}\n\tswitch (type) {\n\t\tcase 'utf8String':\n\t\t\tassertNormalizationFormC(text);\n\t\t\treturn utf8String(text);\n\t\tcase 'bmpString':\n\t\t\tassertNormalizationFormC(text);\n\t\t\treturn encodeBmpDisplayText(text);\n\t\tcase 'visibleString':\n\t\t\treturn encodeVisibleDisplayText(text);\n\t\tcase 'ia5String':\n\t\t\treturn throwExtensionEncoderError(\n\t\t\t\t'display_text_ia5_string',\n\t\t\t\t'explicitText must not be encoded as IA5String',\n\t\t\t);\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = type;\n\t\t\tthrow new Error(`Unhandled DisplayText type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\nfunction isControlCharacter(character: string): boolean {\n\tconst codePoint = character.codePointAt(0) ?? 0;\n\treturn codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f);\n}\n\nfunction assertNormalizationFormC(text: string): void {\n\tif (text.normalize('NFC') !== text) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'display_text_not_nfc',\n\t\t\t'explicitText must be in Unicode normalization form C',\n\t\t);\n\t}\n}\n\nfunction encodeVisibleDisplayText(text: string): Uint8Array {\n\ttry {\n\t\treturn visibleString(text);\n\t} catch {\n\t\treturn throwExtensionEncoderError(\n\t\t\t'invalid_visible_string',\n\t\t\t'VisibleString explicitText must be printable ASCII',\n\t\t);\n\t}\n}\n\nfunction encodeBmpDisplayText(text: string): Uint8Array {\n\ttry {\n\t\treturn bmpString(text);\n\t} catch {\n\t\treturn throwExtensionEncoderError(\n\t\t\t'invalid_bmp_string',\n\t\t\t'BMPString explicitText must hold Basic Multilingual Plane characters other than surrogates, U+FFFE and U+FFFF',\n\t\t);\n\t}\n}\n\n/** DER-encode a NoticeReference SEQUENCE. */\nfunction encodePolicyNoticeReference(reference: PolicyNoticeReference): Uint8Array {\n\tassertDisplayText(reference.organization);\n\treturn sequence([\n\t\tutf8String(reference.organization),\n\t\tsequence(reference.noticeNumbers.map((noticeNumber) => integerFromNumber(noticeNumber))),\n\t]);\n}\n\n/** Encode an INTEGER and return only the content bytes (no TLV wrapper). */\nfunction encodeIntegerContent(value: number): Uint8Array {\n\treturn readElement(integerFromNumber(value)).value;\n}\n\n/** DER-encode a GeneralSubtree SEQUENCE (base name only; min/max omitted per RFC 5280). */\nfunction encodeGeneralSubtree(subtree: GeneralSubtree): Uint8Array {\n\treturn sequence([encodeNameConstraintForm(subtree.base)]);\n}\n\n/**\n * RFC 5280 §4.2.1.13: cRLIssuer, when present, only contains the CRL issuer's\n * distinguished name; nameRelativeToCRLIssuer additionally requires exactly one.\n *\n * Applies to a typed {@linkcode DistributionPoint} and to a decoded\n * {@linkcode ParsedDistributionPoint} alike, so the rule holds whether the value\n * arrives through `crlDistributionPoints` or through `customExtensions`.\n */\nfunction assertCrlIssuerDistinguishedNames<TRelativeName>(\n\tpoint: ProfileDistributionPoint<TRelativeName>,\n): void {\n\tif (point.crlIssuer === undefined) {\n\t\treturn;\n\t}\n\tif (point.crlIssuer.some((name) => name.type !== 'directoryName')) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'distribution_point_crl_issuer_not_directory_name',\n\t\t\t'DistributionPoint cRLIssuer must only contain directoryName entries',\n\t\t);\n\t}\n\tif (point.distributionPoint?.type === 'relativeName' && point.crlIssuer.length > 1) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'distribution_point_relative_name_multiple_crl_issuers',\n\t\t\t'DistributionPointName relativeName requires at most one cRLIssuer distinguished name',\n\t\t);\n\t}\n}\n\n/** DER-encode the fields of a single DistributionPoint, already profile-checked. */\nfunction encodeDistributionPoint(point: DistributionPoint): Uint8Array[] {\n\tconst fields: Uint8Array[] = [];\n\tif (point.distributionPoint !== undefined) {\n\t\tfields.push(\n\t\t\timplicitConstructedContext(0, encodeDistributionPointName(point.distributionPoint)),\n\t\t);\n\t}\n\tif (point.reasons !== undefined && point.reasons.length > 0) {\n\t\tfields.push(\n\t\t\timplicitPrimitiveContext(1, encodeDistributionPointReasonFlagsContent(point.reasons)),\n\t\t);\n\t}\n\tif (point.crlIssuer !== undefined) {\n\t\tfields.push(\n\t\t\timplicitConstructedContext(2, concatBytes(point.crlIssuer.map(encodeSubjectAltName))),\n\t\t);\n\t}\n\treturn fields;\n}\n\n/** DER-encode a DistributionPointName (fullName or relativeName). */\nfunction encodeDistributionPointName(name: DistributionPointName): Uint8Array {\n\tswitch (name.type) {\n\t\tcase 'fullName': {\n\t\t\tif (name.fullName.length === 0) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'distribution_point_full_name_empty',\n\t\t\t\t\t'DistributionPointName fullName must not be empty',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn implicitConstructedContext(0, concatBytes(name.fullName.map(encodeSubjectAltName)));\n\t\t}\n\t\tcase 'relativeName': {\n\t\t\tconst relativeName = encodeRelativeDistinguishedName(name.relativeName);\n\t\t\tconst relativeNameElement = readElement(relativeName);\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t1,\n\t\t\t\trelativeName.slice(relativeNameElement.start, relativeNameElement.end),\n\t\t\t);\n\t\t}\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = name;\n\t\t\tthrow new Error(`Unhandled DistributionPointName type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/** DER-encode a NameConstraintForm as an implicit-tagged {@linkcode GeneralName}. */\nfunction encodeNameConstraintForm(form: NameConstraintForm): Uint8Array {\n\tswitch (form.type) {\n\t\tcase 'dns':\n\t\t\treturn implicitPrimitiveContext(2, encodeIa5Content(toAsciiDnsName(form.value)));\n\t\tcase 'email':\n\t\t\tif (form.value.includes('@')) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'email_name_constraint_names_mailbox',\n\t\t\t\t\t'An rfc822Name constraint names a host or a domain, not a particular mailbox (RFC 9549 §2.2)',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn implicitPrimitiveContext(1, encodeIa5Content(toAsciiMailbox(form.value)));\n\t\tcase 'uri':\n\t\t\tif (parseUriNameConstraint(form.value) === undefined) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'invalid_uri_name_constraint',\n\t\t\t\t\t'A uniformResourceIdentifier constraint is a fully qualified domain name, with a leading period for its subdomains (RFC 5280 §4.2.1.10)',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn implicitPrimitiveContext(6, encodeIa5Content(form.value));\n\t\tcase 'ip': {\n\t\t\tconst total = form.addressBytes.length + form.maskBytes.length;\n\t\t\tif (form.addressBytes.length !== form.maskBytes.length || (total !== 8 && total !== 32)) {\n\t\t\t\tthrowExtensionEncoderError(\n\t\t\t\t\t'invalid_ip_name_constraint',\n\t\t\t\t\t'IP name constraint must be 8 octets (IPv4) or 32 octets (IPv6)',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn implicitPrimitiveContext(7, concatBytes([form.addressBytes, form.maskBytes]));\n\t\t}\n\t\tcase 'directoryName':\n\t\t\treturn implicitConstructedContext(4, readDirectoryNameTlv(form.derHex));\n\t\tcase 'srv':\n\t\t\treturn implicitConstructedContext(\n\t\t\t\t0,\n\t\t\t\tconcatBytes([\n\t\t\t\t\tobjectIdentifier(OIDS.idOnDnsSrv),\n\t\t\t\t\texplicitContext(0, tlv(0x16, encodeIa5Content(toAsciiSrvNameConstraint(form.value)))),\n\t\t\t\t]),\n\t\t\t);\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = form;\n\t\t\tthrow new Error(`Unhandled NameConstraintForm type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/** Returns the complete Name TLV from a hex-encoded DER SEQUENCE, validating the root tag. */\nfunction readDirectoryNameTlv(derHex: string): Uint8Array {\n\tconst bytes = hexToBytes(derHex);\n\tconst element = readRootElement(bytes, { maxDepth: DEFAULT_MAX_DER_DEPTH });\n\tif (element.tag !== 0x30) {\n\t\tthrowExtensionEncoderError(\n\t\t\t'directory_name_not_sequence',\n\t\t\t'directoryName derHex must encode a DER SEQUENCE',\n\t\t);\n\t}\n\treturn bytes.slice(element.start - element.headerLength, element.end);\n}\n\n/**\n * Resolve an {@linkcode ExtendedKeyUsage} to its dotted-decimal OID.\n *\n * @param usage Well-known string or custom OID object.\n */\nexport function getExtendedKeyUsageOid(usage: ExtendedKeyUsage): string {\n\tif (typeof usage === 'string') {\n\t\treturn EXTENDED_KEY_USAGE_OIDS[usage];\n\t}\n\treturn validateOid(usage.value);\n}\n\n/**\n * Map a dotted-decimal OID to an {@linkcode ExtendedKeyUsage} value.\n *\n * Returns a well-known string for recognized OIDs, or `{ type: 'oid', value }` otherwise.\n */\nexport function parseExtendedKeyUsageOid(oid: string): ExtendedKeyUsage {\n\tswitch (oid) {\n\t\tcase OIDS.serverAuth:\n\t\t\treturn 'serverAuth';\n\t\tcase OIDS.clientAuth:\n\t\t\treturn 'clientAuth';\n\t\tcase OIDS.codeSigning:\n\t\t\treturn 'codeSigning';\n\t\tcase OIDS.emailProtection:\n\t\t\treturn 'emailProtection';\n\t\tcase OIDS.timeStamping:\n\t\t\treturn 'timeStamping';\n\t\tcase OIDS.ocspSigning:\n\t\t\treturn 'ocspSigning';\n\t}\n\treturn { type: 'oid', value: oid };\n}\n\n/**\n * Resolve an {@linkcode AuthorityInfoAccessMethod} to its dotted-decimal OID.\n *\n * @param method Well-known string or custom OID object.\n */\nexport function getAuthorityInfoAccessMethodOid(method: AuthorityInfoAccessMethod): string {\n\tif (typeof method === 'string') {\n\t\treturn AUTHORITY_INFO_ACCESS_METHOD_OIDS[method];\n\t}\n\treturn validateOid(method.value);\n}\n\n/**\n * Map a dotted-decimal OID to an {@linkcode AuthorityInfoAccessMethod} value.\n *\n * Returns `'ocsp'` or `'caIssuers'` for recognized OIDs, or `{ type: 'oid', value }` otherwise.\n */\nexport function parseAuthorityInfoAccessMethodOid(oid: string): AuthorityInfoAccessMethod {\n\tswitch (oid) {\n\t\tcase OIDS.ocspAccessMethod:\n\t\t\treturn 'ocsp';\n\t\tcase OIDS.caIssuersAccessMethod:\n\t\t\treturn 'caIssuers';\n\t}\n\treturn { type: 'oid', value: oid };\n}\n\n/** Parse a dotted-decimal/colon-hex IP string to raw address bytes. */\nfunction encodeIpAddress(input: string): Uint8Array {\n\treturn parseIpAddressToBytes(input);\n}\n\n/**\n * Computes a key identifier from a DER `SubjectPublicKeyInfo` using method (1)\n * of RFC 5280 §4.2.1.2: \"the 160-bit SHA-1 hash of the value of the BIT STRING\n * subjectPublicKey (excluding the tag, length, and number of unused bits)\".\n * A parsed certificate carries the input as `subjectPublicKeyInfoDer`.\n */\nexport function buildSubjectKeyIdentifier(subjectPublicKeyInfo: Uint8Array): Uint8Array {\n\tconst topLevel = readSequenceChildren(subjectPublicKeyInfo);\n\tconst subjectPublicKey = topLevel[1];\n\tif (subjectPublicKey === undefined || subjectPublicKey.tag !== 0x03) {\n\t\tthrow new Error('SPKI missing subject public key bit string');\n\t}\n\tconst publicKeyBytes = subjectPublicKey.value.slice(1);\n\treturn sha1(publicKeyBytes);\n}\n\n/**\n * The key identifier a certificate or CRL issued by `issuer` carries in its\n * authority key identifier: the issuer's subject key identifier (RFC 5280\n * §4.2.1.2, §5.2.1), or a method (1) identifier over its public key when it\n * has none (§4.2.1.1).\n */\nexport function issuerKeyIdentifier(issuer: ParsedCertificate): Uint8Array {\n\treturn issuer.subjectKeyIdentifier === undefined\n\t\t? buildSubjectKeyIdentifier(issuer.subjectPublicKeyInfoDer)\n\t\t: hexToBytes(issuer.subjectKeyIdentifier);\n}\n\n/**\n * Throw if the string is not an encodable dotted-decimal OID, and return its\n * canonical spelling.\n *\n * Syntax alone is not enough. X.660 bounds the first arc to 0, 1, or 2 and the\n * second to under 40 beneath arcs 0 and 1, so `3.1` and `1.40` parse as decimals\n * yet cannot be encoded.\n */\nfunction validateOid(oid: string): string {\n\tif (!/^\\d+(?:\\.\\d+)+$/.test(oid)) {\n\t\tthrowExtensionEncoderError('invalid_oid', `Invalid OID: ${oid}`);\n\t}\n\ttry {\n\t\treturn canonicalizeOid(oid);\n\t} catch (error) {\n\t\trethrowDecodeRefusal(error, DECODE_REFUSAL_CODES);\n\t\tthrowExtensionEncoderError('invalid_oid', `Invalid OID: ${oid}`);\n\t}\n}\n\n/** Validate a policy OID and return its canonical spelling. */\nfunction validatePolicyOid(oid: string): string {\n\treturn validateOid(oid);\n}\n\n/**\n * Encode and push an extension, rejecting duplicate OIDs.\n *\n * Duplicate identity is the canonical OID, because two spellings that differ only\n * by leading zeros in an arc encode to the same wire bytes. The diagnostic quotes\n * the OID as submitted, which is the string the caller can find in their input.\n */\nfunction pushExtension(\n\tencoded: Uint8Array[],\n\tseen: Set<string>,\n\toid: string,\n\tvalue: Uint8Array,\n\tcritical = false,\n): void {\n\tconst identity = validateOid(oid);\n\tif (seen.has(identity)) {\n\t\tthrowExtensionEncoderError('duplicate_extension_oid', `Duplicate extension OID: ${oid}`);\n\t}\n\tseen.add(identity);\n\tencoded.push(encodeExtension(oid, value, critical));\n}\n\nexport {\n\tallOnesMaskForIpAddress,\n\tdecodeIpAddress,\n\tnormalizeIpAddress,\n\tparseIpAddressToBytes,\n} from '#micro509/internal/shared/ip';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAw0BA,MAAMiE,KAAiE;CACtE,YAAYtC,EAAK;CACjB,YAAYA,EAAK;C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