micro509 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/CHANGELOG.md +2064 -0
  2. package/README.md +111 -183
  3. package/dist/crypto/crypto.d.ts +104 -0
  4. package/dist/crypto/crypto.js +105 -0
  5. package/dist/crypto/crypto.js.map +1 -0
  6. package/dist/crypto.d.ts +4 -0
  7. package/dist/crypto.js +1 -0
  8. package/dist/der/der.d.ts +41 -33
  9. package/dist/der/der.js +26 -24
  10. package/dist/der/der.js.map +1 -1
  11. package/dist/index.d.ts +18 -14
  12. package/dist/index.js +19 -17
  13. package/dist/internal/asn1/asn1.d.ts +3 -6
  14. package/dist/internal/asn1/asn1.js +355 -44
  15. package/dist/internal/asn1/asn1.js.map +1 -1
  16. package/dist/internal/asn1/ber.js +146 -0
  17. package/dist/internal/asn1/ber.js.map +1 -0
  18. package/dist/internal/asn1/decode-refusal.js +29 -0
  19. package/dist/internal/asn1/decode-refusal.js.map +1 -0
  20. package/dist/internal/asn1/der.d.ts +42 -43
  21. package/dist/internal/asn1/der.js +148 -56
  22. package/dist/internal/asn1/der.js.map +1 -1
  23. package/dist/internal/asn1/oids.js +90 -54
  24. package/dist/internal/asn1/oids.js.map +1 -1
  25. package/dist/internal/asn1/oids2.js +1 -2
  26. package/dist/internal/asn1/oids2.js.map +1 -1
  27. package/dist/internal/crypto/algorithm-names.js +5 -2
  28. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  29. package/dist/internal/crypto/ecdsa.js +13 -8
  30. package/dist/internal/crypto/ecdsa.js.map +1 -1
  31. package/dist/internal/crypto/hash.js +1 -2
  32. package/dist/internal/crypto/hash.js.map +1 -1
  33. package/dist/internal/crypto/pbes2.d.ts +51 -0
  34. package/dist/internal/crypto/pbes2.js +86 -34
  35. package/dist/internal/crypto/pbes2.js.map +1 -1
  36. package/dist/internal/crypto/rsa-pss.js +48 -44
  37. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  38. package/dist/internal/crypto/sig-verify.d.ts +28 -0
  39. package/dist/internal/crypto/sig-verify.js +111 -62
  40. package/dist/internal/crypto/sig-verify.js.map +1 -1
  41. package/dist/internal/crypto/signing.d.ts +1 -4
  42. package/dist/internal/crypto/signing.js +28 -29
  43. package/dist/internal/crypto/signing.js.map +1 -1
  44. package/dist/internal/crypto/webcrypto.js +1 -2
  45. package/dist/internal/crypto/webcrypto.js.map +1 -1
  46. package/dist/internal/shared/base64.js +8 -3
  47. package/dist/internal/shared/base64.js.map +1 -1
  48. package/dist/internal/shared/dn.d.ts +13 -0
  49. package/dist/internal/shared/dn.js +101 -48
  50. package/dist/internal/shared/dn.js.map +1 -1
  51. package/dist/internal/shared/idna-tables.js +7217 -0
  52. package/dist/internal/shared/idna-tables.js.map +1 -0
  53. package/dist/internal/shared/idna.js +296 -0
  54. package/dist/internal/shared/idna.js.map +1 -0
  55. package/dist/internal/shared/ip.d.ts +66 -0
  56. package/dist/internal/shared/ip.js +19 -3
  57. package/dist/internal/shared/ip.js.map +1 -1
  58. package/dist/internal/shared/mailbox.js +26 -0
  59. package/dist/internal/shared/mailbox.js.map +1 -0
  60. package/dist/internal/shared/punycode.js +101 -0
  61. package/dist/internal/shared/punycode.js.map +1 -0
  62. package/dist/internal/shared/rfc3454-tables.js +1 -2
  63. package/dist/internal/shared/rfc3454-tables.js.map +1 -1
  64. package/dist/internal/shared/rfc4518-tables.js +119 -0
  65. package/dist/internal/shared/rfc4518-tables.js.map +1 -0
  66. package/dist/internal/shared/uri-host.js +102 -0
  67. package/dist/internal/shared/uri-host.js.map +1 -0
  68. package/dist/internal/verify/name-constraints-engine.js +246 -131
  69. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  70. package/dist/internal/verify/policy-engine.js +6 -21
  71. package/dist/internal/verify/policy-engine.js.map +1 -1
  72. package/dist/internal/verify/verify-path.d.ts +4 -0
  73. package/dist/internal/verify/verify-path.js +264 -128
  74. package/dist/internal/verify/verify-path.js.map +1 -1
  75. package/dist/internal/x509/directory-name.js +23 -0
  76. package/dist/internal/x509/directory-name.js.map +1 -0
  77. package/dist/internal/x509/extension-bits.js +15 -13
  78. package/dist/internal/x509/extension-bits.js.map +1 -1
  79. package/dist/internal/x509/extension-errors.d.ts +3 -0
  80. package/dist/internal/x509/extension-errors.js +19 -0
  81. package/dist/internal/x509/extension-errors.js.map +1 -0
  82. package/dist/internal/x509/extension-registry.js +157 -81
  83. package/dist/internal/x509/extension-registry.js.map +1 -1
  84. package/dist/internal/x509/general-name-profile.js +129 -0
  85. package/dist/internal/x509/general-name-profile.js.map +1 -0
  86. package/dist/internal/x509/general-name-tags.js +27 -0
  87. package/dist/internal/x509/general-name-tags.js.map +1 -0
  88. package/dist/internal/x509/general-name.js +183 -0
  89. package/dist/internal/x509/general-name.js.map +1 -0
  90. package/dist/internal/x509/name-fields.js +21 -12
  91. package/dist/internal/x509/name-fields.js.map +1 -1
  92. package/dist/internal/x509/or-address.js +217 -0
  93. package/dist/internal/x509/or-address.js.map +1 -0
  94. package/dist/keys/keys.d.ts +124 -95
  95. package/dist/keys/keys.js +362 -214
  96. package/dist/keys/keys.js.map +1 -1
  97. package/dist/keys.d.ts +3 -2
  98. package/dist/keys.js +3 -2
  99. package/dist/pem/pem.d.ts +17 -19
  100. package/dist/pem/pem.js +122 -41
  101. package/dist/pem/pem.js.map +1 -1
  102. package/dist/pem.js +1 -2
  103. package/dist/pkcs/pfx.d.ts +57 -32
  104. package/dist/pkcs/pfx.js +209 -173
  105. package/dist/pkcs/pfx.js.map +1 -1
  106. package/dist/pkcs/pkcs12-mac.d.ts +104 -27
  107. package/dist/pkcs/pkcs12-mac.js +266 -79
  108. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  109. package/dist/pkcs/pkcs7.d.ts +123 -53
  110. package/dist/pkcs/pkcs7.js +314 -238
  111. package/dist/pkcs/pkcs7.js.map +1 -1
  112. package/dist/pkcs.d.ts +5 -4
  113. package/dist/result/result.d.ts +43 -28
  114. package/dist/result/result.js +27 -14
  115. package/dist/result/result.js.map +1 -1
  116. package/dist/result.d.ts +2 -2
  117. package/dist/result.js +1 -2
  118. package/dist/revocation/chain.d.ts +101 -23
  119. package/dist/revocation/chain.js +456 -206
  120. package/dist/revocation/chain.js.map +1 -1
  121. package/dist/revocation/crl.d.ts +140 -65
  122. package/dist/revocation/crl.js +691 -391
  123. package/dist/revocation/crl.js.map +1 -1
  124. package/dist/revocation/ocsp.d.ts +145 -69
  125. package/dist/revocation/ocsp.js +347 -297
  126. package/dist/revocation/ocsp.js.map +1 -1
  127. package/dist/revocation/revocation.d.ts +48 -36
  128. package/dist/revocation/revocation.js +112 -63
  129. package/dist/revocation/revocation.js.map +1 -1
  130. package/dist/revocation.d.ts +5 -5
  131. package/dist/revocation.js +5 -5
  132. package/dist/verify/identity.d.ts +18 -20
  133. package/dist/verify/identity.js +120 -90
  134. package/dist/verify/identity.js.map +1 -1
  135. package/dist/verify/name-constraints.d.ts +1 -4
  136. package/dist/verify/policy.d.ts +15 -8
  137. package/dist/verify/verify.d.ts +86 -46
  138. package/dist/verify/verify.js +309 -143
  139. package/dist/verify/verify.js.map +1 -1
  140. package/dist/verify.d.ts +3 -2
  141. package/dist/verify.js +4 -3
  142. package/dist/x509/certificate.d.ts +50 -28
  143. package/dist/x509/certificate.js +69 -36
  144. package/dist/x509/certificate.js.map +1 -1
  145. package/dist/x509/csr.d.ts +9 -8
  146. package/dist/x509/csr.js +10 -11
  147. package/dist/x509/csr.js.map +1 -1
  148. package/dist/x509/extensions.d.ts +207 -82
  149. package/dist/x509/extensions.js +561 -128
  150. package/dist/x509/extensions.js.map +1 -1
  151. package/dist/x509/fingerprint.d.ts +4 -7
  152. package/dist/x509/fingerprint.js +1 -2
  153. package/dist/x509/fingerprint.js.map +1 -1
  154. package/dist/x509/name-text.d.ts +7 -9
  155. package/dist/x509/name-text.js +20 -4
  156. package/dist/x509/name-text.js.map +1 -1
  157. package/dist/x509/name.d.ts +15 -14
  158. package/dist/x509/name.js +23 -19
  159. package/dist/x509/name.js.map +1 -1
  160. package/dist/x509/parse.d.ts +165 -64
  161. package/dist/x509/parse.js +444 -459
  162. package/dist/x509/parse.js.map +1 -1
  163. package/dist/x509.d.ts +8 -5
  164. package/dist/x509.js +10 -8
  165. package/package.json +90 -65
@@ -1 +1 @@
1
- {"version":3,"file":"name-text.js","names":[],"sources":["../../src/x509/name-text.ts"],"sourcesContent":["/**\n * Human-readable text for parsed names.\n *\n * Renders a {@linkcode ParsedName} or {@linkcode SubjectAltName} as a display string,\n * covering every variant of the union without the caller narrowing it by hand.\n *\n * @module micro509/x509/name-text\n */\n\nimport { hexToBytes, toHex } from '#micro509/internal/asn1/asn1';\nimport { DN_ATTRIBUTE_KEYWORDS } from '#micro509/internal/x509/name-fields';\nimport type { SubjectAltName } from '#micro509/x509/extensions';\nimport type {\n\tParsedName,\n\tParsedNameAttribute,\n\tParsedRelativeDistinguishedName,\n} from '#micro509/x509/parse';\nimport { parseDistinguishedNameDer } from '#micro509/x509/parse';\n\n/** Options for {@linkcode subjectAltNameToString}. */\nexport interface SubjectAltNameTextOptions {\n\t/** Prepend `{@linkcode subjectAltNameLabel}:` to the value, as `openssl x509 -text` does. Defaults to `false`. */\n\treadonly prefix?: boolean;\n}\n\n/**\n * Renders one {@linkcode SubjectAltName} as text.\n *\n * | variant | rendering |\n * | --- | --- |\n * | `dns`, `ip`, `email`, `uri`, `srv` | the value itself |\n * | `directoryName` | {@linkcode distinguishedNameToString} of the embedded name, or the DER hex if it does not decode |\n * | `unknown` | lowercase hex of the raw content bytes |\n *\n * @example Render every SAN of a parsed certificate\n * ```ts\n * const names = (parsed.subjectAltNames ?? []).map((name) => subjectAltNameToString(name));\n * // ['example.com', '192.0.2.1', 'CN=Example CA,C=US']\n *\n * subjectAltNameToString({ type: 'dns', value: 'example.com' }, { prefix: true }); // 'DNS:example.com'\n * ```\n */\nexport function subjectAltNameToString(\n\tname: SubjectAltName,\n\toptions?: SubjectAltNameTextOptions,\n): string {\n\tconst text = subjectAltNameText(name);\n\treturn options?.prefix === true ? `${subjectAltNameLabel(name)}:${text}` : text;\n}\n\n/**\n * The `openssl x509 -text` label for a {@linkcode SubjectAltName} variant —\n * `DNS`, `IP Address`, `email`, `URI`, `SRV`, `DirName`, or `[tag <n>]` for an unrecognized tag.\n */\nexport function subjectAltNameLabel(name: SubjectAltName): string {\n\tswitch (name.type) {\n\t\tcase 'dns':\n\t\t\treturn 'DNS';\n\t\tcase 'ip':\n\t\t\treturn 'IP Address';\n\t\tcase 'email':\n\t\t\treturn 'email';\n\t\tcase 'uri':\n\t\t\treturn 'URI';\n\t\tcase 'srv':\n\t\t\treturn 'SRV';\n\t\tcase 'directoryName':\n\t\t\treturn 'DirName';\n\t\tcase 'unknown':\n\t\t\treturn `[tag ${String(name.tag)}]`;\n\t}\n}\n\n/**\n * Renders a {@linkcode ParsedName} as an RFC 4514 distinguished name string, e.g. `CN=Example CA,O=Acme,C=US`.\n *\n * RDNs are emitted in reverse encoding order and multi-valued RDNs are joined with `+`,\n * both per RFC 4514 [§2](https://datatracker.ietf.org/doc/html/rfc4514#section-2).\n * Attribute types outside the RFC 4514 [§3](https://datatracker.ietf.org/doc/html/rfc4514#section-3)\n * keyword table use the short names `openssl` prints, falling back to the dotted OID.\n *\n * @example\n * ```ts\n * distinguishedNameToString(parsed.subject); // 'CN=example.com,O=Acme\\\\, Inc.,C=US'\n * ```\n */\nexport function distinguishedNameToString(name: ParsedName): string {\n\treturn [...name.rdns]\n\t\t.reverse()\n\t\t.map((rdn) => relativeDistinguishedNameToString(rdn))\n\t\t.join(',');\n}\n\n/** Renders one {@linkcode ParsedRelativeDistinguishedName}, joining a multi-valued RDN's attributes with `+`. */\nexport function relativeDistinguishedNameToString(rdn: ParsedRelativeDistinguishedName): string {\n\treturn rdn.attributes.map((attribute) => attributeToString(attribute)).join('+');\n}\n\n/** Characters RFC 4514 [§2.4](https://datatracker.ietf.org/doc/html/rfc4514#section-2.4) escapes wherever they appear. */\nconst ESCAPED_CHARACTERS = new Set(['\"', '+', ',', ';', '<', '>', '\\\\']);\n\nfunction attributeToString(attribute: ParsedNameAttribute): string {\n\tconst keyword = DN_ATTRIBUTE_KEYWORDS[attribute.oid] ?? attribute.oid;\n\treturn `${keyword}=${escapeAttributeValue(attribute.value)}`;\n}\n\nfunction escapeAttributeValue(value: string): string {\n\tconst characters = [...value];\n\treturn characters\n\t\t.map((character, index) => {\n\t\t\tif (ESCAPED_CHARACTERS.has(character)) {\n\t\t\t\treturn `\\\\${character}`;\n\t\t\t}\n\t\t\tconst code = character.codePointAt(0) ?? 0;\n\t\t\tif (code < 0x20 || code === 0x7f) {\n\t\t\t\treturn `\\\\${code.toString(16).padStart(2, '0')}`;\n\t\t\t}\n\t\t\tif (character === ' ' && (index === 0 || index === characters.length - 1)) {\n\t\t\t\treturn '\\\\ ';\n\t\t\t}\n\t\t\treturn character === '#' && index === 0 ? '\\\\#' : character;\n\t\t})\n\t\t.join('');\n}\n\nfunction subjectAltNameText(name: SubjectAltName): string {\n\tswitch (name.type) {\n\t\tcase 'dns':\n\t\tcase 'ip':\n\t\tcase 'email':\n\t\tcase 'uri':\n\t\tcase 'srv':\n\t\t\treturn name.value;\n\t\tcase 'directoryName':\n\t\t\treturn directoryNameText(name.derHex);\n\t\tcase 'unknown':\n\t\t\treturn toHex(name.value);\n\t}\n}\n\nfunction directoryNameText(derHex: string): string {\n\ttry {\n\t\treturn distinguishedNameToString(parseDistinguishedNameDer(hexToBytes(derHex)));\n\t} catch {\n\t\treturn derHex;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,uBACf,GACA,GACS;CACT,IAAM,IAAO,mBAAmB,CAAI;CACpC,OAAO,GAAS,WAAW,KAAO,GAAG,oBAAoB,CAAI,EAAE,GAAG,MAAS;AAC5E;;;;;AAMA,SAAgB,oBAAoB,GAA8B;CACjE,QAAQ,EAAK,MAAb;EACC,KAAK,OACJ,OAAO;EACR,KAAK,MACJ,OAAO;EACR,KAAK,SACJ,OAAO;EACR,KAAK,OACJ,OAAO;EACR,KAAK,OACJ,OAAO;EACR,KAAK,iBACJ,OAAO;EACR,KAAK,WACJ,OAAO,QAAQ,OAAO,EAAK,GAAG,EAAE;CAClC;AACD;;;;;;;;;;;;;;AAeA,SAAgB,0BAA0B,GAA0B;CACnE,OAAO,CAAC,GAAG,EAAK,IAAI,CAAC,CACnB,QAAQ,CAAC,CACT,KAAK,MAAQ,kCAAkC,CAAG,CAAC,CAAC,CACpD,KAAK,GAAG;AACX;;AAGA,SAAgB,kCAAkC,GAA8C;CAC/F,OAAO,EAAI,WAAW,KAAK,MAAc,kBAAkB,CAAS,CAAC,CAAC,CAAC,KAAK,GAAG;AAChF;;AAGA,MAAM,oBAAqB,IAAI,IAAI;CAAC;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AAAI,CAAC;AAEvE,SAAS,kBAAkB,GAAwC;CAElE,OAAO,GADS,EAAsB,EAAU,QAAQ,EAAU,IAChD,GAAG,qBAAqB,EAAU,KAAK;AAC1D;AAEA,SAAS,qBAAqB,GAAuB;CACpD,IAAM,IAAa,CAAC,GAAG,CAAK;CAC5B,OAAO,EACL,KAAK,GAAW,MAAU;EAC1B,IAAI,EAAmB,IAAI,CAAS,GACnC,OAAO,KAAK;EAEb,IAAM,IAAO,EAAU,YAAY,CAAC,KAAK;EAOzC,OANI,IAAO,MAAQ,MAAS,MACpB,KAAK,EAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,MAE1C,MAAc,QAAQ,MAAU,KAAK,MAAU,EAAW,SAAS,KAC/D,QAED,MAAc,OAAO,MAAU,IAAI,QAAQ;CACnD,CAAC,CAAC,CACD,KAAK,EAAE;AACV;AAEA,SAAS,mBAAmB,GAA8B;CACzD,QAAQ,EAAK,MAAb;EACC,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,OACJ,OAAO,EAAK;EACb,KAAK,iBACJ,OAAO,kBAAkB,EAAK,MAAM;EACrC,KAAK,WACJ,OAAO,EAAM,EAAK,KAAK;CACzB;AACD;AAEA,SAAS,kBAAkB,GAAwB;CAClD,IAAI;EACH,OAAO,0BAA0B,EAA0B,EAAW,CAAM,CAAC,CAAC;CAC/E,QAAQ;EACP,OAAO;CACR;AACD"}
1
+ {"version":3,"file":"name-text.js","names":["_exhaustive","text","name","options","rdn","attribute","ESCAPED_CHARACTERS","DN_ATTRIBUTE_KEYWORDS","characters","value","character","code","index","toHex","parseDistinguishedNameDer","hexToBytes","derHex"],"sources":["../../src/x509/name-text.ts"],"sourcesContent":["/**\n * Human-readable text for parsed names.\n *\n * Renders a {@linkcode ParsedName} or {@linkcode SubjectAltName} as a display string,\n * covering every variant of the union without the caller narrowing it by hand.\n *\n * @module micro509/x509/name-text\n */\n\nimport { hexToBytes, toHex } from '#micro509/internal/asn1/asn1';\nimport { DN_ATTRIBUTE_KEYWORDS } from '#micro509/internal/x509/name-fields';\nimport type { SubjectAltName } from '#micro509/x509/extensions';\nimport type {\n\tParsedName,\n\tParsedNameAttribute,\n\tParsedRelativeDistinguishedName,\n} from '#micro509/x509/parse';\nimport { parseDistinguishedNameDer } from '#micro509/x509/parse';\n\n/** Options for {@linkcode subjectAltNameToString}. */\nexport interface SubjectAltNameTextOptions {\n\t/** Prepend `{@linkcode subjectAltNameLabel}:` to the value, as `openssl x509 -text` does. Defaults to `false`. */\n\treadonly prefix?: boolean;\n}\n\n/**\n * Renders one {@linkcode SubjectAltName} as text.\n *\n * | variant | rendering |\n * | --- | --- |\n * | `dns`, `ip`, `email`, `uri`, `srv` | the value itself |\n * | `directoryName` | {@linkcode distinguishedNameToString} of the embedded name, or the DER hex if it does not decode |\n * | `unknown` | lowercase hex of the raw content bytes |\n *\n * @example Render every SAN of a parsed certificate\n * ```ts\n * const names = (parsed.subjectAltNames ?? []).map((name) => subjectAltNameToString(name));\n * // ['example.com', '192.0.2.1', 'CN=Example CA,C=US']\n *\n * subjectAltNameToString({ type: 'dns', value: 'example.com' }, { prefix: true }); // 'DNS:example.com'\n * ```\n */\nexport function subjectAltNameToString(\n\tname: SubjectAltName,\n\toptions?: SubjectAltNameTextOptions,\n): string {\n\tconst text = subjectAltNameText(name);\n\treturn options?.prefix === true ? `${subjectAltNameLabel(name)}:${text}` : text;\n}\n\n/**\n * The `openssl x509 -text` label for a {@linkcode SubjectAltName} variant —\n * `DNS`, `IP Address`, `email`, `URI`, `SRV`, `SmtpUTF8Mailbox`, `UPN`, `KRB5PrincipalName`, `DirName`, `othername`, `X400Name`,\n * `EdiPartyName`, `Registered ID`, or `[tag <n>]` for raw `unknown` input.\n */\nexport function subjectAltNameLabel(name: SubjectAltName): string {\n\tswitch (name.type) {\n\t\tcase 'dns':\n\t\t\treturn 'DNS';\n\t\tcase 'ip':\n\t\t\treturn 'IP Address';\n\t\tcase 'email':\n\t\t\treturn 'email';\n\t\tcase 'uri':\n\t\t\treturn 'URI';\n\t\tcase 'srv':\n\t\t\treturn 'SRV';\n\t\tcase 'smtpUtf8Mailbox':\n\t\t\treturn 'SmtpUTF8Mailbox';\n\t\tcase 'upn':\n\t\t\treturn 'UPN';\n\t\tcase 'krb5PrincipalName':\n\t\t\treturn 'KRB5PrincipalName';\n\t\tcase 'directoryName':\n\t\t\treturn 'DirName';\n\t\tcase 'otherName':\n\t\t\treturn 'othername';\n\t\tcase 'x400Address':\n\t\t\treturn 'X400Name';\n\t\tcase 'ediPartyName':\n\t\t\treturn 'EdiPartyName';\n\t\tcase 'registeredID':\n\t\t\treturn 'Registered ID';\n\t\tcase 'unknown':\n\t\t\treturn `[tag ${String(name.tag)}]`;\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = name;\n\t\t\tthrow new Error(`Unhandled SubjectAltName type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/**\n * Renders a {@linkcode ParsedName} as an RFC 4514 distinguished name string, e.g. `CN=Example CA,O=Acme,C=US`.\n *\n * RDNs are emitted in reverse encoding order and multi-valued RDNs are joined with `+`,\n * both per RFC 4514 [§2](https://datatracker.ietf.org/doc/html/rfc4514#section-2).\n * Attribute types outside the RFC 4514 [§3](https://datatracker.ietf.org/doc/html/rfc4514#section-3)\n * keyword table use the short names `openssl` prints, falling back to the dotted OID.\n *\n * @example\n * ```ts\n * distinguishedNameToString(parsed.subject); // 'CN=example.com,O=Acme\\\\, Inc.,C=US'\n * ```\n */\nexport function distinguishedNameToString(name: ParsedName): string {\n\treturn [...name.rdns]\n\t\t.reverse()\n\t\t.map((rdn) => relativeDistinguishedNameToString(rdn))\n\t\t.join(',');\n}\n\n/** Renders one {@linkcode ParsedRelativeDistinguishedName}, joining a multi-valued RDN's attributes with `+`. */\nexport function relativeDistinguishedNameToString(rdn: ParsedRelativeDistinguishedName): string {\n\treturn rdn.attributes.map((attribute) => attributeToString(attribute)).join('+');\n}\n\n/** Characters RFC 4514 [§2.4](https://datatracker.ietf.org/doc/html/rfc4514#section-2.4) escapes wherever they appear. */\nconst ESCAPED_CHARACTERS = new Set(['\"', '+', ',', ';', '<', '>', '\\\\']);\n\nfunction attributeToString(attribute: ParsedNameAttribute): string {\n\tconst keyword = DN_ATTRIBUTE_KEYWORDS[attribute.oid] ?? attribute.oid;\n\treturn `${keyword}=${escapeAttributeValue(attribute.value)}`;\n}\n\nfunction escapeAttributeValue(value: string): string {\n\tconst characters = [...value];\n\treturn characters\n\t\t.map((character, index) => {\n\t\t\tif (ESCAPED_CHARACTERS.has(character)) {\n\t\t\t\treturn `\\\\${character}`;\n\t\t\t}\n\t\t\tconst code = character.codePointAt(0) ?? 0;\n\t\t\tif (code < 0x20 || code === 0x7f) {\n\t\t\t\treturn `\\\\${code.toString(16).padStart(2, '0')}`;\n\t\t\t}\n\t\t\tif (character === ' ' && (index === 0 || index === characters.length - 1)) {\n\t\t\t\treturn '\\\\ ';\n\t\t\t}\n\t\t\treturn character === '#' && index === 0 ? '\\\\#' : character;\n\t\t})\n\t\t.join('');\n}\n\nfunction subjectAltNameText(name: SubjectAltName): string {\n\tswitch (name.type) {\n\t\tcase 'dns':\n\t\tcase 'ip':\n\t\tcase 'email':\n\t\tcase 'uri':\n\t\tcase 'srv':\n\t\tcase 'smtpUtf8Mailbox':\n\t\tcase 'upn':\n\t\tcase 'registeredID':\n\t\t\treturn name.value;\n\t\tcase 'krb5PrincipalName':\n\t\t\treturn `${name.nameString.join('/')}@${name.realm}`;\n\t\tcase 'directoryName':\n\t\t\treturn directoryNameText(name.derHex);\n\t\tcase 'otherName':\n\t\t\treturn `${name.typeId}:${toHex(name.value)}`;\n\t\tcase 'x400Address':\n\t\tcase 'ediPartyName':\n\t\t\treturn toHex(name.value);\n\t\tcase 'unknown':\n\t\t\treturn toHex(name.value);\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = name;\n\t\t\tthrow new Error(`Unhandled SubjectAltName type: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\nfunction directoryNameText(derHex: string): string {\n\ttry {\n\t\treturn distinguishedNameToString(parseDistinguishedNameDer(hexToBytes(derHex)));\n\t} catch {\n\t\treturn derHex;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,uBACf,GACA,GACS;CACT,IAAMC,IAAO,mBAAmBC,CAAI;CACpC,OAAOC,GAAS,WAAW,KAAO,GAAG,oBAAoBD,CAAI,EAAE,GAAGD,MAASA;AAC5E;;;;;;AAOA,SAAgB,oBAAoB,GAA8B;CACjE,QAAQC,EAAK,MAAb;EACC,KAAK,OACJ,OAAO;EACR,KAAK,MACJ,OAAO;EACR,KAAK,SACJ,OAAO;EACR,KAAK,OACJ,OAAO;EACR,KAAK,OACJ,OAAO;EACR,KAAK,mBACJ,OAAO;EACR,KAAK,OACJ,OAAO;EACR,KAAK,qBACJ,OAAO;EACR,KAAK,iBACJ,OAAO;EACR,KAAK,aACJ,OAAO;EACR,KAAK,eACJ,OAAO;EACR,KAAK,gBACJ,OAAO;EACR,KAAK,gBACJ,OAAO;EACR,KAAK,WACJ,OAAO,QAAQ,OAAOA,EAAK,GAAG,EAAE;EACjC,SAEC,MAAU,MAAM,kCAAkC,OAAOF,CAAW,GAAG;CAEzE;AACD;;;;;;;;;;;;;;AAeA,SAAgB,0BAA0B,GAA0B;CACnE,OAAO,CAAC,GAAGE,EAAK,IAAI,CAAC,CACnB,QAAQ,CAAC,CACT,KAAK,MAAQ,kCAAkCE,CAAG,CAAC,CAAC,CACpD,KAAK,GAAG;AACX;;AAGA,SAAgB,kCAAkC,GAA8C;CAC/F,OAAOA,EAAI,WAAW,KAAK,MAAc,kBAAkBC,CAAS,CAAC,CAAC,CAAC,KAAK,GAAG;AAChF;;AAGA,MAAMC,oBAAqB,IAAI,IAAI;CAAC;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AAAI,CAAC;AAEvE,SAAS,kBAAkB,GAAwC;CAElE,OAAO,GADSC,EAAsBF,EAAU,QAAQA,EAAU,IAChD,GAAG,qBAAqBA,EAAU,KAAK;AAC1D;AAEA,SAAS,qBAAqB,GAAuB;CACpD,IAAMG,IAAa,CAAC,GAAGC,CAAK;CAC5B,OAAOD,EACL,KAAK,GAAW,MAAU;EAC1B,IAAIF,EAAmB,IAAII,CAAS,GACnC,OAAO,KAAKA;EAEb,IAAMC,IAAOD,EAAU,YAAY,CAAC,KAAK;EAOzC,OANIC,IAAO,MAAQA,MAAS,MACpB,KAAKA,EAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,MAE1CD,MAAc,QAAQE,MAAU,KAAKA,MAAUJ,EAAW,SAAS,KAC/D,QAEDE,MAAc,OAAOE,MAAU,IAAI,QAAQF;CACnD,CAAC,CAAC,CACD,KAAK,EAAE;AACV;AAEA,SAAS,mBAAmB,GAA8B;CACzD,QAAQR,EAAK,MAAb;EACC,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,gBACJ,OAAOA,EAAK;EACb,KAAK,qBACJ,OAAO,GAAGA,EAAK,WAAW,KAAK,GAAG,EAAE,GAAGA,EAAK;EAC7C,KAAK,iBACJ,OAAO,kBAAkBA,EAAK,MAAM;EACrC,KAAK,aACJ,OAAO,GAAGA,EAAK,OAAO,GAAGW,EAAMX,EAAK,KAAK;EAC1C,KAAK;EACL,KAAK,gBACJ,OAAOW,EAAMX,EAAK,KAAK;EACxB,KAAK,WACJ,OAAOW,EAAMX,EAAK,KAAK;EACxB,SAEC,MAAU,MAAM,kCAAkC,OAAOF,CAAW,GAAG;CAEzE;AACD;AAEA,SAAS,kBAAkB,GAAwB;CAClD,IAAI;EACH,OAAO,0BAA0Bc,EAA0BC,EAAWC,CAAM,CAAC,CAAC;CAC/E,QAAQ;EACP,OAAOA;CACR;AACD"}
@@ -1,10 +1,12 @@
1
- //#region src/x509/name.d.ts
1
+ import { canonicalDnKey, compareDistinguishedNames, isWithinDirectoryNameSubtree } from "../internal/shared/dn.js";
2
+ /** Machine-readable reason a distinguished-name encoder rejected its construction input. */
3
+ export type NameEncoderErrorCode = "relative_distinguished_name_empty" | "unsupported_name_field" | "name_attribute_empty" | "name_attribute_too_long" | "name_attribute_lone_surrogate" | "invalid_country_code";
2
4
  /**
3
- * Union of recognized X.501 attribute type shorthand names.
5
+ * Union of recognized distinguished-name attribute type shorthand names.
4
6
  *
5
7
  * Each key maps to an OID + ASN.1 string encoding in `NAME_FIELD_DEFINITIONS`.
6
8
  */
7
- type NameFieldKey = "commonName" | "surname" | "serialNumber" | "country" | "locality" | "state" | "street" | "organization" | "organizationalUnit" | "title" | "givenName" | "emailAddress";
9
+ export type NameFieldKey = "commonName" | "surname" | "serialNumber" | "country" | "locality" | "state" | "street" | "organization" | "organizationalUnit" | "title" | "givenName" | "emailAddress";
8
10
  /**
9
11
  * Convenience object form of an X.501 distinguished name.
10
12
  *
@@ -15,7 +17,7 @@ type NameFieldKey = "commonName" | "surname" | "serialNumber" | "country" | "loc
15
17
  * For caller-controlled ordering, pass a {@linkcode NameAttribute} array to {@linkcode encodeName}.\
16
18
  * For multi-valued RDNs, use {@linkcode encodeRelativeDistinguishedName}.
17
19
  */
18
- interface NameObject {
20
+ export interface NameObject {
19
21
  /** Subject or issuer common name (CN). */
20
22
  readonly commonName?: string;
21
23
  /** Subject surname (SN). */
@@ -38,7 +40,7 @@ interface NameObject {
38
40
  readonly title?: string;
39
41
  /** First / given name (GN). */
40
42
  readonly givenName?: string;
41
- /** RFC 822 email address. Encoded as IA5String, not UTF-8. */
43
+ /** PKCS #9 emailAddress attribute (RFC 2985 §5.2.1). Encoded as IA5String, not UTF-8. RFC 5280 §4.1.2.6 deprecates it in favour of a subjectAltName rfc822Name. */
42
44
  readonly emailAddress?: string;
43
45
  }
44
46
  /**
@@ -50,7 +52,7 @@ interface NameObject {
50
52
  * {@linkcode encodeName} places each attribute in its own single-attribute RDN.\
51
53
  * {@linkcode encodeRelativeDistinguishedName} packs several attributes into one RDN.
52
54
  */
53
- interface NameAttribute {
55
+ export interface NameAttribute {
54
56
  /** Which attribute type this pair represents. */
55
57
  readonly type: NameFieldKey;
56
58
  /** The string value for this attribute (encoding chosen per field definition). */
@@ -62,7 +64,7 @@ interface NameAttribute {
62
64
  * Accepts either a {@linkcode NameObject} convenience shape or an ordered array of {@linkcode NameAttribute} pairs.\
63
65
  * Both forms encode one attribute per RDN.
64
66
  */
65
- type NameInput = NameObject | readonly NameAttribute[];
67
+ export type NameInput = NameObject | readonly NameAttribute[];
66
68
  /**
67
69
  * Input for {@linkcode encodeRelativeDistinguishedName}.
68
70
  *
@@ -71,7 +73,7 @@ type NameInput = NameObject | readonly NameAttribute[];
71
73
  *
72
74
  * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 RFC 5280 Appendix A.1}
73
75
  */
74
- type RelativeDistinguishedNameInput = readonly NameAttribute[];
76
+ export type RelativeDistinguishedNameInput = readonly NameAttribute[];
75
77
  /**
76
78
  * DER-encodes an X.509 `Name`.
77
79
  *
@@ -106,9 +108,9 @@ type RelativeDistinguishedNameInput = readonly NameAttribute[];
106
108
  *
107
109
  * @param input Name fields in convenience-object form or caller-ordered attribute form.
108
110
  * @returns DER-encoded X.509 `Name` bytes.
109
- * @throws {Error} If the input produces no attributes, contains an unsupported field key, or uses an invalid country code.
111
+ * @throws {ResultError} If a value exceeds its RFC 5280 A.1 bound, an ordered attribute value is empty, a field key is unsupported, or a country code is not two characters. An input with no attributes encodes an empty Name (`30 00`) rather than throwing.
110
112
  */
111
- declare function encodeName(input: NameInput): Uint8Array;
113
+ export declare function encodeName(input: NameInput): Uint8Array;
112
114
  /**
113
115
  * DER-encodes a single RelativeDistinguishedName (RDN).
114
116
  *
@@ -132,9 +134,8 @@ declare function encodeName(input: NameInput): Uint8Array;
132
134
  *
133
135
  * @param attributes Attribute list to encode inside one RDN.
134
136
  * @returns DER-encoded RelativeDistinguishedName bytes.
135
- * @throws {Error} If the attribute list is empty, contains an unsupported field key, or uses an invalid country code.
137
+ * @throws {ResultError} If the attribute list is empty, contains an unsupported field key, an empty or over-long value, or an invalid country code.
136
138
  */
137
- declare function encodeRelativeDistinguishedName(attributes: RelativeDistinguishedNameInput): Uint8Array;
138
- //#endregion
139
- export { NameAttribute, NameFieldKey, NameInput, NameObject, RelativeDistinguishedNameInput, encodeName, encodeRelativeDistinguishedName };
139
+ export declare function encodeRelativeDistinguishedName(attributes: RelativeDistinguishedNameInput): Uint8Array;
140
+ export { canonicalDnKey, compareDistinguishedNames, isWithinDirectoryNameSubtree };
140
141
  //# sourceMappingURL=name.d.ts.map
package/dist/x509/name.js CHANGED
@@ -1,6 +1,8 @@
1
- import { objectIdentifier as e, sequence as t, setOf as n } from "../internal/asn1/der.js";
2
- import { NAME_FIELD_DEFINITIONS as r, NAME_OBJECT_ORDER as i, nameFieldKeyFromOid as a } from "../internal/x509/name-fields.js";
3
- //#region src/x509/name.ts
1
+ import { throwMicro509Error as e } from "../result/result.js";
2
+ import { hasLoneSurrogate as t, objectIdentifier as n, sequence as r, setOf as i } from "../internal/asn1/der.js";
3
+ import { NAME_FIELD_DEFINITIONS as a, NAME_OBJECT_ORDER as o, nameFieldKeyFromOid as s } from "../internal/x509/name-fields.js";
4
+ import { canonicalDnKey as c, compareDistinguishedNames as l, isWithinDirectoryNameSubtree as u } from "../internal/shared/dn.js";
5
+ // src/x509/name.ts
4
6
  /**
5
7
  * Distinguished-name input and DER encoding helpers.
6
8
  *
@@ -64,6 +66,10 @@ import { NAME_FIELD_DEFINITIONS as r, NAME_OBJECT_ORDER as i, nameFieldKeyFromOi
64
66
  *
65
67
  * @module
66
68
  */
69
+ /** Throws a {@link ResultError} for a distinguished-name encoder input-validation failure. */
70
+ function throwNameEncoderError(t, n) {
71
+ e(t, n);
72
+ }
67
73
  /**
68
74
  * DER-encodes an X.509 `Name`.
69
75
  *
@@ -98,11 +104,11 @@ import { NAME_FIELD_DEFINITIONS as r, NAME_OBJECT_ORDER as i, nameFieldKeyFromOi
98
104
  *
99
105
  * @param input Name fields in convenience-object form or caller-ordered attribute form.
100
106
  * @returns DER-encoded X.509 `Name` bytes.
101
- * @throws {Error} If the input produces no attributes, contains an unsupported field key, or uses an invalid country code.
107
+ * @throws {ResultError} If a value exceeds its RFC 5280 A.1 bound, an ordered attribute value is empty, a field key is unsupported, or a country code is not two characters. An input with no attributes encodes an empty Name (`30 00`) rather than throwing.
102
108
  */
103
109
  function encodeName(e) {
104
- let n = isNameAttributes(e) ? e : nameObjectToAttributes(e);
105
- return n.length === 0 ? t([]) : t(n.map(encodeNameAttributeAsSet));
110
+ let t = isNameAttributes(e) ? e : nameObjectToAttributes(e);
111
+ return t.length === 0 ? r([]) : r(t.map(encodeNameAttributeAsSet));
106
112
  }
107
113
  /** True when a {@linkcode NameInput} resolves to zero attributes (empty DN). */
108
114
  function isNameInputEmpty(e) {
@@ -131,11 +137,10 @@ function isNameInputEmpty(e) {
131
137
  *
132
138
  * @param attributes Attribute list to encode inside one RDN.
133
139
  * @returns DER-encoded RelativeDistinguishedName bytes.
134
- * @throws {Error} If the attribute list is empty, contains an unsupported field key, or uses an invalid country code.
140
+ * @throws {ResultError} If the attribute list is empty, contains an unsupported field key, an empty or over-long value, or an invalid country code.
135
141
  */
136
142
  function encodeRelativeDistinguishedName(e) {
137
- if (e.length === 0) throw Error("Relative distinguished name must contain at least one attribute");
138
- return n(e.map(encodeNameAttribute));
143
+ return e.length === 0 && throwNameEncoderError("relative_distinguished_name_empty", "Relative distinguished name must contain at least one attribute"), i(e.map(encodeNameAttribute));
139
144
  }
140
145
  /** Narrows a {@linkcode NameInput} to the ordered-attribute-array form. */
141
146
  function isNameAttributes(e) {
@@ -143,23 +148,23 @@ function isNameAttributes(e) {
143
148
  }
144
149
  /** Wraps a single attribute in a SET OF for the Name SEQUENCE. */
145
150
  function encodeNameAttributeAsSet(e) {
146
- return n([encodeNameAttribute(e)]);
151
+ return i([encodeNameAttribute(e)]);
147
152
  }
148
153
  /**
149
154
  * DER-encodes one name attribute SEQUENCE.
150
155
  *
151
- * Throws for unsupported field keys and invalid country codes.
156
+ * Throws for unsupported field keys, empty or over-long values, and invalid country codes.
152
157
  */
153
- function encodeNameAttribute(n) {
154
- let i = r[n.type];
155
- if (i === void 0) throw Error(`Unsupported name field: ${n.type}`);
156
- if (n.type === "country" && n.value.length !== 2) throw Error("Country must be a 2-character code");
157
- return t([e(i.oid), i.encode(n.value)]);
158
+ function encodeNameAttribute(e) {
159
+ let i = a[e.type];
160
+ i === void 0 && throwNameEncoderError("unsupported_name_field", `Unsupported name field: ${e.type}`);
161
+ let o = [...e.value].length;
162
+ return o === 0 && throwNameEncoderError("name_attribute_empty", `Name attribute ${e.type} must not be empty`), t(e.value) && throwNameEncoderError("name_attribute_lone_surrogate", `Name attribute ${e.type} holds a lone UTF-16 surrogate`), e.type === "country" && e.value.length !== 2 && throwNameEncoderError("invalid_country_code", "Country must be a 2-character code"), i.maxLength !== void 0 && o > i.maxLength && throwNameEncoderError("name_attribute_too_long", `Name attribute ${e.type} must be at most ${i.maxLength} characters`), r([n(i.oid), i.encode(e.value)]);
158
163
  }
159
164
  /** Converts a {@linkcode NameObject} to ordered attributes per `NAME_OBJECT_ORDER`. */
160
165
  function nameObjectToAttributes(e) {
161
166
  let t = [];
162
- for (let n of i) {
167
+ for (let n of o) {
163
168
  let r = e[n];
164
169
  typeof r == "string" && r.length > 0 && t.push({
165
170
  type: n,
@@ -168,7 +173,6 @@ function nameObjectToAttributes(e) {
168
173
  }
169
174
  return t;
170
175
  }
171
- //#endregion
172
- export { encodeName, encodeRelativeDistinguishedName, isNameInputEmpty, a as nameFieldKeyFromOid };
176
+ export { c as canonicalDnKey, l as compareDistinguishedNames, encodeName, encodeRelativeDistinguishedName, isNameInputEmpty, u as isWithinDirectoryNameSubtree, s as nameFieldKeyFromOid };
173
177
 
174
178
  //# sourceMappingURL=name.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"name.js","names":[],"sources":["../../src/x509/name.ts"],"sourcesContent":["/**\n * Distinguished-name input and DER encoding helpers.\n *\n * Encodes X.509 `Name` values used for certificate subjects, issuers,\n * and CSR subjects.\\\n * A `Name` is a DER `SEQUENCE` of RelativeDistinguishedNames (RDNs), and each\n * RDN is a `SET OF` one or more name attributes.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 RFC 5280 Appendix A.1}\n *\n * Use {@linkcode encodeName} for the common case where each attribute occupies\n * its own RDN.\\\n * Use {@linkcode encodeRelativeDistinguishedName} when you need one\n * multi-valued RDN.\n *\n * `NameObject` favors convenience: populated fields are emitted in the\n * canonical order from `NAME_OBJECT_ORDER`.\\\n * `NameAttribute` arrays favor control: caller order is preserved, but each\n * entry still becomes its own single-attribute RDN.\n *\n * Attribute OIDs and ASN.1 string encodings come from\n * `NAME_FIELD_DEFINITIONS`.\n *\n * @example\n * ```ts\n * import { encodeName } from 'micro509/x509';\n *\n * const subjectDer = encodeName({\n * \tcountry: 'US',\n * \torganization: 'ACME Inc',\n * \tcommonName: 'example.com',\n * });\n *\n * // DER for: C=US, O=ACME Inc, CN=example.com\n * ```\n *\n * @example\n * ```ts\n * import { encodeName } from 'micro509/x509';\n *\n * const subjectDer = encodeName([\n * \t{ type: 'commonName', value: 'example.com' },\n * \t{ type: 'organization', value: 'ACME Inc' },\n * \t{ type: 'country', value: 'US' },\n * ]);\n *\n * // preserves caller-supplied attribute order\n * ```\n *\n * @example\n * ```ts\n * import { encodeRelativeDistinguishedName } from 'micro509/x509';\n *\n * const rdnDer = encodeRelativeDistinguishedName([\n * \t{ type: 'commonName', value: 'example.com' },\n * \t{ type: 'serialNumber', value: 'device-7' },\n * ]);\n *\n * // one multi-valued RDN containing CN + serialNumber\n * ```\n *\n * @module\n */\n\nimport { objectIdentifier, sequence, setOf } from '#micro509/internal/asn1/der';\nimport { NAME_FIELD_DEFINITIONS, NAME_OBJECT_ORDER } from '#micro509/internal/x509/name-fields';\n\n/**\n * Union of recognized X.501 attribute type shorthand names.\n *\n * Each key maps to an OID + ASN.1 string encoding in `NAME_FIELD_DEFINITIONS`.\n */\nexport type NameFieldKey =\n\t| 'commonName'\n\t| 'surname'\n\t| 'serialNumber'\n\t| 'country'\n\t| 'locality'\n\t| 'state'\n\t| 'street'\n\t| 'organization'\n\t| 'organizationalUnit'\n\t| 'title'\n\t| 'givenName'\n\t| 'emailAddress';\n\n/**\n * Convenience object form of an X.501 distinguished name.\n *\n * Populated fields are emitted in the order defined by\n * `NAME_OBJECT_ORDER`.\\\n * Each populated field becomes its own single-attribute RDN.\n *\n * For caller-controlled ordering, pass a {@linkcode NameAttribute} array to {@linkcode encodeName}.\\\n * For multi-valued RDNs, use {@linkcode encodeRelativeDistinguishedName}.\n */\nexport interface NameObject {\n\t/** Subject or issuer common name (CN). */\n\treadonly commonName?: string;\n\t/** Subject surname (SN). */\n\treadonly surname?: string;\n\t/** Device or entity serial number — not the certificate serial. */\n\treadonly serialNumber?: string;\n\t/** ISO 3166 two-letter country code (C). Must be exactly 2 characters. */\n\treadonly country?: string;\n\t/** City or locality (L). */\n\treadonly locality?: string;\n\t/** State or province (ST). */\n\treadonly state?: string;\n\t/** Street address. */\n\treadonly street?: string;\n\t/** Organization name (O). */\n\treadonly organization?: string;\n\t/** Organizational unit (OU). Deprecated in modern CA practice. */\n\treadonly organizationalUnit?: string;\n\t/** Job title or functional designation. */\n\treadonly title?: string;\n\t/** First / given name (GN). */\n\treadonly givenName?: string;\n\t/** RFC 822 email address. Encoded as IA5String, not UTF-8. */\n\treadonly emailAddress?: string;\n}\n\n/**\n * Single name attribute within a distinguished name.\n *\n * RFC 5280 / X.501 call this structure an `AttributeTypeAndValue`.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 RFC 5280 Appendix A.1}\n * {@linkcode encodeName} places each attribute in its own single-attribute RDN.\\\n * {@linkcode encodeRelativeDistinguishedName} packs several attributes into one RDN.\n */\nexport interface NameAttribute {\n\t/** Which attribute type this pair represents. */\n\treadonly type: NameFieldKey;\n\t/** The string value for this attribute (encoding chosen per field definition). */\n\treadonly value: string;\n}\n\n/**\n * Input for {@linkcode encodeName}.\n *\n * Accepts either a {@linkcode NameObject} convenience shape or an ordered array of {@linkcode NameAttribute} pairs.\\\n * Both forms encode one attribute per RDN.\n */\nexport type NameInput = NameObject | readonly NameAttribute[];\n\n/**\n * Input for {@linkcode encodeRelativeDistinguishedName}.\n *\n * Each entry becomes one name attribute inside the RDN's `SET OF`.\\\n * Use this shape for multi-valued RDNs.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 RFC 5280 Appendix A.1}\n */\nexport type RelativeDistinguishedNameInput = readonly NameAttribute[];\n\nexport { nameFieldKeyFromOid } from '#micro509/internal/x509/name-fields';\n\n/**\n * DER-encodes an X.509 `Name`.\n *\n * Returns a DER `SEQUENCE` of RelativeDistinguishedNames (RDNs).\\\n * Each RDN emitted by this helper contains exactly one name attribute.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 RFC 5280 Appendix A.1}\n *\n * {@linkcode NameObject} input emits populated fields in the canonical order from `NAME_OBJECT_ORDER`.\\\n * {@linkcode NameAttribute} array input preserves caller-supplied ordering,\n * but each entry still becomes its own single-attribute RDN.\n *\n * Attribute OIDs and ASN.1 string encodings come from `NAME_FIELD_DEFINITIONS`.\\\n * Empty strings and `undefined` fields are ignored when the input is a {@linkcode NameObject}.\n *\n * @example\n * ```ts\n * const der = encodeName({ country: 'US', commonName: 'example.com' });\n *\n * // emits two single-attribute RDNs: C=US, then CN=example.com\n * ```\n *\n * @example\n * ```ts\n * const der = encodeName([\n * \t{ type: 'country', value: 'US' },\n * \t{ type: 'commonName', value: 'example.com' },\n * ]);\n *\n * // preserves caller order: C first, then CN\n * ```\n *\n * @param input Name fields in convenience-object form or caller-ordered attribute form.\n * @returns DER-encoded X.509 `Name` bytes.\n * @throws {Error} If the input produces no attributes, contains an unsupported field key, or uses an invalid country code.\n */\nexport function encodeName(input: NameInput): Uint8Array {\n\tconst attributes = isNameAttributes(input) ? input : nameObjectToAttributes(input);\n\tif (attributes.length === 0) {\n\t\treturn sequence([]);\n\t}\n\n\treturn sequence(attributes.map(encodeNameAttributeAsSet));\n}\n\n/** True when a {@linkcode NameInput} resolves to zero attributes (empty DN). */\nexport function isNameInputEmpty(input: NameInput): boolean {\n\tconst attributes = isNameAttributes(input) ? input : nameObjectToAttributes(input);\n\treturn attributes.length === 0;\n}\n\n/**\n * DER-encodes a single RelativeDistinguishedName (RDN).\n *\n * Returns a DER `SET OF` name attributes for one X.509 name segment.\\\n * Use this when you need a multi-valued RDN.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 RFC 5280 Appendix A.1}\n *\n * Attribute OIDs and ASN.1 string encodings come from\n * `NAME_FIELD_DEFINITIONS`.\n *\n * @example\n * ```ts\n * const rdn = encodeRelativeDistinguishedName([\n * \t{ type: 'commonName', value: 'example.com' },\n * \t{ type: 'serialNumber', value: 'device-7' },\n * ]);\n *\n * // emits one RDN with both attributes in the same SET\n * ```\n *\n * @param attributes Attribute list to encode inside one RDN.\n * @returns DER-encoded RelativeDistinguishedName bytes.\n * @throws {Error} If the attribute list is empty, contains an unsupported field key, or uses an invalid country code.\n */\nexport function encodeRelativeDistinguishedName(\n\tattributes: RelativeDistinguishedNameInput,\n): Uint8Array {\n\tif (attributes.length === 0) {\n\t\tthrow new Error('Relative distinguished name must contain at least one attribute');\n\t}\n\treturn setOf(attributes.map(encodeNameAttribute));\n}\n\n/** Narrows a {@linkcode NameInput} to the ordered-attribute-array form. */\nfunction isNameAttributes(input: NameInput): input is readonly NameAttribute[] {\n\treturn Array.isArray(input);\n}\n\n/** Wraps a single attribute in a SET OF for the Name SEQUENCE. */\nfunction encodeNameAttributeAsSet(attribute: NameAttribute): Uint8Array {\n\treturn setOf([encodeNameAttribute(attribute)]);\n}\n\n/**\n * DER-encodes one name attribute SEQUENCE.\n *\n * Throws for unsupported field keys and invalid country codes.\n */\nfunction encodeNameAttribute(attribute: NameAttribute): Uint8Array {\n\tconst definition = NAME_FIELD_DEFINITIONS[attribute.type];\n\tif (definition === undefined) {\n\t\tthrow new Error(`Unsupported name field: ${attribute.type}`);\n\t}\n\tif (attribute.type === 'country' && attribute.value.length !== 2) {\n\t\tthrow new Error('Country must be a 2-character code');\n\t}\n\treturn sequence([objectIdentifier(definition.oid), definition.encode(attribute.value)]);\n}\n\n/** Converts a {@linkcode NameObject} to ordered attributes per `NAME_OBJECT_ORDER`. */\nfunction nameObjectToAttributes(input: NameObject): readonly NameAttribute[] {\n\tconst attributes: NameAttribute[] = [];\n\tfor (const key of NAME_OBJECT_ORDER) {\n\t\tconst value = input[key];\n\t\tif (typeof value === 'string' && value.length > 0) {\n\t\t\tattributes.push({ type: key, value });\n\t\t}\n\t}\n\treturn attributes;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmMA,SAAgB,WAAW,GAA8B;CACxD,IAAM,IAAa,iBAAiB,CAAK,IAAI,IAAQ,uBAAuB,CAAK;CAKjF,OAJI,EAAW,WAAW,IAClB,EAAS,CAAC,CAAC,IAGZ,EAAS,EAAW,IAAI,wBAAwB,CAAC;AACzD;;AAGA,SAAgB,iBAAiB,GAA2B;CAE3D,QADmB,iBAAiB,CAAK,IAAI,IAAQ,uBAAuB,CAAK,EAAA,CAC/D,WAAW;AAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,gCACf,GACa;CACb,IAAI,EAAW,WAAW,GACzB,MAAU,MAAM,iEAAiE;CAElF,OAAO,EAAM,EAAW,IAAI,mBAAmB,CAAC;AACjD;;AAGA,SAAS,iBAAiB,GAAqD;CAC9E,OAAO,MAAM,QAAQ,CAAK;AAC3B;;AAGA,SAAS,yBAAyB,GAAsC;CACvE,OAAO,EAAM,CAAC,oBAAoB,CAAS,CAAC,CAAC;AAC9C;;;;;;AAOA,SAAS,oBAAoB,GAAsC;CAClE,IAAM,IAAa,EAAuB,EAAU;CACpD,IAAI,MAAe,KAAA,GAClB,MAAU,MAAM,2BAA2B,EAAU,MAAM;CAE5D,IAAI,EAAU,SAAS,aAAa,EAAU,MAAM,WAAW,GAC9D,MAAU,MAAM,oCAAoC;CAErD,OAAO,EAAS,CAAC,EAAiB,EAAW,GAAG,GAAG,EAAW,OAAO,EAAU,KAAK,CAAC,CAAC;AACvF;;AAGA,SAAS,uBAAuB,GAA6C;CAC5E,IAAM,IAA8B,CAAC;CACrC,KAAK,IAAM,KAAO,GAAmB;EACpC,IAAM,IAAQ,EAAM;EACpB,AAAI,OAAO,KAAU,YAAY,EAAM,SAAS,KAC/C,EAAW,KAAK;GAAE,MAAM;GAAK;EAAM,CAAC;CAEtC;CACA,OAAO;AACR"}
1
+ {"version":3,"file":"name.js","names":["code","message","attributes","input","sequence","setOf","attribute","definition","NAME_FIELD_DEFINITIONS","length","hasLoneSurrogate","objectIdentifier","key","NAME_OBJECT_ORDER","value","canonicalDnKey","compareDistinguishedNames","isWithinDirectoryNameSubtree","nameFieldKeyFromOid"],"sources":["../../src/x509/name.ts"],"sourcesContent":["/**\n * Distinguished-name input and DER encoding helpers.\n *\n * Encodes X.509 `Name` values used for certificate subjects, issuers,\n * and CSR subjects.\\\n * A `Name` is a DER `SEQUENCE` of RelativeDistinguishedNames (RDNs), and each\n * RDN is a `SET OF` one or more name attributes.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 RFC 5280 Appendix A.1}\n *\n * Use {@linkcode encodeName} for the common case where each attribute occupies\n * its own RDN.\\\n * Use {@linkcode encodeRelativeDistinguishedName} when you need one\n * multi-valued RDN.\n *\n * `NameObject` favors convenience: populated fields are emitted in the\n * canonical order from `NAME_OBJECT_ORDER`.\\\n * `NameAttribute` arrays favor control: caller order is preserved, but each\n * entry still becomes its own single-attribute RDN.\n *\n * Attribute OIDs and ASN.1 string encodings come from\n * `NAME_FIELD_DEFINITIONS`.\n *\n * @example\n * ```ts\n * import { encodeName } from 'micro509/x509';\n *\n * const subjectDer = encodeName({\n * \tcountry: 'US',\n * \torganization: 'ACME Inc',\n * \tcommonName: 'example.com',\n * });\n *\n * // DER for: C=US, O=ACME Inc, CN=example.com\n * ```\n *\n * @example\n * ```ts\n * import { encodeName } from 'micro509/x509';\n *\n * const subjectDer = encodeName([\n * \t{ type: 'commonName', value: 'example.com' },\n * \t{ type: 'organization', value: 'ACME Inc' },\n * \t{ type: 'country', value: 'US' },\n * ]);\n *\n * // preserves caller-supplied attribute order\n * ```\n *\n * @example\n * ```ts\n * import { encodeRelativeDistinguishedName } from 'micro509/x509';\n *\n * const rdnDer = encodeRelativeDistinguishedName([\n * \t{ type: 'commonName', value: 'example.com' },\n * \t{ type: 'serialNumber', value: 'device-7' },\n * ]);\n *\n * // one multi-valued RDN containing CN + serialNumber\n * ```\n *\n * @module\n */\n\nimport { hasLoneSurrogate, objectIdentifier, sequence, setOf } from '#micro509/internal/asn1/der';\nimport { NAME_FIELD_DEFINITIONS, NAME_OBJECT_ORDER } from '#micro509/internal/x509/name-fields';\nimport { throwMicro509Error } from '#micro509/result/result';\n\n/** Machine-readable reason a distinguished-name encoder rejected its construction input. */\nexport type NameEncoderErrorCode =\n\t| 'relative_distinguished_name_empty'\n\t| 'unsupported_name_field'\n\t| 'name_attribute_empty'\n\t| 'name_attribute_too_long'\n\t| 'name_attribute_lone_surrogate'\n\t| 'invalid_country_code';\n\n/** Throws a {@link ResultError} for a distinguished-name encoder input-validation failure. */\nfunction throwNameEncoderError(code: NameEncoderErrorCode, message: string): never {\n\tthrowMicro509Error(code, message);\n}\n\n/**\n * Union of recognized distinguished-name attribute type shorthand names.\n *\n * Each key maps to an OID + ASN.1 string encoding in `NAME_FIELD_DEFINITIONS`.\n */\nexport type NameFieldKey =\n\t| 'commonName'\n\t| 'surname'\n\t| 'serialNumber'\n\t| 'country'\n\t| 'locality'\n\t| 'state'\n\t| 'street'\n\t| 'organization'\n\t| 'organizationalUnit'\n\t| 'title'\n\t| 'givenName'\n\t| 'emailAddress';\n\n/**\n * Convenience object form of an X.501 distinguished name.\n *\n * Populated fields are emitted in the order defined by\n * `NAME_OBJECT_ORDER`.\\\n * Each populated field becomes its own single-attribute RDN.\n *\n * For caller-controlled ordering, pass a {@linkcode NameAttribute} array to {@linkcode encodeName}.\\\n * For multi-valued RDNs, use {@linkcode encodeRelativeDistinguishedName}.\n */\nexport interface NameObject {\n\t/** Subject or issuer common name (CN). */\n\treadonly commonName?: string;\n\t/** Subject surname (SN). */\n\treadonly surname?: string;\n\t/** Device or entity serial number — not the certificate serial. */\n\treadonly serialNumber?: string;\n\t/** ISO 3166 two-letter country code (C). Must be exactly 2 characters. */\n\treadonly country?: string;\n\t/** City or locality (L). */\n\treadonly locality?: string;\n\t/** State or province (ST). */\n\treadonly state?: string;\n\t/** Street address. */\n\treadonly street?: string;\n\t/** Organization name (O). */\n\treadonly organization?: string;\n\t/** Organizational unit (OU). Deprecated in modern CA practice. */\n\treadonly organizationalUnit?: string;\n\t/** Job title or functional designation. */\n\treadonly title?: string;\n\t/** First / given name (GN). */\n\treadonly givenName?: string;\n\t/** PKCS #9 emailAddress attribute (RFC 2985 §5.2.1). Encoded as IA5String, not UTF-8. RFC 5280 §4.1.2.6 deprecates it in favour of a subjectAltName rfc822Name. */\n\treadonly emailAddress?: string;\n}\n\n/**\n * Single name attribute within a distinguished name.\n *\n * RFC 5280 / X.501 call this structure an `AttributeTypeAndValue`.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 RFC 5280 Appendix A.1}\n * {@linkcode encodeName} places each attribute in its own single-attribute RDN.\\\n * {@linkcode encodeRelativeDistinguishedName} packs several attributes into one RDN.\n */\nexport interface NameAttribute {\n\t/** Which attribute type this pair represents. */\n\treadonly type: NameFieldKey;\n\t/** The string value for this attribute (encoding chosen per field definition). */\n\treadonly value: string;\n}\n\n/**\n * Input for {@linkcode encodeName}.\n *\n * Accepts either a {@linkcode NameObject} convenience shape or an ordered array of {@linkcode NameAttribute} pairs.\\\n * Both forms encode one attribute per RDN.\n */\nexport type NameInput = NameObject | readonly NameAttribute[];\n\n/**\n * Input for {@linkcode encodeRelativeDistinguishedName}.\n *\n * Each entry becomes one name attribute inside the RDN's `SET OF`.\\\n * Use this shape for multi-valued RDNs.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 RFC 5280 Appendix A.1}\n */\nexport type RelativeDistinguishedNameInput = readonly NameAttribute[];\n\nexport { nameFieldKeyFromOid } from '#micro509/internal/x509/name-fields';\n\n/**\n * DER-encodes an X.509 `Name`.\n *\n * Returns a DER `SEQUENCE` of RelativeDistinguishedNames (RDNs).\\\n * Each RDN emitted by this helper contains exactly one name attribute.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 RFC 5280 Appendix A.1}\n *\n * {@linkcode NameObject} input emits populated fields in the canonical order from `NAME_OBJECT_ORDER`.\\\n * {@linkcode NameAttribute} array input preserves caller-supplied ordering,\n * but each entry still becomes its own single-attribute RDN.\n *\n * Attribute OIDs and ASN.1 string encodings come from `NAME_FIELD_DEFINITIONS`.\\\n * Empty strings and `undefined` fields are ignored when the input is a {@linkcode NameObject}.\n *\n * @example\n * ```ts\n * const der = encodeName({ country: 'US', commonName: 'example.com' });\n *\n * // emits two single-attribute RDNs: C=US, then CN=example.com\n * ```\n *\n * @example\n * ```ts\n * const der = encodeName([\n * \t{ type: 'country', value: 'US' },\n * \t{ type: 'commonName', value: 'example.com' },\n * ]);\n *\n * // preserves caller order: C first, then CN\n * ```\n *\n * @param input Name fields in convenience-object form or caller-ordered attribute form.\n * @returns DER-encoded X.509 `Name` bytes.\n * @throws {ResultError} If a value exceeds its RFC 5280 A.1 bound, an ordered attribute value is empty, a field key is unsupported, or a country code is not two characters. An input with no attributes encodes an empty Name (`30 00`) rather than throwing.\n */\nexport function encodeName(input: NameInput): Uint8Array {\n\tconst attributes = isNameAttributes(input) ? input : nameObjectToAttributes(input);\n\tif (attributes.length === 0) {\n\t\treturn sequence([]);\n\t}\n\n\treturn sequence(attributes.map(encodeNameAttributeAsSet));\n}\n\n/** True when a {@linkcode NameInput} resolves to zero attributes (empty DN). */\nexport function isNameInputEmpty(input: NameInput): boolean {\n\tconst attributes = isNameAttributes(input) ? input : nameObjectToAttributes(input);\n\treturn attributes.length === 0;\n}\n\n/**\n * DER-encodes a single RelativeDistinguishedName (RDN).\n *\n * Returns a DER `SET OF` name attributes for one X.509 name segment.\\\n * Use this when you need a multi-valued RDN.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1 RFC 5280 Appendix A.1}\n *\n * Attribute OIDs and ASN.1 string encodings come from\n * `NAME_FIELD_DEFINITIONS`.\n *\n * @example\n * ```ts\n * const rdn = encodeRelativeDistinguishedName([\n * \t{ type: 'commonName', value: 'example.com' },\n * \t{ type: 'serialNumber', value: 'device-7' },\n * ]);\n *\n * // emits one RDN with both attributes in the same SET\n * ```\n *\n * @param attributes Attribute list to encode inside one RDN.\n * @returns DER-encoded RelativeDistinguishedName bytes.\n * @throws {ResultError} If the attribute list is empty, contains an unsupported field key, an empty or over-long value, or an invalid country code.\n */\nexport function encodeRelativeDistinguishedName(\n\tattributes: RelativeDistinguishedNameInput,\n): Uint8Array {\n\tif (attributes.length === 0) {\n\t\tthrowNameEncoderError(\n\t\t\t'relative_distinguished_name_empty',\n\t\t\t'Relative distinguished name must contain at least one attribute',\n\t\t);\n\t}\n\treturn setOf(attributes.map(encodeNameAttribute));\n}\n\n/** Narrows a {@linkcode NameInput} to the ordered-attribute-array form. */\nfunction isNameAttributes(input: NameInput): input is readonly NameAttribute[] {\n\treturn Array.isArray(input);\n}\n\n/** Wraps a single attribute in a SET OF for the Name SEQUENCE. */\nfunction encodeNameAttributeAsSet(attribute: NameAttribute): Uint8Array {\n\treturn setOf([encodeNameAttribute(attribute)]);\n}\n\n/**\n * DER-encodes one name attribute SEQUENCE.\n *\n * Throws for unsupported field keys, empty or over-long values, and invalid country codes.\n */\nfunction encodeNameAttribute(attribute: NameAttribute): Uint8Array {\n\tconst definition = NAME_FIELD_DEFINITIONS[attribute.type];\n\tif (definition === undefined) {\n\t\tthrowNameEncoderError('unsupported_name_field', `Unsupported name field: ${attribute.type}`);\n\t}\n\tconst length = [...attribute.value].length;\n\tif (length === 0) {\n\t\tthrowNameEncoderError(\n\t\t\t'name_attribute_empty',\n\t\t\t`Name attribute ${attribute.type} must not be empty`,\n\t\t);\n\t}\n\tif (hasLoneSurrogate(attribute.value)) {\n\t\tthrowNameEncoderError(\n\t\t\t'name_attribute_lone_surrogate',\n\t\t\t`Name attribute ${attribute.type} holds a lone UTF-16 surrogate`,\n\t\t);\n\t}\n\tif (attribute.type === 'country' && attribute.value.length !== 2) {\n\t\tthrowNameEncoderError('invalid_country_code', 'Country must be a 2-character code');\n\t}\n\tif (definition.maxLength !== undefined && length > definition.maxLength) {\n\t\tthrowNameEncoderError(\n\t\t\t'name_attribute_too_long',\n\t\t\t`Name attribute ${attribute.type} must be at most ${definition.maxLength} characters`,\n\t\t);\n\t}\n\treturn sequence([objectIdentifier(definition.oid), definition.encode(attribute.value)]);\n}\n\n/** Converts a {@linkcode NameObject} to ordered attributes per `NAME_OBJECT_ORDER`. */\nfunction nameObjectToAttributes(input: NameObject): readonly NameAttribute[] {\n\tconst attributes: NameAttribute[] = [];\n\tfor (const key of NAME_OBJECT_ORDER) {\n\t\tconst value = input[key];\n\t\tif (typeof value === 'string' && value.length > 0) {\n\t\t\tattributes.push({ type: key, value });\n\t\t}\n\t}\n\treturn attributes;\n}\n\nexport {\n\tcanonicalDnKey,\n\tcompareDistinguishedNames,\n\tisWithinDirectoryNameSubtree,\n} from '#micro509/internal/shared/dn';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8EA,SAAS,sBAAsB,GAA4B,GAAwB;CAClF,EAAmBA,GAAMC,CAAO;AACjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkIA,SAAgB,WAAW,GAA8B;CACxD,IAAMC,IAAa,iBAAiBC,CAAK,IAAIA,IAAQ,uBAAuBA,CAAK;CAKjF,OAJID,EAAW,WAAW,IAClBE,EAAS,CAAC,CAAC,IAGZA,EAASF,EAAW,IAAI,wBAAwB,CAAC;AACzD;;AAGA,SAAgB,iBAAiB,GAA2B;CAE3D,QADmB,iBAAiBC,CAAK,IAAIA,IAAQ,uBAAuBA,CAAK,EAAA,CAC/D,WAAW;AAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,gCACf,GACa;CAOb,OANID,EAAW,WAAW,KACzB,sBACC,qCACA,iEACD,GAEMG,EAAMH,EAAW,IAAI,mBAAmB,CAAC;AACjD;;AAGA,SAAS,iBAAiB,GAAqD;CAC9E,OAAO,MAAM,QAAQC,CAAK;AAC3B;;AAGA,SAAS,yBAAyB,GAAsC;CACvE,OAAOE,EAAM,CAAC,oBAAoBC,CAAS,CAAC,CAAC;AAC9C;;;;;;AAOA,SAAS,oBAAoB,GAAsC;CAClE,IAAMC,IAAaC,EAAuBF,EAAU;CACpD,AAAIC,MAAe,KAAA,KAClB,sBAAsB,0BAA0B,2BAA2BD,EAAU,MAAM;CAE5F,IAAMG,IAAS,CAAC,GAAGH,EAAU,KAAK,CAAC,CAAC;CAsBpC,OArBIG,MAAW,KACd,sBACC,wBACA,kBAAkBH,EAAU,KAAK,mBAClC,GAEGI,EAAiBJ,EAAU,KAAK,KACnC,sBACC,iCACA,kBAAkBA,EAAU,KAAK,+BAClC,GAEGA,EAAU,SAAS,aAAaA,EAAU,MAAM,WAAW,KAC9D,sBAAsB,wBAAwB,oCAAoC,GAE/EC,EAAW,cAAc,KAAA,KAAaE,IAASF,EAAW,aAC7D,sBACC,2BACA,kBAAkBD,EAAU,KAAK,mBAAmBC,EAAW,UAAU,YAC1E,GAEMH,EAAS,CAACO,EAAiBJ,EAAW,GAAG,GAAGA,EAAW,OAAOD,EAAU,KAAK,CAAC,CAAC;AACvF;;AAGA,SAAS,uBAAuB,GAA6C;CAC5E,IAAMJ,IAA8B,CAAC;CACrC,KAAK,IAAMU,KAAOC,GAAmB;EACpC,IAAMC,IAAQX,EAAMS;EACpB,AAAI,OAAOE,KAAU,YAAYA,EAAM,SAAS,KAC/CZ,EAAW,KAAK;GAAE,MAAMU;GAAK;EAAM,CAAC;CAEtC;CACA,OAAOV;AACR"}