micro509 0.12.0 → 0.14.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 (123) hide show
  1. package/README.md +78 -30
  2. package/dist/crypto/crypto.d.ts +73 -0
  3. package/dist/crypto/crypto.js +74 -0
  4. package/dist/crypto/crypto.js.map +1 -0
  5. package/dist/crypto.d.ts +4 -0
  6. package/dist/crypto.js +2 -0
  7. package/dist/der/der.d.ts +127 -0
  8. package/dist/der/der.js +171 -0
  9. package/dist/der/der.js.map +1 -0
  10. package/dist/der.d.ts +4 -0
  11. package/dist/der.js +4 -0
  12. package/dist/index.d.ts +13 -9
  13. package/dist/index.js +17 -15
  14. package/dist/internal/asn1/asn1.d.ts +20 -0
  15. package/dist/internal/asn1/asn1.js +80 -37
  16. package/dist/internal/asn1/asn1.js.map +1 -1
  17. package/dist/internal/asn1/der.d.ts +173 -0
  18. package/dist/internal/asn1/der.js +116 -38
  19. package/dist/internal/asn1/der.js.map +1 -1
  20. package/dist/internal/asn1/oids.js +7 -1
  21. package/dist/internal/asn1/oids2.js +9 -2
  22. package/dist/internal/asn1/oids2.js.map +1 -1
  23. package/dist/internal/crypto/algorithm-names.js +4 -0
  24. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  25. package/dist/internal/crypto/pbes2.d.ts +38 -0
  26. package/dist/internal/crypto/pbes2.js +9 -10
  27. package/dist/internal/crypto/pbes2.js.map +1 -1
  28. package/dist/internal/crypto/rsa-pss.js +2 -0
  29. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  30. package/dist/internal/crypto/sig-verify.d.ts +31 -0
  31. package/dist/internal/crypto/sig-verify.js +10 -8
  32. package/dist/internal/crypto/sig-verify.js.map +1 -1
  33. package/dist/internal/shared/base64.js +7 -1
  34. package/dist/internal/shared/base64.js.map +1 -1
  35. package/dist/internal/shared/dn.d.ts +16 -0
  36. package/dist/internal/shared/dn.js +149 -12
  37. package/dist/internal/shared/dn.js.map +1 -1
  38. package/dist/internal/shared/ip.d.ts +69 -0
  39. package/dist/internal/shared/ip.js +18 -1
  40. package/dist/internal/shared/ip.js.map +1 -1
  41. package/dist/internal/shared/rfc3454-tables.js +1782 -0
  42. package/dist/internal/shared/rfc3454-tables.js.map +1 -0
  43. package/dist/internal/verify/name-constraints-engine.js +47 -15
  44. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  45. package/dist/internal/verify/policy-engine.js +85 -94
  46. package/dist/internal/verify/policy-engine.js.map +1 -1
  47. package/dist/internal/verify/verify-path.d.ts +7 -0
  48. package/dist/internal/verify/verify-path.js +49 -45
  49. package/dist/internal/verify/verify-path.js.map +1 -1
  50. package/dist/internal/x509/directory-name.js +24 -0
  51. package/dist/internal/x509/directory-name.js.map +1 -0
  52. package/dist/internal/x509/extension-bits.js +14 -11
  53. package/dist/internal/x509/extension-bits.js.map +1 -1
  54. package/dist/internal/x509/extension-errors.d.ts +6 -0
  55. package/dist/internal/x509/extension-errors.js +20 -0
  56. package/dist/internal/x509/extension-errors.js.map +1 -0
  57. package/dist/internal/x509/extension-registry.js +113 -55
  58. package/dist/internal/x509/extension-registry.js.map +1 -1
  59. package/dist/internal/x509/general-name-tags.js +28 -0
  60. package/dist/internal/x509/general-name-tags.js.map +1 -0
  61. package/dist/internal/x509/general-name.js +97 -0
  62. package/dist/internal/x509/general-name.js.map +1 -0
  63. package/dist/internal/x509/name-fields.js +20 -10
  64. package/dist/internal/x509/name-fields.js.map +1 -1
  65. package/dist/keys/keys.d.ts +16 -2
  66. package/dist/keys/keys.js +311 -170
  67. package/dist/keys/keys.js.map +1 -1
  68. package/dist/keys.d.ts +3 -2
  69. package/dist/keys.js +3 -2
  70. package/dist/pem/pem.d.ts +3 -2
  71. package/dist/pem/pem.js +112 -30
  72. package/dist/pem/pem.js.map +1 -1
  73. package/dist/pkcs/pkcs12-mac.js +3 -3
  74. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  75. package/dist/pkcs/pkcs7.d.ts +85 -21
  76. package/dist/pkcs/pkcs7.js +261 -186
  77. package/dist/pkcs/pkcs7.js.map +1 -1
  78. package/dist/pkcs.d.ts +2 -2
  79. package/dist/result/result.d.ts +18 -10
  80. package/dist/result/result.js +20 -12
  81. package/dist/result/result.js.map +1 -1
  82. package/dist/result.d.ts +2 -2
  83. package/dist/result.js +2 -2
  84. package/dist/revocation/chain.js +154 -103
  85. package/dist/revocation/chain.js.map +1 -1
  86. package/dist/revocation/crl.d.ts +13 -2
  87. package/dist/revocation/crl.js +415 -236
  88. package/dist/revocation/crl.js.map +1 -1
  89. package/dist/revocation/ocsp.d.ts +58 -17
  90. package/dist/revocation/ocsp.js +186 -174
  91. package/dist/revocation/ocsp.js.map +1 -1
  92. package/dist/revocation/revocation.d.ts +4 -4
  93. package/dist/revocation/revocation.js +48 -30
  94. package/dist/revocation/revocation.js.map +1 -1
  95. package/dist/revocation.d.ts +4 -4
  96. package/dist/revocation.js +5 -5
  97. package/dist/verify/identity.d.ts +2 -1
  98. package/dist/verify/identity.js +2 -1
  99. package/dist/verify/identity.js.map +1 -1
  100. package/dist/verify/policy.d.ts +6 -1
  101. package/dist/verify/verify.d.ts +18 -3
  102. package/dist/verify/verify.js +66 -41
  103. package/dist/verify/verify.js.map +1 -1
  104. package/dist/verify.d.ts +2 -1
  105. package/dist/verify.js +4 -3
  106. package/dist/x509/certificate.d.ts +36 -13
  107. package/dist/x509/certificate.js +36 -19
  108. package/dist/x509/certificate.js.map +1 -1
  109. package/dist/x509/csr.d.ts +6 -3
  110. package/dist/x509/extensions.d.ts +59 -22
  111. package/dist/x509/extensions.js +384 -117
  112. package/dist/x509/extensions.js.map +1 -1
  113. package/dist/x509/name-text.js +2 -0
  114. package/dist/x509/name-text.js.map +1 -1
  115. package/dist/x509/name.d.ts +8 -5
  116. package/dist/x509/name.js +17 -12
  117. package/dist/x509/name.js.map +1 -1
  118. package/dist/x509/parse.d.ts +104 -18
  119. package/dist/x509/parse.js +127 -163
  120. package/dist/x509/parse.js.map +1 -1
  121. package/dist/x509.d.ts +8 -5
  122. package/dist/x509.js +10 -8
  123. package/package.json +52 -34
@@ -1,15 +1,16 @@
1
- import { encodeLength as e, readElement as t, readRootElement as n, readSequenceChildren as r } from "../internal/asn1/der.js";
1
+ import { optionalBytesEqual as e, readElement as t, readRootElement as n, readSequenceChildren as r } from "../internal/asn1/der.js";
2
2
  import { childrenOf as i, decodeBoolean as a, decodeIntegerNumber as o, decodeNonNegativeIntegerNumber as s, decodeObjectIdentifier as c, decodeString as l, extractBitStringValue as u, parseTime as d, requireElement as f, toHex as p } from "../internal/asn1/asn1.js";
3
3
  import { OIDS as m } from "../internal/asn1/oids2.js";
4
4
  import { failureResult as h, rethrowIfInvariant as g, successResult as _ } from "../result/result.js";
5
5
  import { pemDecodeOrThrow as v, splitPemBlocksOrThrow as y } from "../pem/pem.js";
6
6
  import { derivePublicKey as b, exportSpkiDer as x, importSpkiDer as S, importSpkiDerOrThrow as C } from "../keys/keys.js";
7
7
  import { describePublicKeyAlgorithm as w, describeSignatureAlgorithm as T } from "../internal/crypto/algorithm-names.js";
8
- import { decodeIpAddress as E } from "../internal/shared/ip.js";
8
+ import { readDirectoryNameTlv as E } from "../internal/x509/directory-name.js";
9
9
  import { parseDistributionPointReasonFlagsContent as D, parseKeyUsageExtension as O } from "../internal/x509/extension-bits.js";
10
10
  import { nameFieldKeyFromOid as k } from "../internal/x509/name-fields.js";
11
11
  import { parseAuthorityInfoAccessMethodOid as A, parseExtendedKeyUsageOid as j } from "./extensions.js";
12
12
  import { decodeAndApplyKnownExtension as M } from "../internal/x509/extension-registry.js";
13
+ import { parseGeneralName as N, parseGeneralNames as P } from "../internal/x509/general-name.js";
13
14
  //#region src/x509/parse.ts
14
15
  /**
15
16
  * Certificate and CSR parse boundary.
@@ -22,7 +23,7 @@ import { decodeAndApplyKnownExtension as M } from "../internal/x509/extension-re
22
23
  * @module
23
24
  */
24
25
  /** Shared UTF-8 decoder for IA5String / UTF8String values. */
25
- const N = new TextDecoder();
26
+ const F = new TextDecoder();
26
27
  /**
27
28
  * Identity helper that narrows the type of a custom {@linkcode ExtensionDecoder} literal.
28
29
  *
@@ -81,6 +82,7 @@ function parseCertificateDerOrThrow(e, t) {
81
82
  ...c.keyUsage === void 0 ? {} : { keyUsage: c.keyUsage },
82
83
  ...c.extendedKeyUsage === void 0 ? {} : { extendedKeyUsage: c.extendedKeyUsage },
83
84
  ...c.subjectAltNames === void 0 ? {} : { subjectAltNames: c.subjectAltNames },
85
+ ...c.issuerAltNames === void 0 ? {} : { issuerAltNames: c.issuerAltNames },
84
86
  ...c.nameConstraints === void 0 ? {} : { nameConstraints: c.nameConstraints },
85
87
  ...c.certificatePolicies === void 0 ? {} : { certificatePolicies: c.certificatePolicies },
86
88
  ...c.policyMappings === void 0 ? {} : { policyMappings: c.policyMappings },
@@ -217,17 +219,33 @@ function parseCertificateFromSource(e, t) {
217
219
  return typeof e == "string" ? parseCertificatePemOrThrow(e, t) : hasParsedCertificateShape(e) ? e : parseCertificateDerOrThrow(new Uint8Array(e), t);
218
220
  }
219
221
  /**
220
- * Decode a PEM bundle containing one or more certificates.
222
+ * Decode a PEM bundle containing one or more certificates, throwing on malformed input.
221
223
  *
222
224
  * Non-CERTIFICATE blocks (e.g. private keys) are silently skipped.
223
225
  *
224
226
  * @param pemBundle PEM text that may contain multiple CERTIFICATE blocks.
225
227
  * @param options Custom extension decoders to apply during parsing.
226
228
  */
227
- function parseCertificateChainPem(e, t) {
229
+ function parseCertificateChainPemOrThrow(e, t) {
228
230
  return parseCertificatesFromPemBlocks(e, t);
229
231
  }
230
232
  /**
233
+ * Decode a PEM bundle containing one or more certificates.
234
+ *
235
+ * Non-CERTIFICATE blocks (e.g. private keys) are silently skipped. Returns a
236
+ * typed `malformed` failure for invalid PEM or certificate DER.
237
+ *
238
+ * @param pemBundle PEM text that may contain multiple CERTIFICATE blocks.
239
+ * @param options Custom extension decoders to apply during parsing.
240
+ */
241
+ function parseCertificateChainPem(e, t) {
242
+ try {
243
+ return _(parseCertificateChainPemOrThrow(e, t));
244
+ } catch (e) {
245
+ return g(e), h("malformed", e instanceof Error ? e.message : "Malformed certificate chain");
246
+ }
247
+ }
248
+ /**
231
249
  * Decode a DER-encoded PKCS#10 CSR into a {@linkcode ParsedCertificateSigningRequest}.
232
250
  *
233
251
  * @param der Raw DER bytes of a PKCS#10 certificate signing request.
@@ -268,18 +286,18 @@ function parseCertificateSigningRequestDerOrThrow(e, t) {
268
286
  }
269
287
  function parseCertificationRequestInfoFields(e, t) {
270
288
  let n = i(e, t);
271
- if (n.length < 3 || n.length > 4) throw Error("Malformed CertificationRequestInfo");
289
+ if (n.length !== 4) throw Error("Malformed CertificationRequestInfo");
272
290
  let r = f(n[0], "version");
273
291
  if (r.tag !== 2) throw Error("version must use INTEGER");
274
292
  let a = o(r.value) + 1;
275
293
  if (a !== 1) throw Error(`Unsupported CertificationRequestInfo version: ${String(a)}`);
276
- let s = n[3];
277
- if (s !== void 0 && s.tag !== 160) throw Error("CertificationRequestInfo attributes must use [0]");
294
+ let s = f(n[3], "attributes");
295
+ if (s.tag !== 160) throw Error("CertificationRequestInfo attributes must use [0]");
278
296
  return {
279
297
  version: a,
280
298
  subject: f(n[1], "subject"),
281
299
  subjectPublicKeyInfo: f(n[2], "subjectPublicKeyInfo"),
282
- ...s === void 0 ? {} : { attributes: s }
300
+ attributes: s
283
301
  };
284
302
  }
285
303
  /**
@@ -376,9 +394,9 @@ function subjectPublicKeyInfoAlgorithmDer(e) {
376
394
  * AlgorithmIdentifier portions decide whether it is a same-algorithm key
377
395
  * mismatch or a cross-algorithm (`key_type_mismatch`) one.
378
396
  */
379
- async function compareCertificateToPrivateKey(e, t) {
380
- let n = await x(await b(t));
381
- return optionalBytesEqual(n, e) ? "match" : optionalBytesEqual(subjectPublicKeyInfoAlgorithmDer(n), subjectPublicKeyInfoAlgorithmDer(e)) ? "key_mismatch" : "key_type_mismatch";
397
+ async function compareCertificateToPrivateKey(t, n) {
398
+ let r = await x(await b(n));
399
+ return e(r, t) ? "match" : e(subjectPublicKeyInfoAlgorithmDer(r), subjectPublicKeyInfoAlgorithmDer(t)) ? "key_mismatch" : "key_type_mismatch";
382
400
  }
383
401
  /**
384
402
  * Check whether a certificate's subject public key belongs to a private key.
@@ -483,6 +501,7 @@ async function matchCertificatePrivateKey(e, t) {
483
501
  case "match": return _(void 0);
484
502
  case "key_mismatch": return h("key_mismatch", "Private key does not match the certificate's subject public key");
485
503
  case "key_type_mismatch": return h("key_type_mismatch", "Private key algorithm does not match the certificate's subject public key algorithm");
504
+ default: throw Error(`Unhandled key comparison result: ${String(r)}`);
486
505
  }
487
506
  }
488
507
  /**
@@ -553,19 +572,22 @@ function parseExtensionContainer(e, t) {
553
572
  }
554
573
  /** Extract extensions from the CSR extensionRequest attribute. */
555
574
  function parseRequestedExtensions(e, t) {
556
- if (t === void 0) return { all: [] };
557
- if (t.tag !== 160) throw Error("CertificationRequestInfo attributes must use [0]");
558
575
  let n;
559
576
  for (let r of i(e, t)) {
577
+ if (r.tag !== 48) throw Error("CSR attribute must use SEQUENCE");
560
578
  let t = i(e, r);
561
579
  if (t.length !== 2) throw Error("Malformed CSR attribute");
562
- if (c(f(t[0], "attribute OID").value) !== m.extensionRequest) continue;
563
- if (n !== void 0) throw Error("extensionRequest attribute must not repeat");
564
- let a = f(t[1], "attribute values");
565
- if (a.tag !== 49) throw Error("extensionRequest attribute values must use SET");
566
- let o = i(e, a);
567
- if (o.length !== 1) throw Error("extensionRequest attribute must contain exactly one value");
568
- n = parseExtensionSequence(e, f(o[0], "requested extensions"), "csr");
580
+ let a = f(t[0], "attribute OID");
581
+ if (a.tag !== 6) throw Error("CSR attribute type must use OBJECT IDENTIFIER");
582
+ let o = f(t[1], "attribute values");
583
+ if (o.tag !== 49) throw Error("CSR attribute values must use SET");
584
+ let s = i(e, o);
585
+ if (s.length === 0) throw Error("CSR attribute values must not be empty");
586
+ if (c(a.value) === m.extensionRequest) {
587
+ if (n !== void 0) throw Error("extensionRequest attribute must not repeat");
588
+ if (s.length !== 1) throw Error("extensionRequest attribute must contain exactly one value");
589
+ n = parseExtensionSequence(e, f(s[0], "requested extensions"), "csr");
590
+ }
569
591
  }
570
592
  return n ?? { all: [] };
571
593
  }
@@ -596,8 +618,10 @@ function parseExtensionSequence(e, t, n) {
596
618
  }
597
619
  /** Decode an X.501 Name (issuer / subject) into a {@linkcode ParsedName}. */
598
620
  function parseName(e, t) {
621
+ if (t.tag !== 48) throw Error("Name must use SEQUENCE");
599
622
  let n = [], r = [], a = {};
600
623
  for (let o of i(e, t)) {
624
+ if (o.tag !== 49) throw Error("RelativeDistinguishedName must use SET");
601
625
  let t = parseNameAttributeSet(e, o);
602
626
  n.push(t);
603
627
  for (let e of t.attributes) r.push(e), e.key !== void 0 && a[e.key] === void 0 && (a[e.key] = e.value);
@@ -617,17 +641,22 @@ function parseRelativeDistinguishedName(e, t) {
617
641
  function parseNameAttributeSet(e, t) {
618
642
  let n = [], r = {};
619
643
  for (let a of i(e, t)) {
620
- let t = i(e, a), o = c(f(t[0], "name OID").value), s = f(t[1], "name value"), u = k(o), d = l(s.tag, s.value), p = u === void 0 ? {
621
- oid: o,
622
- valueTag: s.tag,
623
- value: d
644
+ if (a.tag !== 48) throw Error("AttributeTypeAndValue must use SEQUENCE");
645
+ let t = i(e, a);
646
+ if (t.length !== 2) throw Error("AttributeTypeAndValue must contain type and value");
647
+ let o = f(t[0], "name OID");
648
+ if (o.tag !== 6) throw Error("AttributeTypeAndValue type must use OBJECT IDENTIFIER");
649
+ let s = c(o.value), u = f(t[1], "name value"), d = k(s), p = l(u.tag, u.value), m = d === void 0 ? {
650
+ oid: s,
651
+ valueTag: u.tag,
652
+ value: p
624
653
  } : {
625
- oid: o,
626
- key: u,
627
- valueTag: s.tag,
628
- value: d
654
+ oid: s,
655
+ key: d,
656
+ valueTag: u.tag,
657
+ value: p
629
658
  };
630
- n.push(p), u !== void 0 && r[u] === void 0 && (r[u] = d);
659
+ n.push(m), d !== void 0 && r[d] === void 0 && (r[d] = p);
631
660
  }
632
661
  return {
633
662
  derHex: p(e.slice(t.start - t.headerLength, t.end)),
@@ -655,30 +684,27 @@ function parseSubjectPublicKeyInfo(e, t) {
655
684
  }
656
685
  /** Decode an AlgorithmIdentifier SEQUENCE (OID + optional parameters). */
657
686
  function parseAlgorithmIdentifier(e, t) {
687
+ if (t.tag !== 48) throw Error("AlgorithmIdentifier must use SEQUENCE");
658
688
  let n = i(e, t);
659
689
  if (n.length === 0 || n.length > 2) throw Error("Malformed AlgorithmIdentifier");
660
- let r = c(f(n[0], "algorithm OID").value), a = n[1];
661
- if (a === void 0) return { oid: r };
662
- let o = e.slice(a.start - a.headerLength, a.end);
663
- return a?.tag === 6 ? {
664
- oid: r,
665
- parametersDer: o,
666
- parametersOid: c(a.value)
690
+ let r = f(n[0], "algorithm OID");
691
+ if (r.tag !== 6) throw Error("AlgorithmIdentifier algorithm must use OBJECT IDENTIFIER");
692
+ let a = c(r.value), o = n[1];
693
+ if (o === void 0) return { oid: a };
694
+ let s = e.slice(o.start - o.headerLength, o.end);
695
+ return o?.tag === 6 ? {
696
+ oid: a,
697
+ parametersDer: s,
698
+ parametersOid: c(o.value)
667
699
  } : {
668
- oid: r,
669
- parametersDer: o
700
+ oid: a,
701
+ parametersDer: s
670
702
  };
671
703
  }
672
- function assertMatchingCertificateSignatureAlgorithms(e, t) {
673
- if (e.oid !== t.oid || !optionalBytesEqual(e.parametersDer, t.parametersDer)) throw Error("Certificate signatureAlgorithm must match TBSCertificate signature");
674
- }
675
- function optionalBytesEqual(e, t) {
676
- if (e === void 0 || t === void 0) return e === t;
677
- if (e.length !== t.length) return !1;
678
- for (let n = 0; n < e.length; n += 1) if (e[n] !== t[n]) return !1;
679
- return !0;
704
+ function assertMatchingCertificateSignatureAlgorithms(t, n) {
705
+ if (t.oid !== n.oid || !e(t.parametersDer, n.parametersDer)) throw Error("Certificate signatureAlgorithm must match TBSCertificate signature");
680
706
  }
681
- /** @internal Decode the Basic Constraints extension value DER. */
707
+ /** Decodes the Basic Constraints extension value DER. */
682
708
  function parseBasicConstraints(e) {
683
709
  let t = n(e, { maxDepth: 64 });
684
710
  if (t.tag !== 48) throw Error("basicConstraints must use SEQUENCE");
@@ -703,15 +729,20 @@ function parseBasicConstraints(e) {
703
729
  pathLength: c
704
730
  } : { ca: !1 };
705
731
  }
706
- /** @internal Decode the Key Usage BIT STRING extension value. */
732
+ /** Decodes the Key Usage BIT STRING extension value. */
707
733
  function parseKeyUsage(e) {
708
734
  return O(e);
709
735
  }
710
- /** @internal Decode the Extended Key Usage SEQUENCE OF OIDs. */
736
+ /** Decodes the Extended Key Usage SEQUENCE OF OIDs. */
711
737
  function parseExtendedKeyUsage(e) {
712
- return i(e, f(n(e, { maxDepth: 64 }), "extendedKeyUsage sequence")).map((e) => j(c(e.value)));
738
+ let t = r(e, { maxDepth: 64 });
739
+ if (t.length === 0) throw Error("extendedKeyUsage must not be empty");
740
+ return t.map((e) => {
741
+ if (e.tag !== 6) throw Error("extendedKeyUsage entry must use OBJECT IDENTIFIER");
742
+ return j(c(e.value));
743
+ });
713
744
  }
714
- /** @internal Decode the Certificate Policies extension value. */
745
+ /** Decodes the Certificate Policies extension value. */
715
746
  function parseCertificatePolicies(e) {
716
747
  let t = i(e, f(n(e, { maxDepth: 64 }), "certificatePolicies sequence"));
717
748
  if (t.length === 0) throw Error("certificatePolicies must not be empty");
@@ -786,7 +817,7 @@ function parsePolicyNoticeNumbers(e, t) {
786
817
  return s(e.value, "noticeRef noticeNumber");
787
818
  });
788
819
  }
789
- /** @internal Decode the Policy Mappings extension value. */
820
+ /** Decodes the Policy Mappings extension value. */
790
821
  function parsePolicyMappings(e) {
791
822
  let t = i(e, f(n(e, { maxDepth: 64 }), "policyMappings sequence"));
792
823
  if (t.length === 0) throw Error("policyMappings must not be empty");
@@ -800,7 +831,7 @@ function parsePolicyMappings(e) {
800
831
  };
801
832
  });
802
833
  }
803
- /** @internal Decode the Policy Constraints extension value. */
834
+ /** Decodes the Policy Constraints extension value. */
804
835
  function parsePolicyConstraints(e) {
805
836
  let t = f(n(e, { maxDepth: 64 }), "policyConstraints sequence"), r, a;
806
837
  for (let n of i(e, t)) {
@@ -822,23 +853,25 @@ function parsePolicyConstraints(e) {
822
853
  ...a === void 0 ? {} : { inhibitPolicyMapping: a }
823
854
  };
824
855
  }
825
- /** @internal Decode the Inhibit anyPolicy extension (single INTEGER). */
856
+ /** Decodes the Inhibit anyPolicy extension (single INTEGER). */
826
857
  function parseInhibitAnyPolicy(e) {
827
858
  let t = f(n(e, { maxDepth: 64 }), "inhibitAnyPolicy integer");
828
859
  if (t.tag !== 2) throw Error("inhibitAnyPolicy must be an INTEGER");
829
860
  return { skipCerts: s(t.value, "inhibitAnyPolicy skipCerts") };
830
861
  }
831
- /** @internal Decode the Subject Alternative Names SEQUENCE OF GeneralName. */
832
- function parseSubjectAltNames(e) {
833
- return i(e, f(n(e, { maxDepth: 64 }), "subjectAltName sequence")).map((t) => parseGeneralName(e, t));
862
+ /** Decodes a subjectAltName or issuerAltName SEQUENCE OF GeneralName. */
863
+ function parseSubjectAltNames(e, t = "subjectAltName") {
864
+ let r = f(n(e, { maxDepth: 64 }), `${t} sequence`);
865
+ if (r.tag !== 48) throw Error(`${t} must use SEQUENCE`);
866
+ return P(e, r);
834
867
  }
835
- /** @internal Decode a bare DER-encoded X.501 Name, as carried in a `directoryName` GeneralName. */
868
+ /** Decodes a bare DER-encoded X.501 Name, as carried in a `directoryName` GeneralName. */
836
869
  function parseDistinguishedNameDer(e) {
837
870
  let t = f(n(e, { maxDepth: 64 }), "distinguished name sequence");
838
871
  if (t.tag !== 48) throw Error("distinguished name must use SEQUENCE");
839
872
  return parseName(e, t);
840
873
  }
841
- /** @internal Decode the Authority Information Access extension value. */
874
+ /** Decodes the Authority Information Access extension value. */
842
875
  function parseAuthorityInfoAccess(e) {
843
876
  let t = f(n(e, { maxDepth: 64 }), "authorityInfoAccess sequence");
844
877
  if (t.tag !== 48) throw Error("authorityInfoAccess must use SEQUENCE");
@@ -850,14 +883,13 @@ function parseAuthorityInfoAccess(e) {
850
883
  if (n.length !== 2) throw Error("authorityInfoAccess entry must contain method and location only");
851
884
  let r = f(n[0], "authorityInfoAccess method"), a = f(n[1], "authorityInfoAccess location");
852
885
  if (r.tag !== 6) throw Error("authorityInfoAccess method must use OBJECT IDENTIFIER");
853
- if (a.tag !== 134) throw Error(`Unsupported authorityInfoAccess location tag: ${a.tag}`);
854
886
  return {
855
887
  method: A(c(r.value)),
856
- uri: N.decode(a.value)
888
+ location: N(e, a)
857
889
  };
858
890
  });
859
891
  }
860
- /** @internal Decode the CRL Distribution Points extension value. */
892
+ /** Decodes the CRL Distribution Points extension value. */
861
893
  function parseCrlDistributionPoints(e) {
862
894
  let t = f(n(e, { maxDepth: 64 }), "CRLDistributionPoints sequence");
863
895
  if (t.tag !== 48) throw Error("CRLDistributionPoints must use SEQUENCE");
@@ -891,7 +923,7 @@ function parseDistributionPointField(e, t, n) {
891
923
  return;
892
924
  case 162:
893
925
  if (n.crlIssuer !== void 0) throw Error("DistributionPoint crlIssuer must not repeat");
894
- n.crlIssuer = parseGeneralNames(e, t);
926
+ n.crlIssuer = P(e, t);
895
927
  return;
896
928
  default: throw Error(`Unsupported DistributionPoint field tag: ${String(t.tag)}`);
897
929
  }
@@ -905,75 +937,18 @@ function parseDistributionPointName(e, t) {
905
937
  let t = i(e, r);
906
938
  if (t.length === 0) throw Error("distributionPointName fullName must not be empty");
907
939
  for (let e of t) if ((e.tag & 192) != 128) throw Error("distributionPointName fullName must contain GeneralName entries");
908
- return { fullName: t.map((t) => parseGeneralName(e, t)) };
909
- }
910
- if (r.tag === 161) return { relativeName: parseRelativeDistinguishedName(e, r) };
911
- throw Error(`Unsupported distributionPointName tag: ${r.tag}`);
912
- }
913
- /** Decode a SEQUENCE OF GeneralName. */
914
- function parseGeneralNames(e, t) {
915
- let n = i(e, t);
916
- if (n.length === 0) throw Error("GeneralNames must not be empty");
917
- for (let e of n) if ((e.tag & 192) != 128) throw Error("GeneralNames must contain GeneralName entries");
918
- return n.map((t) => parseGeneralName(e, t));
919
- }
920
- /** Decode a single GeneralName from its implicit context tag. */
921
- function parseGeneralName(e, t) {
922
- switch (t.tag) {
923
- case 160: {
924
- let n = parseOtherName(e, t);
925
- return n === void 0 ? {
926
- type: "unknown",
927
- tag: t.tag,
928
- value: e.slice(t.start, t.end)
929
- } : n;
930
- }
931
- case 129: return {
932
- type: "email",
933
- value: N.decode(t.value)
934
- };
935
- case 130: return {
936
- type: "dns",
937
- value: N.decode(t.value)
938
- };
939
- case 134: return {
940
- type: "uri",
941
- value: N.decode(t.value)
942
- };
943
- case 135: return {
944
- type: "ip",
945
- value: E(t.value)
946
- };
947
- case 164: return {
948
- type: "directoryName",
949
- derHex: p(rebuildDirectoryNameFromImplicit(t, e))
950
- };
951
- default: return {
952
- type: "unknown",
953
- tag: t.tag,
954
- value: e.slice(t.start, t.end)
940
+ return {
941
+ type: "fullName",
942
+ fullName: t.map((t) => N(e, t))
955
943
  };
956
944
  }
957
- }
958
- /** Attempt to decode an otherName [0] as a known type (currently only SRV-ID). */
959
- function parseOtherName(e, t) {
960
- let n = i(e, t);
961
- if (n.length !== 1) throw Error("otherName must contain exactly one SEQUENCE");
962
- let r = i(e, f(n[0], "otherName sequence"));
963
- if (r.length !== 2) throw Error("otherName must contain exactly type-id and value");
964
- let a = f(r[0], "otherName type-id"), o = f(r[1], "otherName value");
965
- if (c(a.value) !== m.idOnDnsSrv) return;
966
- if (o.tag !== 160) throw Error("SRV-ID otherName value must use explicit [0]");
967
- let s = i(e, o);
968
- if (s.length !== 1) throw Error("SRV-ID otherName value must contain exactly one IA5String");
969
- let u = f(s[0], "SRV-ID IA5String");
970
- if (u.tag !== 22) throw Error("SRV-ID otherName value must be an IA5String");
971
- return {
972
- type: "srv",
973
- value: l(u.tag, u.value)
945
+ if (r.tag === 161) return {
946
+ type: "relativeName",
947
+ relativeName: parseRelativeDistinguishedName(e, r)
974
948
  };
949
+ throw Error(`Unsupported distributionPointName tag: ${r.tag}`);
975
950
  }
976
- /** @internal Decode the Name Constraints extension value. */
951
+ /** Decodes the Name Constraints extension value. */
977
952
  function parseNameConstraints(e) {
978
953
  let t = f(n(e, {
979
954
  maxDepth: 64,
@@ -1011,7 +986,7 @@ function parseGeneralSubtree(e, t) {
1011
986
  if (t.tag !== 48) throw Error("name constraints GeneralSubtree must use SEQUENCE");
1012
987
  let n = i(e, t), r = n[0];
1013
988
  if (r === void 0) throw Error("GeneralSubtree base is required");
1014
- return validateGeneralSubtreeBounds(n.slice(1)), parseNameConstraintGeneralName(e, r);
989
+ return validateGeneralSubtreeBounds(n.slice(1)), parseNameConstraintGeneralName(r);
1015
990
  }
1016
991
  function validateGeneralSubtreeBounds(e) {
1017
992
  let t = !1;
@@ -1025,73 +1000,61 @@ function validateGeneralSubtreeBounds(e) {
1025
1000
  }
1026
1001
  }
1027
1002
  /** Decode a GeneralName for use in name constraints (IP carries address+mask). */
1028
- function parseNameConstraintGeneralName(e, t) {
1029
- switch (t.tag) {
1003
+ function parseNameConstraintGeneralName(e) {
1004
+ switch (e.tag) {
1030
1005
  case 160: return {
1031
1006
  type: "otherName",
1032
- value: new Uint8Array(t.value)
1007
+ value: new Uint8Array(e.value)
1033
1008
  };
1034
1009
  case 129: return {
1035
1010
  type: "email",
1036
- value: N.decode(t.value)
1011
+ value: l(22, e.value)
1037
1012
  };
1038
1013
  case 130: return {
1039
1014
  type: "dns",
1040
- value: N.decode(t.value)
1015
+ value: l(22, e.value)
1041
1016
  };
1042
1017
  case 163: return {
1043
1018
  type: "x400Address",
1044
- value: new Uint8Array(t.value)
1019
+ value: new Uint8Array(e.value)
1045
1020
  };
1046
1021
  case 134: return {
1047
1022
  type: "uri",
1048
- value: N.decode(t.value)
1023
+ value: l(22, e.value)
1049
1024
  };
1050
1025
  case 135:
1051
- if (t.value.length === 8) return {
1026
+ if (e.value.length === 8) return {
1052
1027
  type: "ip",
1053
- addressBytes: t.value.slice(0, 4),
1054
- maskBytes: t.value.slice(4, 8)
1028
+ addressBytes: e.value.slice(0, 4),
1029
+ maskBytes: e.value.slice(4, 8)
1055
1030
  };
1056
- if (t.value.length === 32) return {
1031
+ if (e.value.length === 32) return {
1057
1032
  type: "ip",
1058
- addressBytes: t.value.slice(0, 16),
1059
- maskBytes: t.value.slice(16, 32)
1033
+ addressBytes: e.value.slice(0, 16),
1034
+ maskBytes: e.value.slice(16, 32)
1060
1035
  };
1061
- throw Error(`Invalid IP name constraint: expected 8 (IPv4) or 32 (IPv6) bytes, got ${String(t.value.length)}`);
1036
+ throw Error(`Invalid IP name constraint: expected 8 (IPv4) or 32 (IPv6) bytes, got ${String(e.value.length)}`);
1062
1037
  case 164: return {
1063
1038
  type: "directoryName",
1064
- derHex: p(rebuildDirectoryNameFromImplicit(t, e))
1039
+ derHex: p(E(e))
1065
1040
  };
1066
1041
  case 165: return {
1067
1042
  type: "ediPartyName",
1068
- value: new Uint8Array(t.value)
1043
+ value: new Uint8Array(e.value)
1069
1044
  };
1070
1045
  case 136: return {
1071
1046
  type: "registeredID",
1072
- value: c(t.value)
1047
+ value: c(e.value)
1073
1048
  };
1074
1049
  }
1075
- throw Error(`Unsupported name constraint GeneralName tag: ${String(t.tag)}`);
1076
- }
1077
- /**
1078
- * Extracts the Name SEQUENCE from an implicitly-tagged directoryName [4].
1079
- *
1080
- * Handles two encoding styles found in the wild:
1081
- * - Proper implicit: [4] replaces SEQUENCE tag, content is RDN SETs directly → wrap with 0x30
1082
- * - Explicit-like: [4] wraps entire SEQUENCE, content starts with 0x30 → return content as-is
1083
- */
1084
- function rebuildDirectoryNameFromImplicit(t, n) {
1085
- if (t.value.length > 0 && t.value[0] === 48) return new Uint8Array(t.value);
1086
- let r = e(t.value.length), i = new Uint8Array(1 + r.length + t.value.length);
1087
- return i[0] = 48, i.set(r, 1), i.set(t.value, 1 + r.length), i;
1050
+ throw Error(`Unsupported name constraint GeneralName tag: ${String(e.tag)}`);
1088
1051
  }
1089
1052
  /** Decode a DisplayText (UTF8String, IA5String, VisibleString, or BMPString). */
1090
1053
  function parseDisplayText(e) {
1091
1054
  switch (e.tag) {
1092
1055
  case 12:
1093
1056
  case 22:
1094
- case 26: return N.decode(e.value);
1057
+ case 26: return F.decode(e.value);
1095
1058
  case 30: return decodeBmpString(e.value);
1096
1059
  default: throw Error(`Unsupported DisplayText tag: ${e.tag}`);
1097
1060
  }
@@ -1107,6 +1070,7 @@ function decodeBmpString(e) {
1107
1070
  }
1108
1071
  return t;
1109
1072
  }
1073
+ /** Decodes the Authority Key Identifier extension, returning the keyIdentifier hex or undefined. */
1110
1074
  function parseAuthorityKeyIdentifier(e) {
1111
1075
  let n = f(t(e, 0), "authorityKeyIdentifier sequence");
1112
1076
  if (n.end !== e.length) throw Error("Trailing data after DER element");
@@ -1150,7 +1114,7 @@ function parseAuthorityKeyIdentifierIssuer(e, t, n) {
1150
1114
  if (r.length === 0) throw Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
1151
1115
  for (let t of r) {
1152
1116
  if ((t.tag & 192) != 128) throw Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
1153
- parseGeneralName(e, t);
1117
+ N(e, t);
1154
1118
  }
1155
1119
  n.sawAuthorityCertIssuer = !0, n.lastFieldOrder = 1;
1156
1120
  }
@@ -1179,6 +1143,6 @@ function validateImplicitBitStringContent(e, t) {
1179
1143
  if (i & (1 << n) - 1) throw Error(`${t} BIT STRING must not set padding bits`);
1180
1144
  }
1181
1145
  //#endregion
1182
- export { certificateMatchesPrivateKey, decodeExtension, decodeExtensionMap, decodeExtensions, defineExtensionDecoder, defineExtensionDecoderMap, findExtension, getSubjectPublicKey, getSubjectPublicKeyOrThrow, matchCertificatePrivateKey, parseAuthorityInfoAccess, parseAuthorityKeyIdentifier, parseBasicConstraints, parseCertificateChainPem, parseCertificateDer, parseCertificateDerOrThrow, parseCertificateFromSource, parseCertificatePem, parseCertificatePemOrThrow, parseCertificatePolicies, parseCertificateSigningRequestDer, parseCertificateSigningRequestDerOrThrow, parseCertificateSigningRequestPem, parseCertificateSigningRequestPemOrThrow, parseCertificatesFromSource, parseCrlDistributionPoints, parseDistinguishedNameDer, parseExtendedKeyUsage, parseInhibitAnyPolicy, parseKeyUsage, parseNameConstraints, parsePolicyConstraints, parsePolicyMappings, parseSubjectAltNames };
1146
+ export { certificateMatchesPrivateKey, decodeExtension, decodeExtensionMap, decodeExtensions, defineExtensionDecoder, defineExtensionDecoderMap, findExtension, getSubjectPublicKey, getSubjectPublicKeyOrThrow, matchCertificatePrivateKey, parseAuthorityInfoAccess, parseAuthorityKeyIdentifier, parseBasicConstraints, parseCertificateChainPem, parseCertificateChainPemOrThrow, parseCertificateDer, parseCertificateDerOrThrow, parseCertificateFromSource, parseCertificatePem, parseCertificatePemOrThrow, parseCertificatePolicies, parseCertificateSigningRequestDer, parseCertificateSigningRequestDerOrThrow, parseCertificateSigningRequestPem, parseCertificateSigningRequestPemOrThrow, parseCertificatesFromSource, parseCrlDistributionPoints, parseDistinguishedNameDer, parseExtendedKeyUsage, parseInhibitAnyPolicy, parseKeyUsage, parseNameConstraints, parsePolicyConstraints, parsePolicyMappings, parseSubjectAltNames };
1183
1147
 
1184
1148
  //# sourceMappingURL=parse.js.map