micro509 0.8.0 → 0.10.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 (108) hide show
  1. package/dist/index.d.ts +4 -4
  2. package/dist/index.js +15 -15
  3. package/dist/internal/asn1/asn1.js +145 -186
  4. package/dist/internal/asn1/asn1.js.map +1 -0
  5. package/dist/internal/asn1/der.js +210 -227
  6. package/dist/internal/asn1/der.js.map +1 -0
  7. package/dist/internal/asn1/oids.js +297 -101
  8. package/dist/internal/asn1/oids.js.map +1 -0
  9. package/dist/internal/asn1/oids2.js +69 -0
  10. package/dist/internal/asn1/oids2.js.map +1 -0
  11. package/dist/internal/crypto/algorithm-names.js +37 -35
  12. package/dist/internal/crypto/algorithm-names.js.map +1 -0
  13. package/dist/internal/crypto/ecdsa.js +25 -28
  14. package/dist/internal/crypto/ecdsa.js.map +1 -0
  15. package/dist/internal/crypto/hash.js +56 -117
  16. package/dist/internal/crypto/hash.js.map +1 -0
  17. package/dist/internal/crypto/pbes2.js +122 -133
  18. package/dist/internal/crypto/pbes2.js.map +1 -0
  19. package/dist/internal/crypto/rsa-pss.js +118 -124
  20. package/dist/internal/crypto/rsa-pss.js.map +1 -0
  21. package/dist/internal/crypto/sig-verify.js +87 -99
  22. package/dist/internal/crypto/sig-verify.js.map +1 -0
  23. package/dist/internal/crypto/signing.d.ts +12 -8
  24. package/dist/internal/crypto/signing.js +53 -55
  25. package/dist/internal/crypto/signing.js.map +1 -0
  26. package/dist/internal/crypto/webcrypto.js +5 -3
  27. package/dist/internal/crypto/webcrypto.js.map +1 -0
  28. package/dist/internal/shared/base64.js +10 -9
  29. package/dist/internal/shared/base64.js.map +1 -0
  30. package/dist/internal/shared/dn.js +50 -57
  31. package/dist/internal/shared/dn.js.map +1 -0
  32. package/dist/internal/shared/ip.js +43 -53
  33. package/dist/internal/shared/ip.js.map +1 -0
  34. package/dist/internal/verify/name-constraints-engine.js +211 -239
  35. package/dist/internal/verify/name-constraints-engine.js.map +1 -0
  36. package/dist/internal/verify/policy-engine.js +228 -247
  37. package/dist/internal/verify/policy-engine.js.map +1 -0
  38. package/dist/internal/verify/verify-path.js +213 -228
  39. package/dist/internal/verify/verify-path.js.map +1 -0
  40. package/dist/internal/x509/extension-bits.js +62 -59
  41. package/dist/internal/x509/extension-bits.js.map +1 -0
  42. package/dist/internal/x509/extension-registry.js +133 -164
  43. package/dist/internal/x509/extension-registry.js.map +1 -0
  44. package/dist/internal/x509/name-fields.js +35 -41
  45. package/dist/internal/x509/name-fields.js.map +1 -0
  46. package/dist/keys/keys.d.ts +626 -447
  47. package/dist/keys/keys.js +652 -404
  48. package/dist/keys/keys.js.map +1 -0
  49. package/dist/keys.d.ts +2 -2
  50. package/dist/keys.js +2 -2
  51. package/dist/pem/pem.d.ts +46 -46
  52. package/dist/pem/pem.js +62 -81
  53. package/dist/pem/pem.js.map +1 -0
  54. package/dist/pem.js +2 -2
  55. package/dist/pkcs/pfx.d.ts +96 -80
  56. package/dist/pkcs/pfx.js +191 -231
  57. package/dist/pkcs/pfx.js.map +1 -0
  58. package/dist/pkcs/pkcs12-mac.d.ts +20 -18
  59. package/dist/pkcs/pkcs12-mac.js +90 -111
  60. package/dist/pkcs/pkcs12-mac.js.map +1 -0
  61. package/dist/pkcs/pkcs7.d.ts +118 -69
  62. package/dist/pkcs/pkcs7.js +401 -443
  63. package/dist/pkcs/pkcs7.js.map +1 -0
  64. package/dist/pkcs.d.ts +2 -2
  65. package/dist/pkcs.js +4 -4
  66. package/dist/result/result.d.ts +37 -32
  67. package/dist/result/result.js +46 -44
  68. package/dist/result/result.js.map +1 -0
  69. package/dist/result.js +2 -2
  70. package/dist/revocation/chain.d.ts +138 -119
  71. package/dist/revocation/chain.js +248 -281
  72. package/dist/revocation/chain.js.map +1 -0
  73. package/dist/revocation/crl.d.ts +125 -123
  74. package/dist/revocation/crl.js +653 -745
  75. package/dist/revocation/crl.js.map +1 -0
  76. package/dist/revocation/ocsp.d.ts +183 -177
  77. package/dist/revocation/ocsp.js +581 -638
  78. package/dist/revocation/ocsp.js.map +1 -0
  79. package/dist/revocation/revocation.d.ts +26 -26
  80. package/dist/revocation/revocation.js +104 -125
  81. package/dist/revocation/revocation.js.map +1 -0
  82. package/dist/revocation.js +5 -5
  83. package/dist/verify/identity.d.ts +42 -42
  84. package/dist/verify/identity.js +158 -167
  85. package/dist/verify/identity.js.map +1 -0
  86. package/dist/verify/name-constraints.d.ts +7 -7
  87. package/dist/verify/policy.d.ts +10 -10
  88. package/dist/verify/verify.d.ts +163 -163
  89. package/dist/verify/verify.js +396 -392
  90. package/dist/verify/verify.js.map +1 -0
  91. package/dist/verify.js +3 -3
  92. package/dist/x509/certificate.d.ts +117 -117
  93. package/dist/x509/certificate.js +51 -60
  94. package/dist/x509/certificate.js.map +1 -0
  95. package/dist/x509/csr.d.ts +25 -25
  96. package/dist/x509/csr.js +26 -30
  97. package/dist/x509/csr.js.map +1 -0
  98. package/dist/x509/extensions.d.ts +228 -184
  99. package/dist/x509/extensions.js +175 -200
  100. package/dist/x509/extensions.js.map +1 -0
  101. package/dist/x509/name.d.ts +94 -93
  102. package/dist/x509/name.js +30 -29
  103. package/dist/x509/name.js.map +1 -0
  104. package/dist/x509/parse.d.ts +185 -185
  105. package/dist/x509/parse.js +638 -676
  106. package/dist/x509/parse.js.map +1 -0
  107. package/dist/x509.js +6 -6
  108. package/package.json +79 -41
@@ -1,11 +1,11 @@
1
- import { bool, concatBytes, explicitContext, ia5String, implicitConstructedContext, implicitPrimitiveContext, integerFromNumber, objectIdentifier, octetString, readElement, readRootElement, readSequenceChildren, sequence, tlv, utf8String } from "../internal/asn1/der.js";
2
- import { hexToBytes } from "../internal/asn1/asn1.js";
3
- import { OIDS } from "../internal/asn1/oids.js";
4
- import { sha1 } from "../internal/crypto/hash.js";
5
- import { parseIpAddressToBytes } from "../internal/shared/ip.js";
6
- import { encodeDistributionPointReasonFlagsContent, encodeKeyUsageExtension } from "../internal/x509/extension-bits.js";
7
- import { encodeRelativeDistinguishedName } from "./name.js";
8
- import { AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION, AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION, BASIC_CONSTRAINTS_EXTENSION_DEFINITION, CERTIFICATE_POLICIES_EXTENSION_DEFINITION, CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION, EXTENDED_KEY_USAGE_EXTENSION_DEFINITION, INHIBIT_ANY_POLICY_EXTENSION_DEFINITION, KEY_USAGE_EXTENSION_DEFINITION, NAME_CONSTRAINTS_EXTENSION_DEFINITION, POLICY_CONSTRAINTS_EXTENSION_DEFINITION, POLICY_MAPPINGS_EXTENSION_DEFINITION, SUBJECT_ALT_NAME_EXTENSION_DEFINITION, SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION, getExtensionDefinition } from "../internal/x509/extension-registry.js";
1
+ import { bool as e, concatBytes as t, explicitContext as n, ia5String as r, implicitConstructedContext as i, implicitPrimitiveContext as a, integerFromNumber as o, objectIdentifier as s, octetString as c, readElement as l, readRootElement as u, readSequenceChildren as d, sequence as f, tlv as p, utf8String as m } from "../internal/asn1/der.js";
2
+ import { hexToBytes as h } from "../internal/asn1/asn1.js";
3
+ import { OIDS as g } from "../internal/asn1/oids2.js";
4
+ import { sha1 as _ } from "../internal/crypto/hash.js";
5
+ import { parseIpAddressToBytes as v } from "../internal/shared/ip.js";
6
+ import { encodeDistributionPointReasonFlagsContent as y, encodeKeyUsageExtension as b } from "../internal/x509/extension-bits.js";
7
+ import { encodeRelativeDistinguishedName as x } from "./name.js";
8
+ import { AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION as S, AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION as C, BASIC_CONSTRAINTS_EXTENSION_DEFINITION as w, CERTIFICATE_POLICIES_EXTENSION_DEFINITION as T, CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION as E, EXTENDED_KEY_USAGE_EXTENSION_DEFINITION as D, INHIBIT_ANY_POLICY_EXTENSION_DEFINITION as O, KEY_USAGE_EXTENSION_DEFINITION as k, NAME_CONSTRAINTS_EXTENSION_DEFINITION as A, POLICY_CONSTRAINTS_EXTENSION_DEFINITION as j, POLICY_MAPPINGS_EXTENSION_DEFINITION as M, SUBJECT_ALT_NAME_EXTENSION_DEFINITION as N, SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION as P, getExtensionDefinition as F } from "../internal/x509/extension-registry.js";
9
9
  //#region src/x509/extensions.ts
10
10
  /**
11
11
  * Typed certificate and CSR extension model plus ASN.1 encoder helpers.
@@ -16,18 +16,16 @@ import { AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION, AUTHORITY_KEY_IDENTIFIER_EX
16
16
  * @module
17
17
  */
18
18
  /** Map from well-known EKU names to their dotted-decimal OIDs. */
19
- const EXTENDED_KEY_USAGE_OIDS = {
20
- serverAuth: OIDS.serverAuth,
21
- clientAuth: OIDS.clientAuth,
22
- codeSigning: OIDS.codeSigning,
23
- emailProtection: OIDS.emailProtection,
24
- timeStamping: OIDS.timeStamping,
25
- ocspSigning: OIDS.ocspSigning
26
- };
27
- /** Map from well-known AIA method names to their dotted-decimal OIDs. */
28
- const AUTHORITY_INFO_ACCESS_METHOD_OIDS = {
29
- ocsp: OIDS.ocspAccessMethod,
30
- caIssuers: OIDS.caIssuersAccessMethod
19
+ const I = {
20
+ serverAuth: g.serverAuth,
21
+ clientAuth: g.clientAuth,
22
+ codeSigning: g.codeSigning,
23
+ emailProtection: g.emailProtection,
24
+ timeStamping: g.timeStamping,
25
+ ocspSigning: g.ocspSigning
26
+ }, L = {
27
+ ocsp: g.ocspAccessMethod,
28
+ caIssuers: g.caIssuersAccessMethod
31
29
  };
32
30
  /**
33
31
  * Build the v3 extensions block for a certificate.
@@ -43,17 +41,12 @@ const AUTHORITY_INFO_ACCESS_METHOD_OIDS = {
43
41
  * subjectAltName extension is marked critical per RFC 5280 §4.2.1.6.
44
42
  * @returns Array of DER-encoded Extension SEQUENCEs.
45
43
  */
46
- function buildCertificateExtensions(subjectPublicKeyInfo, issuerPublicKeyInfo, input, subjectIsEmpty = false) {
47
- const extensions = [];
48
- const seen = /* @__PURE__ */ new Set();
49
- pushKnownExtension(extensions, seen, BASIC_CONSTRAINTS_EXTENSION_DEFINITION, input?.basicConstraints ?? { ca: false });
50
- pushKnownExtension(extensions, seen, SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION, buildSubjectKeyIdentifier(subjectPublicKeyInfo));
51
- if (issuerPublicKeyInfo !== void 0) pushKnownExtension(extensions, seen, AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION, buildSubjectKeyIdentifier(issuerPublicKeyInfo));
52
- appendConfiguredExtensions(extensions, seen, input, "certificate", {
53
- includeBasicConstraints: false,
54
- subjectIsEmpty
55
- });
56
- return extensions;
44
+ function buildCertificateExtensions(e, t, n, r = !1) {
45
+ let i = [], a = /* @__PURE__ */ new Set();
46
+ return pushKnownExtension(i, a, w, n?.basicConstraints ?? { ca: !1 }), pushKnownExtension(i, a, P, buildSubjectKeyIdentifier(e)), t !== void 0 && pushKnownExtension(i, a, C, buildSubjectKeyIdentifier(t)), appendConfiguredExtensions(i, a, n, "certificate", {
47
+ includeBasicConstraints: !1,
48
+ subjectIsEmpty: r
49
+ }), i;
57
50
  }
58
51
  /**
59
52
  * Build the extensions for a CSR's extensionRequest attribute.
@@ -63,37 +56,41 @@ function buildCertificateExtensions(subjectPublicKeyInfo, issuerPublicKeyInfo, i
63
56
  * @param input Optional extension configuration.
64
57
  * @returns Array of DER-encoded Extension SEQUENCEs.
65
58
  */
66
- function buildRequestedExtensions(input) {
67
- const extensions = [];
68
- appendConfiguredExtensions(extensions, /* @__PURE__ */ new Set(), input, "csr", { includeBasicConstraints: true });
69
- return extensions;
59
+ function buildRequestedExtensions(e) {
60
+ let t = [];
61
+ return appendConfiguredExtensions(t, /* @__PURE__ */ new Set(), e, "csr", { includeBasicConstraints: !0 }), t;
70
62
  }
71
63
  /** Encode and push each configured extension from the input, enforcing no duplicates. */
72
- function appendConfiguredExtensions(encoded, seen, input, context, options) {
73
- if (input === void 0) return;
74
- if (options.includeBasicConstraints && input.basicConstraints !== void 0) pushKnownExtension(encoded, seen, BASIC_CONSTRAINTS_EXTENSION_DEFINITION, input.basicConstraints);
75
- if (input.keyUsage !== void 0 && input.keyUsage.length > 0) pushKnownExtension(encoded, seen, KEY_USAGE_EXTENSION_DEFINITION, input.keyUsage);
76
- if (input.subjectAltNames !== void 0 && input.subjectAltNames.length > 0) {
77
- const sanCritical = options.subjectIsEmpty === true ? true : void 0;
78
- pushKnownExtension(encoded, seen, SUBJECT_ALT_NAME_EXTENSION_DEFINITION, input.subjectAltNames, sanCritical);
64
+ function appendConfiguredExtensions(e, t, n, r, i) {
65
+ n !== void 0 && (appendConstraintExtensions(e, t, n, i.includeBasicConstraints), appendIdentityExtensions(e, t, n, i.subjectIsEmpty === !0), appendPolicyExtensions(e, t, n), appendAccessExtensions(e, t, n), appendCustomExtensions(e, t, n, r));
66
+ }
67
+ function appendConstraintExtensions(e, t, n, r) {
68
+ r && n.basicConstraints !== void 0 && pushKnownExtension(e, t, w, n.basicConstraints), n.keyUsage !== void 0 && n.keyUsage.length > 0 && pushKnownExtension(e, t, k, n.keyUsage), n.nameConstraints !== void 0 && pushKnownExtension(e, t, A, n.nameConstraints);
69
+ }
70
+ function appendIdentityExtensions(e, t, n, r) {
71
+ if (n.subjectAltNames !== void 0 && n.subjectAltNames.length > 0) {
72
+ let i = r ? !0 : void 0;
73
+ pushKnownExtension(e, t, N, n.subjectAltNames, i);
79
74
  }
80
- if (input.extendedKeyUsage !== void 0 && input.extendedKeyUsage.length > 0) pushKnownExtension(encoded, seen, EXTENDED_KEY_USAGE_EXTENSION_DEFINITION, input.extendedKeyUsage);
81
- if (input.nameConstraints !== void 0) pushKnownExtension(encoded, seen, NAME_CONSTRAINTS_EXTENSION_DEFINITION, input.nameConstraints);
82
- if (input.certificatePolicies !== void 0 && input.certificatePolicies.length > 0) pushKnownExtension(encoded, seen, CERTIFICATE_POLICIES_EXTENSION_DEFINITION, input.certificatePolicies);
83
- if (input.policyMappings !== void 0 && input.policyMappings.length > 0) pushKnownExtension(encoded, seen, POLICY_MAPPINGS_EXTENSION_DEFINITION, input.policyMappings);
84
- if (input.policyConstraints !== void 0) pushKnownExtension(encoded, seen, POLICY_CONSTRAINTS_EXTENSION_DEFINITION, input.policyConstraints);
85
- if (input.inhibitAnyPolicy !== void 0) pushKnownExtension(encoded, seen, INHIBIT_ANY_POLICY_EXTENSION_DEFINITION, input.inhibitAnyPolicy);
86
- if (input.authorityInfoAccess !== void 0 && input.authorityInfoAccess.length > 0) pushKnownExtension(encoded, seen, AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION, input.authorityInfoAccess);
87
- if (input.crlDistributionPoints !== void 0 && input.crlDistributionPoints.length > 0) pushKnownExtension(encoded, seen, CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION, input.crlDistributionPoints);
88
- if (input.customExtensions !== void 0) for (const extension of input.customExtensions) {
89
- const knownDefinition = getExtensionDefinition(extension.oid);
90
- if (knownDefinition !== void 0 && !knownDefinition.contexts.includes(context)) throw new Error(`Extension ${extension.oid} is not supported in ${context} context`);
91
- pushExtension(encoded, seen, extension.oid, new Uint8Array(extension.value), extension.critical ?? false);
75
+ n.extendedKeyUsage !== void 0 && n.extendedKeyUsage.length > 0 && pushKnownExtension(e, t, D, n.extendedKeyUsage);
76
+ }
77
+ /** Appends configured certificate-policy extensions while enforcing unique OIDs. */
78
+ function appendPolicyExtensions(e, t, n) {
79
+ n.certificatePolicies !== void 0 && n.certificatePolicies.length > 0 && pushKnownExtension(e, t, T, n.certificatePolicies), n.policyMappings !== void 0 && n.policyMappings.length > 0 && pushKnownExtension(e, t, M, n.policyMappings), n.policyConstraints !== void 0 && pushKnownExtension(e, t, j, n.policyConstraints), n.inhibitAnyPolicy !== void 0 && pushKnownExtension(e, t, O, n.inhibitAnyPolicy);
80
+ }
81
+ function appendAccessExtensions(e, t, n) {
82
+ n.authorityInfoAccess !== void 0 && n.authorityInfoAccess.length > 0 && pushKnownExtension(e, t, S, n.authorityInfoAccess), n.crlDistributionPoints !== void 0 && n.crlDistributionPoints.length > 0 && pushKnownExtension(e, t, E, n.crlDistributionPoints);
83
+ }
84
+ function appendCustomExtensions(e, t, n, r) {
85
+ if (n.customExtensions !== void 0) for (let i of n.customExtensions) {
86
+ let n = F(i.oid);
87
+ if (n !== void 0 && !n.contexts.includes(r)) throw Error(`Extension ${i.oid} is not supported in ${r} context`);
88
+ pushExtension(e, t, i.oid, new Uint8Array(i.value), i.critical ?? !1);
92
89
  }
93
90
  }
94
91
  /** Encode a known extension via its registry definition and push it. */
95
- function pushKnownExtension(encoded, seen, definition, value, critical = definition.defaultCritical) {
96
- pushExtension(encoded, seen, definition.oid, definition.encode(value), critical);
92
+ function pushKnownExtension(e, t, n, r, i = n.defaultCritical) {
93
+ pushExtension(e, t, n.oid, n.encode(r), i);
97
94
  }
98
95
  /**
99
96
  * Encode a single X.509 Extension SEQUENCE (OID + optional critical BOOLEAN + OCTET STRING).
@@ -102,11 +99,9 @@ function pushKnownExtension(encoded, seen, definition, value, critical = definit
102
99
  * @param extnValue DER-encoded extension payload.
103
100
  * @param critical Whether to mark the extension as critical. Default `false`.
104
101
  */
105
- function encodeExtension(oid, extnValue, critical = false) {
106
- const fields = [objectIdentifier(oid)];
107
- if (critical) fields.push(bool(true));
108
- fields.push(octetString(extnValue));
109
- return sequence(fields);
102
+ function encodeExtension(t, n, r = !1) {
103
+ let i = [s(t)];
104
+ return r && i.push(e(!0)), i.push(c(n)), f(i);
110
105
  }
111
106
  /**
112
107
  * DER-encode a {@linkcode BasicConstraints} value.
@@ -114,38 +109,37 @@ function encodeExtension(oid, extnValue, critical = false) {
114
109
  * @param input CA flag and optional pathLength.
115
110
  * @returns DER SEQUENCE suitable for wrapping in an Extension OCTET STRING.
116
111
  */
117
- function encodeBasicConstraints(input) {
118
- const fields = [];
119
- if (input.ca) fields.push(bool(true));
120
- if (input.pathLength !== void 0) {
121
- if (!input.ca) throw new Error("pathLength requires ca=true");
122
- fields.push(integerFromNumber(input.pathLength));
112
+ function encodeBasicConstraints(t) {
113
+ let n = [];
114
+ if (t.ca && n.push(e(!0)), t.pathLength !== void 0) {
115
+ if (!t.ca) throw Error("pathLength requires ca=true");
116
+ n.push(o(t.pathLength));
123
117
  }
124
- return sequence(fields);
118
+ return f(n);
125
119
  }
126
120
  /**
127
121
  * DER-encode a Key Usage BIT STRING from an array of {@linkcode KeyUsage} flags.
128
122
  *
129
123
  * @param usages Flags to set in the bit string.
130
124
  */
131
- function encodeKeyUsage(usages) {
132
- return encodeKeyUsageExtension(usages);
125
+ function encodeKeyUsage(e) {
126
+ return b(e);
133
127
  }
134
128
  /**
135
129
  * DER-encode a single {@linkcode SubjectAltName} GeneralName element.
136
130
  *
137
131
  * @param value The SAN entry to encode.
138
132
  */
139
- function encodeSubjectAltName(value) {
140
- switch (value.type) {
141
- case "dns": return implicitPrimitiveContext(2, new TextEncoder().encode(value.value));
142
- case "email": return implicitPrimitiveContext(1, new TextEncoder().encode(value.value));
143
- case "uri": return implicitPrimitiveContext(6, new TextEncoder().encode(value.value));
144
- case "srv": return implicitConstructedContext(0, sequence([objectIdentifier(OIDS.idOnDnsSrv), explicitContext(0, ia5String(value.value))]));
145
- case "ip": return implicitPrimitiveContext(7, encodeIpAddress(value.value));
146
- case "directoryName": return implicitConstructedContext(4, extractDirectoryNameContent(value.derHex));
147
- case "unknown": return tlv(value.tag, value.value);
148
- default: throw new Error(`Unhandled SubjectAltName type: ${String(value)}`);
133
+ function encodeSubjectAltName(e) {
134
+ switch (e.type) {
135
+ case "dns": return a(2, new TextEncoder().encode(e.value));
136
+ case "email": return a(1, new TextEncoder().encode(e.value));
137
+ case "uri": return a(6, new TextEncoder().encode(e.value));
138
+ case "srv": return i(0, f([s(g.idOnDnsSrv), n(0, r(e.value))]));
139
+ case "ip": return a(7, encodeIpAddress(e.value));
140
+ case "directoryName": return i(4, extractDirectoryNameContent(e.derHex));
141
+ case "unknown": return p(e.tag, e.value);
142
+ default: throw Error(`Unhandled SubjectAltName type: ${String(e)}`);
149
143
  }
150
144
  }
151
145
  /**
@@ -153,57 +147,53 @@ function encodeSubjectAltName(value) {
153
147
  *
154
148
  * @param usages EKU purposes to encode.
155
149
  */
156
- function encodeExtendedKeyUsage(usages) {
157
- return sequence(usages.map((usage) => objectIdentifier(getExtendedKeyUsageOid(usage))));
150
+ function encodeExtendedKeyUsage(e) {
151
+ return f(e.map((e) => s(getExtendedKeyUsageOid(e))));
158
152
  }
159
153
  /**
160
154
  * DER-encode an Authority Information Access SEQUENCE.
161
155
  *
162
156
  * @param entries AIA entries (OCSP, caIssuers, or custom) to encode.
163
157
  */
164
- function encodeAuthorityInfoAccess(entries) {
165
- return sequence(entries.map((entry) => sequence([objectIdentifier(getAuthorityInfoAccessMethodOid(entry.method)), implicitPrimitiveContext(6, new TextEncoder().encode(entry.uri))])));
158
+ function encodeAuthorityInfoAccess(e) {
159
+ return f(e.map((e) => f([s(getAuthorityInfoAccessMethodOid(e.method)), a(6, new TextEncoder().encode(e.uri))])));
166
160
  }
167
161
  /**
168
162
  * DER-encode a CRL Distribution Points SEQUENCE.
169
163
  *
170
164
  * @param points Distribution points to encode.
171
165
  */
172
- function encodeCrlDistributionPoints(points) {
173
- return sequence(points.map((point) => sequence(encodeDistributionPoint(point))));
166
+ function encodeCrlDistributionPoints(e) {
167
+ return f(e.map((e) => f(encodeDistributionPoint(e))));
174
168
  }
175
169
  /**
176
170
  * DER-encode a Name Constraints extension value.
177
171
  *
178
172
  * @param constraints Permitted and/or excluded subtrees.
179
173
  */
180
- function encodeNameConstraints(constraints) {
181
- const parts = [];
182
- if (constraints.permittedSubtrees !== void 0 && constraints.permittedSubtrees.length > 0) parts.push(implicitConstructedContext(0, concatBytes(constraints.permittedSubtrees.map(encodeGeneralSubtree))));
183
- if (constraints.excludedSubtrees !== void 0 && constraints.excludedSubtrees.length > 0) parts.push(implicitConstructedContext(1, concatBytes(constraints.excludedSubtrees.map(encodeGeneralSubtree))));
184
- return sequence(parts);
174
+ function encodeNameConstraints(e) {
175
+ let n = [];
176
+ return e.permittedSubtrees !== void 0 && e.permittedSubtrees.length > 0 && n.push(i(0, t(e.permittedSubtrees.map(encodeGeneralSubtree)))), e.excludedSubtrees !== void 0 && e.excludedSubtrees.length > 0 && n.push(i(1, t(e.excludedSubtrees.map(encodeGeneralSubtree)))), f(n);
185
177
  }
186
178
  /**
187
179
  * DER-encode a Certificate Policies extension value.
188
180
  *
189
181
  * @param policies Non-empty array of policy information entries.
190
182
  */
191
- function encodeCertificatePolicies(policies) {
192
- if (policies.length === 0) throw new Error("certificatePolicies must not be empty");
193
- return sequence(policies.map(encodePolicyInformation));
183
+ function encodeCertificatePolicies(e) {
184
+ if (e.length === 0) throw Error("certificatePolicies must not be empty");
185
+ return f(e.map(encodePolicyInformation));
194
186
  }
195
187
  /**
196
188
  * DER-encode a Policy Mappings extension value.
197
189
  *
198
190
  * @param mappings Non-empty array of issuer-to-subject policy pairs. Neither OID may be anyPolicy.
199
191
  */
200
- function encodePolicyMappings(mappings) {
201
- if (mappings.length === 0) throw new Error("policyMappings must not be empty");
202
- return sequence(mappings.map((mapping) => {
203
- validatePolicyOid(mapping.issuerDomainPolicy);
204
- validatePolicyOid(mapping.subjectDomainPolicy);
205
- if (mapping.issuerDomainPolicy === OIDS.anyPolicy || mapping.subjectDomainPolicy === OIDS.anyPolicy) throw new Error("policyMappings must not use anyPolicy");
206
- return sequence([objectIdentifier(mapping.issuerDomainPolicy), objectIdentifier(mapping.subjectDomainPolicy)]);
192
+ function encodePolicyMappings(e) {
193
+ if (e.length === 0) throw Error("policyMappings must not be empty");
194
+ return f(e.map((e) => {
195
+ if (validatePolicyOid(e.issuerDomainPolicy), validatePolicyOid(e.subjectDomainPolicy), e.issuerDomainPolicy === g.anyPolicy || e.subjectDomainPolicy === g.anyPolicy) throw Error("policyMappings must not use anyPolicy");
196
+ return f([s(e.issuerDomainPolicy), s(e.subjectDomainPolicy)]);
207
197
  }));
208
198
  }
209
199
  /**
@@ -211,126 +201,113 @@ function encodePolicyMappings(mappings) {
211
201
  *
212
202
  * @param constraints At least one of `requireExplicitPolicy` or `inhibitPolicyMapping` must be set.
213
203
  */
214
- function encodePolicyConstraints(constraints) {
215
- const fields = [];
216
- if (constraints.requireExplicitPolicy !== void 0) fields.push(implicitPrimitiveContext(0, encodeIntegerContent(constraints.requireExplicitPolicy)));
217
- if (constraints.inhibitPolicyMapping !== void 0) fields.push(implicitPrimitiveContext(1, encodeIntegerContent(constraints.inhibitPolicyMapping)));
218
- if (fields.length === 0) throw new Error("policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping");
219
- return sequence(fields);
204
+ function encodePolicyConstraints(e) {
205
+ let t = [];
206
+ if (e.requireExplicitPolicy !== void 0 && t.push(a(0, encodeIntegerContent(e.requireExplicitPolicy))), e.inhibitPolicyMapping !== void 0 && t.push(a(1, encodeIntegerContent(e.inhibitPolicyMapping))), t.length === 0) throw Error("policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping");
207
+ return f(t);
220
208
  }
221
209
  /**
222
210
  * DER-encode an Inhibit anyPolicy extension value (single INTEGER).
223
211
  *
224
212
  * @param input The skipCerts threshold.
225
213
  */
226
- function encodeInhibitAnyPolicy(input) {
227
- return integerFromNumber(input.skipCerts);
214
+ function encodeInhibitAnyPolicy(e) {
215
+ return o(e.skipCerts);
228
216
  }
229
217
  /** DER-encode a single PolicyInformation SEQUENCE. */
230
- function encodePolicyInformation(policy) {
231
- validatePolicyOid(policy.policyIdentifier);
232
- const fields = [objectIdentifier(policy.policyIdentifier)];
233
- if (policy.policyQualifiers !== void 0 && policy.policyQualifiers.length > 0) fields.push(sequence(policy.policyQualifiers.map(encodePolicyQualifierInfo)));
234
- return sequence(fields);
218
+ function encodePolicyInformation(e) {
219
+ validatePolicyOid(e.policyIdentifier);
220
+ let t = [s(e.policyIdentifier)];
221
+ return e.policyQualifiers !== void 0 && e.policyQualifiers.length > 0 && t.push(f(e.policyQualifiers.map(encodePolicyQualifierInfo))), f(t);
235
222
  }
236
223
  /** DER-encode a single PolicyQualifierInfo SEQUENCE. */
237
- function encodePolicyQualifierInfo(qualifier) {
238
- switch (qualifier.type) {
239
- case "cps": return sequence([objectIdentifier(OIDS.cpsPolicyQualifier), ia5String(qualifier.uri)]);
240
- case "userNotice": return sequence([objectIdentifier(OIDS.userNoticePolicyQualifier), encodeUserNoticePolicyQualifierInfo(qualifier)]);
241
- case "oid":
242
- validateOid(qualifier.oid);
243
- return sequence([objectIdentifier(qualifier.oid), new Uint8Array(qualifier.qualifierDer)]);
244
- default: throw new Error(`Unhandled PolicyQualifierInfo type: ${String(qualifier)}`);
224
+ function encodePolicyQualifierInfo(e) {
225
+ switch (e.type) {
226
+ case "cps": return f([s(g.cpsPolicyQualifier), r(e.uri)]);
227
+ case "userNotice": return f([s(g.userNoticePolicyQualifier), encodeUserNoticePolicyQualifierInfo(e)]);
228
+ case "oid": return validateOid(e.oid), f([s(e.oid), new Uint8Array(e.qualifierDer)]);
229
+ default: throw Error(`Unhandled PolicyQualifierInfo type: ${String(e)}`);
245
230
  }
246
231
  }
247
232
  /** DER-encode a UserNotice qualifier SEQUENCE. */
248
- function encodeUserNoticePolicyQualifierInfo(qualifier) {
249
- const fields = [];
250
- if (qualifier.noticeRef !== void 0) fields.push(encodePolicyNoticeReference(qualifier.noticeRef));
251
- if (qualifier.explicitText !== void 0) fields.push(utf8String(qualifier.explicitText));
252
- return sequence(fields);
233
+ function encodeUserNoticePolicyQualifierInfo(e) {
234
+ let t = [];
235
+ return e.noticeRef !== void 0 && t.push(encodePolicyNoticeReference(e.noticeRef)), e.explicitText !== void 0 && t.push(m(e.explicitText)), f(t);
253
236
  }
254
237
  /** DER-encode a NoticeReference SEQUENCE. */
255
- function encodePolicyNoticeReference(reference) {
256
- return sequence([utf8String(reference.organization), sequence(reference.noticeNumbers.map((noticeNumber) => integerFromNumber(noticeNumber)))]);
238
+ function encodePolicyNoticeReference(e) {
239
+ return f([m(e.organization), f(e.noticeNumbers.map((e) => o(e)))]);
257
240
  }
258
241
  /** Encode an INTEGER and return only the content bytes (no TLV wrapper). */
259
- function encodeIntegerContent(value) {
260
- return readElement(integerFromNumber(value)).value;
242
+ function encodeIntegerContent(e) {
243
+ return l(o(e)).value;
261
244
  }
262
245
  /** DER-encode a GeneralSubtree SEQUENCE (base name only; min/max omitted per RFC 5280). */
263
- function encodeGeneralSubtree(subtree) {
264
- return sequence([encodeNameConstraintForm(subtree.base)]);
246
+ function encodeGeneralSubtree(e) {
247
+ return f([encodeNameConstraintForm(e.base)]);
265
248
  }
266
249
  /** DER-encode the fields of a single DistributionPoint. */
267
- function encodeDistributionPoint(point) {
268
- if (point.crlIssuer !== void 0 && point.crlIssuer.length === 0) throw new Error("DistributionPoint crlIssuer must not be empty");
269
- if (point.distributionPoint === void 0 && point.crlIssuer === void 0) throw new Error("DistributionPoint must contain distributionPoint or crlIssuer");
270
- const fields = [];
271
- if (point.distributionPoint !== void 0) fields.push(implicitConstructedContext(0, encodeDistributionPointName(point.distributionPoint)));
272
- if (point.reasons !== void 0 && point.reasons.length > 0) fields.push(implicitPrimitiveContext(1, encodeDistributionPointReasonFlagsContent(point.reasons)));
273
- if (point.crlIssuer !== void 0 && point.crlIssuer.length > 0) fields.push(implicitConstructedContext(2, concatBytes(point.crlIssuer.map(encodeSubjectAltName))));
274
- return fields;
250
+ function encodeDistributionPoint(e) {
251
+ if (e.crlIssuer !== void 0 && e.crlIssuer.length === 0) throw Error("DistributionPoint crlIssuer must not be empty");
252
+ if (e.distributionPoint === void 0 && e.crlIssuer === void 0) throw Error("DistributionPoint must contain distributionPoint or crlIssuer");
253
+ let n = [];
254
+ return e.distributionPoint !== void 0 && n.push(i(0, encodeDistributionPointName(e.distributionPoint))), e.reasons !== void 0 && e.reasons.length > 0 && n.push(a(1, y(e.reasons))), e.crlIssuer !== void 0 && e.crlIssuer.length > 0 && n.push(i(2, t(e.crlIssuer.map(encodeSubjectAltName)))), n;
275
255
  }
276
256
  /** DER-encode a DistributionPointName (fullName or relativeName). */
277
- function encodeDistributionPointName(name) {
278
- if (name.fullName !== void 0 && name.relativeName !== void 0) throw new Error("DistributionPointName cannot contain both fullName and relativeName");
279
- if (name.fullName !== void 0) {
280
- if (name.fullName.length === 0) throw new Error("DistributionPointName fullName must not be empty");
281
- return implicitConstructedContext(0, concatBytes(name.fullName.map(encodeSubjectAltName)));
257
+ function encodeDistributionPointName(e) {
258
+ if (e.fullName !== void 0 && e.relativeName !== void 0) throw Error("DistributionPointName cannot contain both fullName and relativeName");
259
+ if (e.fullName !== void 0) {
260
+ if (e.fullName.length === 0) throw Error("DistributionPointName fullName must not be empty");
261
+ return i(0, t(e.fullName.map(encodeSubjectAltName)));
282
262
  }
283
- if (name.relativeName !== void 0) {
284
- const relativeName = encodeRelativeDistinguishedName(name.relativeName);
285
- const relativeNameElement = readElement(relativeName);
286
- return implicitConstructedContext(1, relativeName.slice(relativeNameElement.start, relativeNameElement.end));
263
+ if (e.relativeName !== void 0) {
264
+ let t = x(e.relativeName), n = l(t);
265
+ return i(1, t.slice(n.start, n.end));
287
266
  }
288
- throw new Error("DistributionPointName must contain fullName or relativeName");
267
+ throw Error("DistributionPointName must contain fullName or relativeName");
289
268
  }
290
269
  /** DER-encode a NameConstraintForm as an implicit-tagged {@linkcode GeneralName}. */
291
- function encodeNameConstraintForm(form) {
292
- switch (form.type) {
293
- case "dns": return implicitPrimitiveContext(2, new TextEncoder().encode(form.value));
294
- case "email": return implicitPrimitiveContext(1, new TextEncoder().encode(form.value));
295
- case "uri": return implicitPrimitiveContext(6, new TextEncoder().encode(form.value));
296
- case "ip": return implicitPrimitiveContext(7, concatBytes([form.addressBytes, form.maskBytes]));
297
- case "directoryName": return implicitConstructedContext(4, extractDirectoryNameContent(form.derHex));
298
- default: throw new Error(`Unhandled NameConstraintForm type: ${String(form)}`);
270
+ function encodeNameConstraintForm(e) {
271
+ switch (e.type) {
272
+ case "dns": return a(2, new TextEncoder().encode(e.value));
273
+ case "email": return a(1, new TextEncoder().encode(e.value));
274
+ case "uri": return a(6, new TextEncoder().encode(e.value));
275
+ case "ip": return a(7, t([e.addressBytes, e.maskBytes]));
276
+ case "directoryName": return i(4, extractDirectoryNameContent(e.derHex));
277
+ default: throw Error(`Unhandled NameConstraintForm type: ${String(e)}`);
299
278
  }
300
279
  }
301
280
  /** Extract the content bytes from a hex-encoded DER SEQUENCE (strips the outer TLV). */
302
- function extractDirectoryNameContent(derHex) {
303
- const element = readRootElement(hexToBytes(derHex), { maxDepth: 64 });
304
- if (element.tag !== 48) throw new Error("directoryName derHex must encode a DER SEQUENCE");
305
- return new Uint8Array(element.value);
281
+ function extractDirectoryNameContent(e) {
282
+ let t = u(h(e), { maxDepth: 64 });
283
+ if (t.tag !== 48) throw Error("directoryName derHex must encode a DER SEQUENCE");
284
+ return new Uint8Array(t.value);
306
285
  }
307
286
  /**
308
287
  * Resolve an {@linkcode ExtendedKeyUsage} to its dotted-decimal OID.
309
288
  *
310
289
  * @param usage Well-known string or custom OID object.
311
290
  */
312
- function getExtendedKeyUsageOid(usage) {
313
- if (typeof usage === "string") return EXTENDED_KEY_USAGE_OIDS[usage];
314
- validateOid(usage.value);
315
- return usage.value;
291
+ function getExtendedKeyUsageOid(e) {
292
+ return typeof e == "string" ? I[e] : (validateOid(e.value), e.value);
316
293
  }
317
294
  /**
318
295
  * Map a dotted-decimal OID to an {@linkcode ExtendedKeyUsage} value.
319
296
  *
320
297
  * Returns a well-known string for recognized OIDs, or `{ type: 'oid', value }` otherwise.
321
298
  */
322
- function parseExtendedKeyUsageOid(oid) {
323
- switch (oid) {
324
- case OIDS.serverAuth: return "serverAuth";
325
- case OIDS.clientAuth: return "clientAuth";
326
- case OIDS.codeSigning: return "codeSigning";
327
- case OIDS.emailProtection: return "emailProtection";
328
- case OIDS.timeStamping: return "timeStamping";
329
- case OIDS.ocspSigning: return "ocspSigning";
299
+ function parseExtendedKeyUsageOid(e) {
300
+ switch (e) {
301
+ case g.serverAuth: return "serverAuth";
302
+ case g.clientAuth: return "clientAuth";
303
+ case g.codeSigning: return "codeSigning";
304
+ case g.emailProtection: return "emailProtection";
305
+ case g.timeStamping: return "timeStamping";
306
+ case g.ocspSigning: return "ocspSigning";
330
307
  }
331
308
  return {
332
309
  type: "oid",
333
- value: oid
310
+ value: e
334
311
  };
335
312
  }
336
313
  /**
@@ -338,50 +315,48 @@ function parseExtendedKeyUsageOid(oid) {
338
315
  *
339
316
  * @param method Well-known string or custom OID object.
340
317
  */
341
- function getAuthorityInfoAccessMethodOid(method) {
342
- if (typeof method === "string") return AUTHORITY_INFO_ACCESS_METHOD_OIDS[method];
343
- validateOid(method.value);
344
- return method.value;
318
+ function getAuthorityInfoAccessMethodOid(e) {
319
+ return typeof e == "string" ? L[e] : (validateOid(e.value), e.value);
345
320
  }
346
321
  /**
347
322
  * Map a dotted-decimal OID to an {@linkcode AuthorityInfoAccessMethod} value.
348
323
  *
349
324
  * Returns `'ocsp'` or `'caIssuers'` for recognized OIDs, or `{ type: 'oid', value }` otherwise.
350
325
  */
351
- function parseAuthorityInfoAccessMethodOid(oid) {
352
- switch (oid) {
353
- case OIDS.ocspAccessMethod: return "ocsp";
354
- case OIDS.caIssuersAccessMethod: return "caIssuers";
326
+ function parseAuthorityInfoAccessMethodOid(e) {
327
+ switch (e) {
328
+ case g.ocspAccessMethod: return "ocsp";
329
+ case g.caIssuersAccessMethod: return "caIssuers";
355
330
  }
356
331
  return {
357
332
  type: "oid",
358
- value: oid
333
+ value: e
359
334
  };
360
335
  }
361
336
  /** Parse a dotted-decimal/colon-hex IP string to raw address bytes. */
362
- function encodeIpAddress(input) {
363
- return parseIpAddressToBytes(input);
337
+ function encodeIpAddress(e) {
338
+ return v(e);
364
339
  }
365
340
  /** @internal Compute the SKI as SHA-1 of the subjectPublicKey BIT STRING content. */
366
- function buildSubjectKeyIdentifier(subjectPublicKeyInfo) {
367
- const subjectPublicKey = readSequenceChildren(subjectPublicKeyInfo)[1];
368
- if (subjectPublicKey === void 0 || subjectPublicKey.tag !== 3) throw new Error("SPKI missing subject public key bit string");
369
- return sha1(subjectPublicKey.value.slice(1));
341
+ function buildSubjectKeyIdentifier(e) {
342
+ let t = d(e)[1];
343
+ if (t === void 0 || t.tag !== 3) throw Error("SPKI missing subject public key bit string");
344
+ return _(t.value.slice(1));
370
345
  }
371
346
  /** Throw if the string is not a valid dotted-decimal OID. */
372
- function validateOid(oid) {
373
- if (!/^\d+(?:\.\d+)+$/.test(oid)) throw new Error(`Invalid OID: ${oid}`);
347
+ function validateOid(e) {
348
+ if (!/^\d+(?:\.\d+)+$/.test(e)) throw Error(`Invalid OID: ${e}`);
374
349
  }
375
350
  /** Validate that a policy OID is syntactically valid. */
376
- function validatePolicyOid(oid) {
377
- validateOid(oid);
351
+ function validatePolicyOid(e) {
352
+ validateOid(e);
378
353
  }
379
354
  /** Encode and push an extension, rejecting duplicate OIDs. */
380
- function pushExtension(encoded, seen, oid, value, critical = false) {
381
- validateOid(oid);
382
- if (seen.has(oid)) throw new Error(`Duplicate extension OID: ${oid}`);
383
- seen.add(oid);
384
- encoded.push(encodeExtension(oid, value, critical));
355
+ function pushExtension(e, t, n, r, i = !1) {
356
+ if (validateOid(n), t.has(n)) throw Error(`Duplicate extension OID: ${n}`);
357
+ t.add(n), e.push(encodeExtension(n, r, i));
385
358
  }
386
359
  //#endregion
387
360
  export { buildCertificateExtensions, buildRequestedExtensions, buildSubjectKeyIdentifier, encodeAuthorityInfoAccess, encodeBasicConstraints, encodeCertificatePolicies, encodeCrlDistributionPoints, encodeExtendedKeyUsage, encodeExtension, encodeInhibitAnyPolicy, encodeKeyUsage, encodeNameConstraints, encodePolicyConstraints, encodePolicyMappings, encodeSubjectAltName, getAuthorityInfoAccessMethodOid, getExtendedKeyUsageOid, parseAuthorityInfoAccessMethodOid, parseExtendedKeyUsageOid };
361
+
362
+ //# sourceMappingURL=extensions.js.map