micro509 0.13.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 (109) 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 +1 -1
  8. package/dist/index.d.ts +13 -9
  9. package/dist/index.js +17 -15
  10. package/dist/internal/asn1/asn1.js +21 -10
  11. package/dist/internal/asn1/asn1.js.map +1 -1
  12. package/dist/internal/asn1/der.d.ts +4 -2
  13. package/dist/internal/asn1/der.js +18 -5
  14. package/dist/internal/asn1/der.js.map +1 -1
  15. package/dist/internal/asn1/oids.js +7 -1
  16. package/dist/internal/crypto/algorithm-names.js +4 -0
  17. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  18. package/dist/internal/crypto/pbes2.d.ts +38 -0
  19. package/dist/internal/crypto/pbes2.js +9 -10
  20. package/dist/internal/crypto/pbes2.js.map +1 -1
  21. package/dist/internal/crypto/rsa-pss.js +2 -0
  22. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  23. package/dist/internal/crypto/sig-verify.d.ts +31 -0
  24. package/dist/internal/crypto/sig-verify.js +10 -8
  25. package/dist/internal/crypto/sig-verify.js.map +1 -1
  26. package/dist/internal/shared/base64.js +7 -1
  27. package/dist/internal/shared/base64.js.map +1 -1
  28. package/dist/internal/shared/dn.d.ts +16 -0
  29. package/dist/internal/shared/dn.js +13 -6
  30. package/dist/internal/shared/dn.js.map +1 -1
  31. package/dist/internal/shared/ip.d.ts +69 -0
  32. package/dist/internal/shared/ip.js +18 -1
  33. package/dist/internal/shared/ip.js.map +1 -1
  34. package/dist/internal/verify/verify-path.d.ts +7 -0
  35. package/dist/internal/verify/verify-path.js +36 -36
  36. package/dist/internal/x509/directory-name.js +24 -0
  37. package/dist/internal/x509/directory-name.js.map +1 -0
  38. package/dist/internal/x509/extension-bits.js +13 -10
  39. package/dist/internal/x509/extension-bits.js.map +1 -1
  40. package/dist/internal/x509/extension-errors.d.ts +6 -0
  41. package/dist/internal/x509/extension-errors.js +20 -0
  42. package/dist/internal/x509/extension-errors.js.map +1 -0
  43. package/dist/internal/x509/extension-registry.js +113 -55
  44. package/dist/internal/x509/extension-registry.js.map +1 -1
  45. package/dist/internal/x509/general-name-tags.js +28 -0
  46. package/dist/internal/x509/general-name-tags.js.map +1 -0
  47. package/dist/internal/x509/general-name.js +97 -0
  48. package/dist/internal/x509/general-name.js.map +1 -0
  49. package/dist/internal/x509/name-fields.js +20 -10
  50. package/dist/internal/x509/name-fields.js.map +1 -1
  51. package/dist/keys/keys.d.ts +16 -2
  52. package/dist/keys/keys.js +311 -170
  53. package/dist/keys/keys.js.map +1 -1
  54. package/dist/keys.d.ts +3 -2
  55. package/dist/keys.js +3 -2
  56. package/dist/pem/pem.d.ts +3 -2
  57. package/dist/pem/pem.js +112 -30
  58. package/dist/pem/pem.js.map +1 -1
  59. package/dist/pkcs/pkcs12-mac.js +3 -3
  60. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  61. package/dist/pkcs/pkcs7.d.ts +85 -21
  62. package/dist/pkcs/pkcs7.js +261 -186
  63. package/dist/pkcs/pkcs7.js.map +1 -1
  64. package/dist/pkcs.d.ts +2 -2
  65. package/dist/result/result.d.ts +18 -10
  66. package/dist/result/result.js +20 -12
  67. package/dist/result/result.js.map +1 -1
  68. package/dist/result.d.ts +2 -2
  69. package/dist/result.js +2 -2
  70. package/dist/revocation/chain.js +77 -81
  71. package/dist/revocation/chain.js.map +1 -1
  72. package/dist/revocation/crl.d.ts +13 -2
  73. package/dist/revocation/crl.js +415 -236
  74. package/dist/revocation/crl.js.map +1 -1
  75. package/dist/revocation/ocsp.d.ts +58 -17
  76. package/dist/revocation/ocsp.js +185 -173
  77. package/dist/revocation/ocsp.js.map +1 -1
  78. package/dist/revocation/revocation.d.ts +4 -4
  79. package/dist/revocation/revocation.js +48 -30
  80. package/dist/revocation/revocation.js.map +1 -1
  81. package/dist/revocation.d.ts +4 -4
  82. package/dist/revocation.js +5 -5
  83. package/dist/verify/identity.d.ts +2 -1
  84. package/dist/verify/identity.js +2 -1
  85. package/dist/verify/identity.js.map +1 -1
  86. package/dist/verify/policy.d.ts +6 -1
  87. package/dist/verify/verify.d.ts +4 -2
  88. package/dist/verify/verify.js +32 -14
  89. package/dist/verify/verify.js.map +1 -1
  90. package/dist/verify.d.ts +2 -1
  91. package/dist/verify.js +4 -3
  92. package/dist/x509/certificate.d.ts +36 -13
  93. package/dist/x509/certificate.js +36 -19
  94. package/dist/x509/certificate.js.map +1 -1
  95. package/dist/x509/csr.d.ts +6 -3
  96. package/dist/x509/extensions.d.ts +58 -21
  97. package/dist/x509/extensions.js +384 -117
  98. package/dist/x509/extensions.js.map +1 -1
  99. package/dist/x509/name-text.js +2 -0
  100. package/dist/x509/name-text.js.map +1 -1
  101. package/dist/x509/name.d.ts +8 -5
  102. package/dist/x509/name.js +17 -12
  103. package/dist/x509/name.js.map +1 -1
  104. package/dist/x509/parse.d.ts +104 -18
  105. package/dist/x509/parse.js +127 -163
  106. package/dist/x509/parse.js.map +1 -1
  107. package/dist/x509.d.ts +8 -5
  108. package/dist/x509.js +10 -8
  109. package/package.json +28 -20
@@ -1,8 +1,8 @@
1
1
  import { implicitPrimitiveContext as e, octetString as t, readRootElement as n, sequence as r } from "../asn1/der.js";
2
2
  import { hexToBytes as i, toHex as a } from "../asn1/asn1.js";
3
3
  import { OIDS as o } from "../asn1/oids2.js";
4
- import { encodeAuthorityInfoAccess as s, encodeBasicConstraints as c, encodeCertificatePolicies as l, encodeCrlDistributionPoints as u, encodeExtendedKeyUsage as d, encodeInhibitAnyPolicy as f, encodeKeyUsage as p, encodeNameConstraints as m, encodePolicyConstraints as h, encodePolicyMappings as g, encodeSubjectAltName as _ } from "../../x509/extensions.js";
5
- import { parseAuthorityInfoAccess as v, parseAuthorityKeyIdentifier as y, parseBasicConstraints as b, parseCertificatePolicies as x, parseCrlDistributionPoints as S, parseExtendedKeyUsage as C, parseInhibitAnyPolicy as w, parseKeyUsage as T, parseNameConstraints as E, parsePolicyConstraints as D, parsePolicyMappings as O, parseSubjectAltNames as k } from "../../x509/parse.js";
4
+ import { assertAuthorityInfoAccessProfile as s, assertCrlDistributionPointsProfile as c, assertExtensionCriticality as l, assertNameConstraintsProfile as u, encodeAuthorityInfoAccess as d, encodeBasicConstraints as f, encodeCertificatePolicies as p, encodeCrlDistributionPoints as m, encodeExtendedKeyUsage as h, encodeInhibitAnyPolicy as g, encodeKeyUsage as _, encodeNameConstraints as v, encodePolicyConstraints as y, encodePolicyMappings as b, encodeSubjectAltName as x } from "../../x509/extensions.js";
5
+ import { parseAuthorityInfoAccess as S, parseAuthorityKeyIdentifier as C, parseBasicConstraints as w, parseCertificatePolicies as T, parseCrlDistributionPoints as E, parseExtendedKeyUsage as D, parseInhibitAnyPolicy as O, parseKeyUsage as k, parseNameConstraints as A, parsePolicyConstraints as j, parsePolicyMappings as M, parseSubjectAltNames as N } from "../../x509/parse.js";
6
6
  //#region src/internal/x509/extension-registry.ts
7
7
  /**
8
8
  * Internal extension registry for certificate and CSR parsing.
@@ -20,130 +20,177 @@ import { parseAuthorityInfoAccess as v, parseAuthorityKeyIdentifier as y, parseB
20
20
  * when the concrete generic type is known, avoiding the correlated-union problem
21
21
  * that would arise from calling `decode` and `applyParsed` through a union type.
22
22
  */
23
- const A = /* @__PURE__ */ new Map(), j = defineExtensionDefinition({
23
+ const P = /* @__PURE__ */ new Map(), F = defineExtensionDefinition({
24
24
  oid: o.basicConstraints,
25
25
  contexts: ["certificate", "csr"],
26
26
  defaultCritical: !0,
27
- decode: (e) => b(e),
28
- encode: (e) => c(e),
27
+ decode: (e) => w(e),
28
+ encode: (e) => f(e),
29
+ assertProfile: (e) => {
30
+ f(e);
31
+ },
29
32
  applyParsed: (e, t) => {
30
33
  e.basicConstraints = t;
31
34
  }
32
- }), M = defineExtensionDefinition({
35
+ }), I = defineExtensionDefinition({
33
36
  oid: o.keyUsage,
34
37
  contexts: ["certificate", "csr"],
35
38
  defaultCritical: !0,
36
- decode: (e) => T(e),
37
- encode: (e) => p(e),
39
+ decode: (e) => k(e),
40
+ encode: (e) => _(e),
41
+ assertProfile: (e) => {
42
+ _(e.flags);
43
+ },
38
44
  applyParsed: (e, t) => {
39
45
  e.keyUsage = t;
40
46
  }
41
- }), N = defineExtensionDefinition({
47
+ }), L = defineExtensionDefinition({
42
48
  oid: o.extendedKeyUsage,
43
49
  contexts: ["certificate", "csr"],
44
50
  defaultCritical: !1,
45
- decode: (e) => C(e),
46
- encode: (e) => d(e),
51
+ decode: (e) => D(e),
52
+ encode: (e) => h(e),
53
+ assertProfile: (e) => {
54
+ h(e);
55
+ },
47
56
  applyParsed: (e, t) => {
48
57
  e.extendedKeyUsage = t;
49
58
  }
50
- }), P = defineExtensionDefinition({
59
+ }), R = defineExtensionDefinition({
51
60
  oid: o.subjectAltName,
52
61
  contexts: ["certificate", "csr"],
53
62
  defaultCritical: !1,
54
- decode: (e) => k(e),
55
- encode: (e) => r(e.map(_)),
63
+ decode: (e) => N(e),
64
+ encode: (e) => r(e.map(x)),
65
+ assertProfile: (e) => {
66
+ for (let t of e) x(t);
67
+ },
56
68
  applyParsed: (e, t) => {
57
69
  e.subjectAltNames = t;
58
70
  }
59
- }), F = defineExtensionDefinition({
71
+ }), z = defineExtensionDefinition({
72
+ oid: o.issuerAltName,
73
+ contexts: ["certificate"],
74
+ defaultCritical: !1,
75
+ decode: (e) => N(e, "issuerAltName"),
76
+ encode: (e) => r(e.map(x)),
77
+ assertProfile: (e) => {
78
+ for (let t of e) x(t);
79
+ },
80
+ applyParsed: (e, t) => {
81
+ e.issuerAltNames = t;
82
+ }
83
+ }), B = defineExtensionDefinition({
60
84
  oid: o.nameConstraints,
61
85
  contexts: ["certificate", "csr"],
62
86
  defaultCritical: !0,
63
- decode: (e) => E(e),
64
- encode: (e) => m(e),
87
+ decode: (e) => A(e),
88
+ encode: (e) => v(e),
89
+ assertProfile: (e, t) => {
90
+ u(e), l("nameConstraints", !0, t);
91
+ },
65
92
  applyParsed: (e, t) => {
66
93
  e.nameConstraints = t;
67
94
  }
68
- }), I = defineExtensionDefinition({
95
+ }), V = defineExtensionDefinition({
69
96
  oid: o.certificatePolicies,
70
97
  contexts: ["certificate", "csr"],
71
98
  defaultCritical: !1,
72
- decode: (e) => x(e),
73
- encode: (e) => l(e),
99
+ decode: (e) => T(e),
100
+ encode: (e) => p(e),
101
+ assertProfile: (e) => {
102
+ p(e);
103
+ },
74
104
  applyParsed: (e, t) => {
75
105
  e.certificatePolicies = t;
76
106
  }
77
- }), L = defineExtensionDefinition({
107
+ }), H = defineExtensionDefinition({
78
108
  oid: o.policyMappings,
79
109
  contexts: ["certificate", "csr"],
80
110
  defaultCritical: !0,
81
- decode: (e) => O(e),
82
- encode: (e) => g(e),
111
+ decode: (e) => M(e),
112
+ encode: (e) => b(e),
113
+ assertProfile: (e) => {
114
+ b(e);
115
+ },
83
116
  applyParsed: (e, t) => {
84
117
  e.policyMappings = t;
85
118
  }
86
- }), R = defineExtensionDefinition({
119
+ }), U = defineExtensionDefinition({
87
120
  oid: o.policyConstraints,
88
121
  contexts: ["certificate", "csr"],
89
122
  defaultCritical: !0,
90
- decode: (e) => D(e),
91
- encode: (e) => h(e),
123
+ decode: (e) => j(e),
124
+ encode: (e) => y(e),
125
+ assertProfile: (e, t) => {
126
+ y(e), l("policyConstraints", !0, t);
127
+ },
92
128
  applyParsed: (e, t) => {
93
129
  e.policyConstraints = t;
94
130
  }
95
- }), z = defineExtensionDefinition({
131
+ }), W = defineExtensionDefinition({
96
132
  oid: o.inhibitAnyPolicy,
97
133
  contexts: ["certificate", "csr"],
98
134
  defaultCritical: !0,
99
- decode: (e) => w(e),
100
- encode: (e) => f(e),
135
+ decode: (e) => O(e),
136
+ encode: (e) => g(e),
137
+ assertProfile: (e, t) => {
138
+ g(e), l("inhibitAnyPolicy", !0, t);
139
+ },
101
140
  applyParsed: (e, t) => {
102
141
  e.inhibitAnyPolicy = t;
103
142
  }
104
- }), B = defineExtensionDefinition({
143
+ }), G = defineExtensionDefinition({
105
144
  oid: o.authorityInfoAccess,
106
145
  contexts: ["certificate", "csr"],
107
146
  defaultCritical: !1,
108
- decode: (e) => v(e),
109
- encode: (e) => s(e),
147
+ decode: (e) => S(e),
148
+ encode: (e) => d(e),
149
+ assertProfile: (e, t) => {
150
+ s(e), l("authorityInfoAccess", !1, t);
151
+ },
110
152
  applyParsed: (e, t) => {
111
153
  e.authorityInfoAccess = t;
112
154
  }
113
- }), V = defineExtensionDefinition({
155
+ }), K = defineExtensionDefinition({
114
156
  oid: o.cRLDistributionPoints,
115
157
  contexts: ["certificate", "csr"],
116
158
  defaultCritical: !1,
117
- decode: (e) => S(e),
118
- encode: (e) => u(e),
159
+ decode: (e) => E(e),
160
+ encode: (e) => m(e),
161
+ assertProfile: (e) => {
162
+ c(e);
163
+ },
119
164
  applyParsed: (e, t) => {
120
165
  e.crlDistributionPoints = t;
121
166
  }
122
- }), H = defineExtensionDefinition({
167
+ }), q = defineExtensionDefinition({
123
168
  oid: o.subjectKeyIdentifier,
124
169
  contexts: ["certificate"],
125
170
  defaultCritical: !1,
126
171
  autoGenerated: !0,
127
172
  decode: (e) => decodeSubjectKeyIdentifier(e),
128
173
  encode: (e) => t(normalizeKeyIdentifier(e)),
174
+ assertProfile: (e, t) => {
175
+ i(e), l("subjectKeyIdentifier", !1, t);
176
+ },
129
177
  applyParsed: (e, t) => {
130
178
  e.subjectKeyIdentifier = t;
131
179
  }
132
- }), U = defineExtensionDefinition({
180
+ }), J = defineExtensionDefinition({
133
181
  oid: o.authorityKeyIdentifier,
134
182
  contexts: ["certificate"],
135
183
  defaultCritical: !1,
136
184
  autoGenerated: !0,
137
- decode: (e) => y(e),
185
+ decode: (e) => C(e),
138
186
  encode: (t) => r([e(0, normalizeKeyIdentifier(t))]),
187
+ assertProfile: (e, t) => {
188
+ e !== void 0 && i(e), l("authorityKeyIdentifier", !1, t);
189
+ },
139
190
  applyParsed: (e, t) => {
140
191
  t !== void 0 && (e.authorityKeyIdentifier = t);
141
192
  }
142
- }), W = [
143
- j,
144
- M,
145
- N,
146
- P,
193
+ }), Y = [
147
194
  F,
148
195
  I,
149
196
  L,
@@ -152,10 +199,15 @@ const A = /* @__PURE__ */ new Map(), j = defineExtensionDefinition({
152
199
  B,
153
200
  V,
154
201
  H,
155
- U
156
- ], G = new Map(W.map((e) => [e.oid, e]));
202
+ U,
203
+ W,
204
+ G,
205
+ K,
206
+ q,
207
+ J
208
+ ], X = new Map(Y.map((e) => [e.oid, e]));
157
209
  function getExtensionDefinition(e) {
158
- return G.get(e);
210
+ return X.get(e);
159
211
  }
160
212
  /**
161
213
  * If `oid` matches a known extension valid in `context`, decode its DER
@@ -166,21 +218,27 @@ function getExtensionDefinition(e) {
166
218
  function decodeAndApplyKnownExtension(e, t, n, r) {
167
219
  let i = getExtensionDefinition(t);
168
220
  if (i === void 0 || !i.contexts.includes(e)) return !1;
169
- let a = A.get(t);
221
+ let a = P.get(t);
170
222
  return a === void 0 ? !1 : (a(n, r), !0);
171
223
  }
172
224
  /**
173
- * Identity helper that narrows the type of an {@linkcode ExtensionDefinition} literal
174
- * and captures a decode-and-apply closure in {@linkcode extensionAppliers}.
225
+ * Register an {@linkcode ExtensionDefinition} literal, capturing its
226
+ * decode-and-apply and decode-and-validate closures.
175
227
  *
176
- * The closure is built here — where `TParsed` is concrete — so that
177
- * `decodeAndApplyKnownExtension` can call it through the union-typed
178
- * `KnownExtensionDefinition` without hitting TypeScript's correlated-union limitation.
228
+ * Both closures are built here, where `TParsed` is concrete, so that
229
+ * `decodeAndApplyKnownExtension` and `assertDerProfile` can be called through the
230
+ * union-typed `KnownExtensionDefinition` without hitting TypeScript's
231
+ * correlated-union limitation.
179
232
  */
180
233
  function defineExtensionDefinition(e) {
181
- return A.set(e.oid, (t, n) => {
234
+ return P.set(e.oid, (t, n) => {
182
235
  e.applyParsed(t, e.decode(n));
183
- }), e;
236
+ }), {
237
+ ...e,
238
+ assertDerProfile: (t, n) => {
239
+ e.assertProfile(e.decode(t), n);
240
+ }
241
+ };
184
242
  }
185
243
  /** Accept hex string or Uint8Array and return raw bytes. */
186
244
  function normalizeKeyIdentifier(e) {
@@ -193,6 +251,6 @@ function decodeSubjectKeyIdentifier(e) {
193
251
  return a(t.value);
194
252
  }
195
253
  //#endregion
196
- export { B as AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION, U as AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION, j as BASIC_CONSTRAINTS_EXTENSION_DEFINITION, I as CERTIFICATE_POLICIES_EXTENSION_DEFINITION, W as CERT_CSR_EXTENSION_DEFINITIONS, V as CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION, N as EXTENDED_KEY_USAGE_EXTENSION_DEFINITION, z as INHIBIT_ANY_POLICY_EXTENSION_DEFINITION, M as KEY_USAGE_EXTENSION_DEFINITION, F as NAME_CONSTRAINTS_EXTENSION_DEFINITION, R as POLICY_CONSTRAINTS_EXTENSION_DEFINITION, L as POLICY_MAPPINGS_EXTENSION_DEFINITION, P as SUBJECT_ALT_NAME_EXTENSION_DEFINITION, H as SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION, decodeAndApplyKnownExtension, getExtensionDefinition };
254
+ export { G as AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION, J as AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION, F as BASIC_CONSTRAINTS_EXTENSION_DEFINITION, V as CERTIFICATE_POLICIES_EXTENSION_DEFINITION, Y as CERT_CSR_EXTENSION_DEFINITIONS, K as CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION, L as EXTENDED_KEY_USAGE_EXTENSION_DEFINITION, W as INHIBIT_ANY_POLICY_EXTENSION_DEFINITION, z as ISSUER_ALT_NAME_EXTENSION_DEFINITION, I as KEY_USAGE_EXTENSION_DEFINITION, B as NAME_CONSTRAINTS_EXTENSION_DEFINITION, U as POLICY_CONSTRAINTS_EXTENSION_DEFINITION, H as POLICY_MAPPINGS_EXTENSION_DEFINITION, R as SUBJECT_ALT_NAME_EXTENSION_DEFINITION, q as SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION, decodeAndApplyKnownExtension, getExtensionDefinition };
197
255
 
198
256
  //# sourceMappingURL=extension-registry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extension-registry.js","names":[],"sources":["../../../src/internal/x509/extension-registry.ts"],"sourcesContent":["/**\n * Internal extension registry for certificate and CSR parsing.\n *\n * Maps each supported extension OID to a definition that can decode DER,\n * encode input, and apply parsed values to the accumulator used during\n * certificate/CSR parsing.\n *\n * @module\n */\n\nimport { hexToBytes, toHex } from '#micro509/internal/asn1/asn1';\nimport {\n\tDEFAULT_MAX_DER_DEPTH,\n\timplicitPrimitiveContext,\n\toctetString,\n\treadRootElement,\n\tsequence,\n} from '#micro509/internal/asn1/der';\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport type { ParsedBitFlags } from '#micro509/internal/x509/extension-bits';\nimport type {\n\tAuthorityInformationAccess,\n\tBasicConstraints,\n\tCertificatePolicies,\n\tDistributionPoint,\n\tExtendedKeyUsage,\n\tInhibitAnyPolicy,\n\tKeyUsage,\n\tNameConstraints,\n\tParsedNameConstraintForm,\n\tPolicyConstraints,\n\tPolicyMappings,\n\tSubjectAltName,\n} from '#micro509/x509/extensions';\nimport {\n\tbuildSubjectKeyIdentifier,\n\tencodeAuthorityInfoAccess,\n\tencodeBasicConstraints,\n\tencodeCertificatePolicies,\n\tencodeCrlDistributionPoints,\n\tencodeExtendedKeyUsage,\n\tencodeInhibitAnyPolicy,\n\tencodeKeyUsage,\n\tencodeNameConstraints,\n\tencodePolicyConstraints,\n\tencodePolicyMappings,\n\tencodeSubjectAltName,\n} from '#micro509/x509/extensions';\nimport type { ParsedDistributionPoint } from '#micro509/x509/parse';\nimport {\n\tparseAuthorityInfoAccess,\n\tparseAuthorityKeyIdentifier,\n\tparseBasicConstraints,\n\tparseCertificatePolicies,\n\tparseCrlDistributionPoints,\n\tparseExtendedKeyUsage,\n\tparseInhibitAnyPolicy,\n\tparseKeyUsage,\n\tparseNameConstraints,\n\tparsePolicyConstraints,\n\tparsePolicyMappings,\n\tparseSubjectAltNames,\n} from '#micro509/x509/parse';\n\n/** Whether an extension applies to certificate parsing, CSR parsing, or both. */\nexport type ExtensionRegistryContext = 'certificate' | 'csr';\n\n/**\n * Readonly snapshot of decoded known extensions collected during parsing.\n *\n * Fields mirror the extension slots on {@linkcode ParsedCertificate}.\n */\nexport interface KnownParsedExtensionAccumulator {\n\t/** Basic Constraints (CA flag + optional pathLength). */\n\treadonly basicConstraints?: BasicConstraints;\n\t/** Key Usage flags (digitalSignature, keyCertSign, etc.). */\n\treadonly keyUsage?: ParsedBitFlags<KeyUsage>;\n\t/** Extended Key Usage purposes (serverAuth, clientAuth, etc.). */\n\treadonly extendedKeyUsage?: readonly ExtendedKeyUsage[];\n\t/** Subject Alternative Names (dns, ip, email, uri, srv, directoryName). */\n\treadonly subjectAltNames?: readonly SubjectAltName[];\n\t/** Name Constraints (permitted/excluded subtrees). */\n\treadonly nameConstraints?: NameConstraints<ParsedNameConstraintForm>;\n\t/** Certificate Policies extension values. */\n\treadonly certificatePolicies?: CertificatePolicies;\n\t/** Policy Mappings from issuer to subject policy domains. */\n\treadonly policyMappings?: PolicyMappings;\n\t/** Policy Constraints (requireExplicitPolicy / inhibitPolicyMapping). */\n\treadonly policyConstraints?: PolicyConstraints;\n\t/** Inhibit Any-Policy skip-certs value. */\n\treadonly inhibitAnyPolicy?: InhibitAnyPolicy;\n\t/** Authority Information Access (OCSP, CA issuers). */\n\treadonly authorityInfoAccess?: readonly AuthorityInformationAccess[];\n\t/** CRL Distribution Points. */\n\treadonly crlDistributionPoints?: readonly ParsedDistributionPoint[];\n\t/** Hex-encoded Subject Key Identifier. */\n\treadonly subjectKeyIdentifier?: string;\n\t/** Hex-encoded Authority Key Identifier. */\n\treadonly authorityKeyIdentifier?: string;\n}\n\n/**\n * Mutable version of {@linkcode KnownParsedExtensionAccumulator} used during\n * extension parsing to progressively fill in decoded values.\n */\nexport type MutableKnownParsedExtensionAccumulator = {\n\t-readonly [Key in keyof KnownParsedExtensionAccumulator]: KnownParsedExtensionAccumulator[Key];\n};\n\n/**\n * Full lifecycle definition for a known X.509 extension: decode, encode,\n * and apply-to-accumulator during parsing.\n *\n * `TParsed` is the type produced when decoding DER; `TInput` is the type\n * accepted when encoding (they may differ, e.g. for NameConstraints).\n */\nexport interface ExtensionDefinition<TParsed, TInput = TParsed> {\n\t/** Dotted-decimal OID of the extension. */\n\treadonly oid: string;\n\t/** Contexts where this extension is valid (`'certificate'`, `'csr'`, or both). */\n\treadonly contexts: readonly ExtensionRegistryContext[];\n\t/** Whether the extension is marked critical by default when encoding. */\n\treadonly defaultCritical: boolean;\n\t/** When true, the extension is computed by the builder (e.g. SKI, AKI) rather than user-supplied. */\n\treadonly autoGenerated?: boolean;\n\t/** Decode the extension's DER extnValue into a typed value. */\n\tdecode(valueDer: Uint8Array): TParsed;\n\t/** Encode a typed input into the extension's DER extnValue. */\n\tencode(value: TInput): Uint8Array;\n\t/** Store a decoded value into the parse-time accumulator. */\n\tapplyParsed(accumulator: MutableKnownParsedExtensionAccumulator, value: TParsed): void;\n}\n\n/**\n * Module-internal decode-and-apply closures, captured at definition time.\n *\n * Each entry is keyed by OID and populated by {@linkcode defineExtensionDefinition}\n * when the concrete generic type is known, avoiding the correlated-union problem\n * that would arise from calling `decode` and `applyParsed` through a union type.\n */\nconst extensionAppliers = new Map<\n\tstring,\n\t(accumulator: MutableKnownParsedExtensionAccumulator, valueDer: Uint8Array) => void\n>();\n\n/** Registry entry for Basic Constraints (OID 2.5.29.19). Critical by default. */\nexport const BASIC_CONSTRAINTS_EXTENSION_DEFINITION: ExtensionDefinition<BasicConstraints> =\n\tdefineExtensionDefinition<BasicConstraints>({\n\t\toid: OIDS.basicConstraints,\n\t\tcontexts: ['certificate', 'csr'],\n\t\tdefaultCritical: true,\n\t\tdecode: (valueDer) => parseBasicConstraints(valueDer),\n\t\tencode: (value) => encodeBasicConstraints(value),\n\t\tapplyParsed: (accumulator, value) => {\n\t\t\taccumulator.basicConstraints = value;\n\t\t},\n\t});\n\n/** Registry entry for Key Usage (OID 2.5.29.15). Critical by default. */\nexport const KEY_USAGE_EXTENSION_DEFINITION: ExtensionDefinition<\n\tParsedBitFlags<KeyUsage>,\n\treadonly KeyUsage[]\n> = defineExtensionDefinition<ParsedBitFlags<KeyUsage>, readonly KeyUsage[]>({\n\toid: OIDS.keyUsage,\n\tcontexts: ['certificate', 'csr'],\n\tdefaultCritical: true,\n\tdecode: (valueDer) => parseKeyUsage(valueDer),\n\tencode: (value) => encodeKeyUsage(value),\n\tapplyParsed: (accumulator, value) => {\n\t\taccumulator.keyUsage = value;\n\t},\n});\n\n/** Registry entry for Extended Key Usage (OID 2.5.29.37). Non-critical by default. */\nexport const EXTENDED_KEY_USAGE_EXTENSION_DEFINITION: ExtensionDefinition<\n\treadonly ExtendedKeyUsage[]\n> = defineExtensionDefinition<readonly ExtendedKeyUsage[]>({\n\toid: OIDS.extendedKeyUsage,\n\tcontexts: ['certificate', 'csr'],\n\tdefaultCritical: false,\n\tdecode: (valueDer) => parseExtendedKeyUsage(valueDer),\n\tencode: (value) => encodeExtendedKeyUsage(value),\n\tapplyParsed: (accumulator, value) => {\n\t\taccumulator.extendedKeyUsage = value;\n\t},\n});\n\n/** Registry entry for Subject Alternative Name (OID 2.5.29.17). Non-critical by default. */\nexport const SUBJECT_ALT_NAME_EXTENSION_DEFINITION: ExtensionDefinition<readonly SubjectAltName[]> =\n\tdefineExtensionDefinition<readonly SubjectAltName[]>({\n\t\toid: OIDS.subjectAltName,\n\t\tcontexts: ['certificate', 'csr'],\n\t\tdefaultCritical: false,\n\t\tdecode: (valueDer) => parseSubjectAltNames(valueDer),\n\t\tencode: (value) => sequence(value.map(encodeSubjectAltName)),\n\t\tapplyParsed: (accumulator, value) => {\n\t\t\taccumulator.subjectAltNames = value;\n\t\t},\n\t});\n\n/** Registry entry for Name Constraints (OID 2.5.29.30). Critical by default. */\nexport const NAME_CONSTRAINTS_EXTENSION_DEFINITION: ExtensionDefinition<\n\tNameConstraints<ParsedNameConstraintForm>,\n\tNameConstraints\n> = defineExtensionDefinition<NameConstraints<ParsedNameConstraintForm>, NameConstraints>({\n\toid: OIDS.nameConstraints,\n\tcontexts: ['certificate', 'csr'],\n\tdefaultCritical: true,\n\tdecode: (valueDer) => parseNameConstraints(valueDer),\n\tencode: (value) => encodeNameConstraints(value),\n\tapplyParsed: (accumulator, value) => {\n\t\taccumulator.nameConstraints = value;\n\t},\n});\n\n/** Registry entry for Certificate Policies (OID 2.5.29.32). Non-critical by default. */\nexport const CERTIFICATE_POLICIES_EXTENSION_DEFINITION: ExtensionDefinition<CertificatePolicies> =\n\tdefineExtensionDefinition<CertificatePolicies>({\n\t\toid: OIDS.certificatePolicies,\n\t\tcontexts: ['certificate', 'csr'],\n\t\tdefaultCritical: false,\n\t\tdecode: (valueDer) => parseCertificatePolicies(valueDer),\n\t\tencode: (value) => encodeCertificatePolicies(value),\n\t\tapplyParsed: (accumulator, value) => {\n\t\t\taccumulator.certificatePolicies = value;\n\t\t},\n\t});\n\n/** Registry entry for Policy Mappings (OID 2.5.29.33). Critical by default. */\nexport const POLICY_MAPPINGS_EXTENSION_DEFINITION: ExtensionDefinition<PolicyMappings> =\n\tdefineExtensionDefinition<PolicyMappings>({\n\t\toid: OIDS.policyMappings,\n\t\tcontexts: ['certificate', 'csr'],\n\t\tdefaultCritical: true,\n\t\tdecode: (valueDer) => parsePolicyMappings(valueDer),\n\t\tencode: (value) => encodePolicyMappings(value),\n\t\tapplyParsed: (accumulator, value) => {\n\t\t\taccumulator.policyMappings = value;\n\t\t},\n\t});\n\n/** Registry entry for Policy Constraints (OID 2.5.29.36). Critical by default. */\nexport const POLICY_CONSTRAINTS_EXTENSION_DEFINITION: ExtensionDefinition<PolicyConstraints> =\n\tdefineExtensionDefinition<PolicyConstraints>({\n\t\toid: OIDS.policyConstraints,\n\t\tcontexts: ['certificate', 'csr'],\n\t\tdefaultCritical: true,\n\t\tdecode: (valueDer) => parsePolicyConstraints(valueDer),\n\t\tencode: (value) => encodePolicyConstraints(value),\n\t\tapplyParsed: (accumulator, value) => {\n\t\t\taccumulator.policyConstraints = value;\n\t\t},\n\t});\n\n/** Registry entry for Inhibit anyPolicy (OID 2.5.29.54). Critical by default. */\nexport const INHIBIT_ANY_POLICY_EXTENSION_DEFINITION: ExtensionDefinition<InhibitAnyPolicy> =\n\tdefineExtensionDefinition<InhibitAnyPolicy>({\n\t\toid: OIDS.inhibitAnyPolicy,\n\t\tcontexts: ['certificate', 'csr'],\n\t\tdefaultCritical: true,\n\t\tdecode: (valueDer) => parseInhibitAnyPolicy(valueDer),\n\t\tencode: (value) => encodeInhibitAnyPolicy(value),\n\t\tapplyParsed: (accumulator, value) => {\n\t\t\taccumulator.inhibitAnyPolicy = value;\n\t\t},\n\t});\n\n/** Registry entry for Authority Information Access (OID 1.3.6.1.5.5.7.1.1). Non-critical. */\nexport const AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION: ExtensionDefinition<\n\treadonly AuthorityInformationAccess[]\n> = defineExtensionDefinition<readonly AuthorityInformationAccess[]>({\n\toid: OIDS.authorityInfoAccess,\n\tcontexts: ['certificate', 'csr'],\n\tdefaultCritical: false,\n\tdecode: (valueDer) => parseAuthorityInfoAccess(valueDer),\n\tencode: (value) => encodeAuthorityInfoAccess(value),\n\tapplyParsed: (accumulator, value) => {\n\t\taccumulator.authorityInfoAccess = value;\n\t},\n});\n\n/** Registry entry for CRL Distribution Points (OID 2.5.29.31). Non-critical by default. */\nexport const CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION: ExtensionDefinition<\n\treadonly ParsedDistributionPoint[],\n\treadonly DistributionPoint[]\n> = defineExtensionDefinition<readonly ParsedDistributionPoint[], readonly DistributionPoint[]>({\n\toid: OIDS.cRLDistributionPoints,\n\tcontexts: ['certificate', 'csr'],\n\tdefaultCritical: false,\n\tdecode: (valueDer) => parseCrlDistributionPoints(valueDer),\n\tencode: (value) => encodeCrlDistributionPoints(value),\n\tapplyParsed: (accumulator, value) => {\n\t\taccumulator.crlDistributionPoints = value;\n\t},\n});\n\n/** Registry entry for Subject Key Identifier (OID 2.5.29.14). Auto-generated; non-critical. */\nexport const SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION: ExtensionDefinition<\n\tstring,\n\tstring | Uint8Array\n> = defineExtensionDefinition<string, string | Uint8Array>({\n\toid: OIDS.subjectKeyIdentifier,\n\tcontexts: ['certificate'],\n\tdefaultCritical: false,\n\tautoGenerated: true,\n\tdecode: (valueDer) => decodeSubjectKeyIdentifier(valueDer),\n\tencode: (value) => octetString(normalizeKeyIdentifier(value)),\n\tapplyParsed: (accumulator, value) => {\n\t\taccumulator.subjectKeyIdentifier = value;\n\t},\n});\n\n/** Registry entry for Authority Key Identifier (OID 2.5.29.35). Auto-generated; non-critical. */\nexport const AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION: ExtensionDefinition<\n\tstring | undefined,\n\tstring | Uint8Array\n> = defineExtensionDefinition<string | undefined, string | Uint8Array>({\n\toid: OIDS.authorityKeyIdentifier,\n\tcontexts: ['certificate'],\n\tdefaultCritical: false,\n\tautoGenerated: true,\n\tdecode: (valueDer) => parseAuthorityKeyIdentifier(valueDer),\n\tencode: (value) => sequence([implicitPrimitiveContext(0, normalizeKeyIdentifier(value))]),\n\tapplyParsed: (accumulator, value) => {\n\t\tif (value !== undefined) {\n\t\t\taccumulator.authorityKeyIdentifier = value;\n\t\t}\n\t},\n});\n\n/** Union of all built-in extension definition constants. */\nexport type KnownExtensionDefinition =\n\t| typeof BASIC_CONSTRAINTS_EXTENSION_DEFINITION\n\t| typeof KEY_USAGE_EXTENSION_DEFINITION\n\t| typeof EXTENDED_KEY_USAGE_EXTENSION_DEFINITION\n\t| typeof SUBJECT_ALT_NAME_EXTENSION_DEFINITION\n\t| typeof NAME_CONSTRAINTS_EXTENSION_DEFINITION\n\t| typeof CERTIFICATE_POLICIES_EXTENSION_DEFINITION\n\t| typeof POLICY_MAPPINGS_EXTENSION_DEFINITION\n\t| typeof POLICY_CONSTRAINTS_EXTENSION_DEFINITION\n\t| typeof INHIBIT_ANY_POLICY_EXTENSION_DEFINITION\n\t| typeof AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION\n\t| typeof CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION\n\t| typeof SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION\n\t| typeof AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION;\n\n/** All built-in extension definitions, in registration order. */\nexport const CERT_CSR_EXTENSION_DEFINITIONS: readonly KnownExtensionDefinition[] = [\n\tBASIC_CONSTRAINTS_EXTENSION_DEFINITION,\n\tKEY_USAGE_EXTENSION_DEFINITION,\n\tEXTENDED_KEY_USAGE_EXTENSION_DEFINITION,\n\tSUBJECT_ALT_NAME_EXTENSION_DEFINITION,\n\tNAME_CONSTRAINTS_EXTENSION_DEFINITION,\n\tCERTIFICATE_POLICIES_EXTENSION_DEFINITION,\n\tPOLICY_MAPPINGS_EXTENSION_DEFINITION,\n\tPOLICY_CONSTRAINTS_EXTENSION_DEFINITION,\n\tINHIBIT_ANY_POLICY_EXTENSION_DEFINITION,\n\tAUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION,\n\tCRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION,\n\tSUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n\tAUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n];\n\n/** OID-keyed lookup for known extension definitions. */\nconst EXTENSION_DEFINITION_MAP = new Map<string, KnownExtensionDefinition>(\n\tCERT_CSR_EXTENSION_DEFINITIONS.map((definition) => [definition.oid, definition]),\n);\n\n/**\n * Return all known extension definitions, optionally filtered by context.\n *\n * @param context If provided, only definitions valid in that context are returned.\n */\nexport function listExtensionDefinitions(\n\tcontext?: ExtensionRegistryContext,\n): readonly KnownExtensionDefinition[] {\n\tif (context === undefined) {\n\t\treturn CERT_CSR_EXTENSION_DEFINITIONS;\n\t}\n\treturn CERT_CSR_EXTENSION_DEFINITIONS.filter((definition) =>\n\t\tdefinition.contexts.includes(context),\n\t);\n}\n\n/**\n * Look up a known extension definition by OID.\n *\n * Overloaded for each built-in OID constant to return the exact definition type;\n * the generic `string` form returns the union or `undefined`.\n *\n * @param oid Dotted-decimal extension OID.\n * @returns The matching definition, or `undefined` for unrecognized OIDs.\n */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.basicConstraints,\n): typeof BASIC_CONSTRAINTS_EXTENSION_DEFINITION;\n/** Exact definition for the Key Usage extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.keyUsage,\n): typeof KEY_USAGE_EXTENSION_DEFINITION;\n/** Exact definition for the Extended Key Usage extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.extendedKeyUsage,\n): typeof EXTENDED_KEY_USAGE_EXTENSION_DEFINITION;\n/** Exact definition for the Subject Alternative Name extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.subjectAltName,\n): typeof SUBJECT_ALT_NAME_EXTENSION_DEFINITION;\n/** Exact definition for the Name Constraints extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.nameConstraints,\n): typeof NAME_CONSTRAINTS_EXTENSION_DEFINITION;\n/** Exact definition for the Certificate Policies extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.certificatePolicies,\n): typeof CERTIFICATE_POLICIES_EXTENSION_DEFINITION;\n/** Exact definition for the Policy Mappings extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.policyMappings,\n): typeof POLICY_MAPPINGS_EXTENSION_DEFINITION;\n/** Exact definition for the Policy Constraints extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.policyConstraints,\n): typeof POLICY_CONSTRAINTS_EXTENSION_DEFINITION;\n/** Exact definition for the Inhibit Any-Policy extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.inhibitAnyPolicy,\n): typeof INHIBIT_ANY_POLICY_EXTENSION_DEFINITION;\n/** Exact definition for the Authority Information Access extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.authorityInfoAccess,\n): typeof AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION;\n/** Exact definition for the CRL Distribution Points extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.cRLDistributionPoints,\n): typeof CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION;\n/** Exact definition for the Subject Key Identifier extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.subjectKeyIdentifier,\n): typeof SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION;\n/** Exact definition for the Authority Key Identifier extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.authorityKeyIdentifier,\n): typeof AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION;\n/** Generic lookup: returns the matching definition, or `undefined` for unrecognized OIDs. */\nexport function getExtensionDefinition(oid: string): KnownExtensionDefinition | undefined;\nexport function getExtensionDefinition(oid: string): KnownExtensionDefinition | undefined {\n\treturn EXTENSION_DEFINITION_MAP.get(oid);\n}\n\n/**\n * If `oid` matches a known extension valid in `context`, decode its DER\n * value and store the result in the accumulator.\n *\n * @returns `true` if the extension was recognized and applied.\n */\nexport function decodeAndApplyKnownExtension(\n\tcontext: ExtensionRegistryContext,\n\toid: string,\n\taccumulator: MutableKnownParsedExtensionAccumulator,\n\tvalueDer: Uint8Array,\n): boolean {\n\tconst definition = getExtensionDefinition(oid);\n\tif (definition === undefined || !definition.contexts.includes(context)) {\n\t\treturn false;\n\t}\n\tconst applier = extensionAppliers.get(oid);\n\tif (applier === undefined) {\n\t\treturn false;\n\t}\n\tapplier(accumulator, valueDer);\n\treturn true;\n}\n\n/**\n * Compute a Subject Key Identifier (SHA-1 of the public key bits) from\n * a DER-encoded SubjectPublicKeyInfo.\n */\nexport function buildSubjectKeyIdentifierFromSubjectPublicKeyInfo(\n\tsubjectPublicKeyInfo: Uint8Array,\n): Uint8Array {\n\treturn buildSubjectKeyIdentifier(subjectPublicKeyInfo);\n}\n\n/**\n * Identity helper that narrows the type of an {@linkcode ExtensionDefinition} literal\n * and captures a decode-and-apply closure in {@linkcode extensionAppliers}.\n *\n * The closure is built here — where `TParsed` is concrete — so that\n * `decodeAndApplyKnownExtension` can call it through the union-typed\n * `KnownExtensionDefinition` without hitting TypeScript's correlated-union limitation.\n */\nfunction defineExtensionDefinition<TParsed, TInput = TParsed>(\n\tdefinition: ExtensionDefinition<TParsed, TInput>,\n): ExtensionDefinition<TParsed, TInput> {\n\textensionAppliers.set(definition.oid, (accumulator, valueDer) => {\n\t\tdefinition.applyParsed(accumulator, definition.decode(valueDer));\n\t});\n\treturn definition;\n}\n\n/** Accept hex string or Uint8Array and return raw bytes. */\nfunction normalizeKeyIdentifier(value: string | Uint8Array): Uint8Array {\n\treturn typeof value === 'string' ? hexToBytes(value) : value;\n}\n\n/** Decode an SKI extension value DER to a hex string. */\nfunction decodeSubjectKeyIdentifier(valueDer: Uint8Array): string {\n\tconst element = readRootElement(valueDer, { maxDepth: DEFAULT_MAX_DER_DEPTH });\n\tif (element.tag !== 0x04) {\n\t\tthrow new Error('SubjectKeyIdentifier must be an OCTET STRING');\n\t}\n\treturn toHex(element.value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA4IA,MAAM,oBAAoB,IAAI,IAG5B,GAGW,IACZ,0BAA4C;CAC3C,KAAK,EAAK;CACV,UAAU,CAAC,eAAe,KAAK;CAC/B,iBAAiB;CACjB,SAAS,MAAa,EAAsB,CAAQ;CACpD,SAAS,MAAU,EAAuB,CAAK;CAC/C,cAAc,GAAa,MAAU;EACpC,EAAY,mB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a,EAA4B,CAAQ;CAC1D,SAAS,MAAU,EAAS,CAAC,EAAyB,GAAG,uBAAuB,CAAK,CAAC,CAAC,CAAC;CACxF,cAAc,GAAa,MAAU;EACpC,AAAI,MAAU,KAAA,MACb,EAAY,yBAAyB;CAEvC;AACD,CAAC,GAmBY,IAAsE;CAClF;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,GAGM,IAA2B,IAAI,IACpC,EAA+B,KAAK,MAAe,CAAC,EAAW,KAAK,CAAU,CAAC,CAChF;AAgFA,SAAgB,uBAAuB,GAAmD;CACzF,OAAO,EAAyB,IAAI,CAAG;AACxC;;;;;;;AAQA,SAAgB,6BACf,GACA,GACA,GACA,GACU;CACV,IAAM,IAAa,uBAAuB,CAAG;CAC7C,IAAI,MAAe,KAAA,KAAa,CAAC,EAAW,SAAS,SAAS,CAAO,GACpE,OAAO;CAER,IAAM,IAAU,EAAkB,IAAI,CAAG;CAKzC,OAJI,MAAY,KAAA,IACR,MAER,EAAQ,GAAa,CAAQ,GACtB;AACR;;;;;;;;;AAoBA,SAAS,0BACR,GACuC;CAIvC,OAHA,EAAkB,IAAI,EAAW,MAAM,GAAa,MAAa;EAChE,EAAW,YAAY,GAAa,EAAW,OAAO,CAAQ,CAAC;CAChE,CAAC,GACM;AACR;;AAGA,SAAS,uBAAuB,GAAwC;CACvE,OAAO,OAAO,KAAU,WAAW,EAAW,CAAK,IAAI;AACxD;;AAGA,SAAS,2BAA2B,GAA8B;CACjE,IAAM,IAAU,EAAgB,GAAU,EAAE,UAAA,GAAgC,CAAC;CAC7E,IAAI,EAAQ,QAAQ,GACnB,MAAU,MAAM,8CAA8C;CAE/D,OAAO,EAAM,EAAQ,KAAK;AAC3B"}
1
+ {"version":3,"file":"extension-registry.js","names":[],"sources":["../../../src/internal/x509/extension-registry.ts"],"sourcesContent":["/**\n * Internal extension registry for certificate and CSR parsing.\n *\n * Maps each supported extension OID to a definition that can decode DER,\n * encode input, and apply parsed values to the accumulator used during\n * certificate/CSR parsing.\n *\n * @module\n */\n\nimport { hexToBytes, toHex } from '#micro509/internal/asn1/asn1';\nimport {\n\tDEFAULT_MAX_DER_DEPTH,\n\timplicitPrimitiveContext,\n\toctetString,\n\treadRootElement,\n\tsequence,\n} from '#micro509/internal/asn1/der';\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport type { ParsedBitFlags } from '#micro509/internal/x509/extension-bits';\nimport type {\n\tAuthorityInformationAccess,\n\tAuthorityInformationAccessInput,\n\tBasicConstraints,\n\tCertificatePolicies,\n\tDistributionPoint,\n\tExtendedKeyUsage,\n\tInhibitAnyPolicy,\n\tKeyUsage,\n\tNameConstraints,\n\tParsedNameConstraintForm,\n\tPolicyConstraints,\n\tPolicyMappings,\n\tSubjectAltName,\n} from '#micro509/x509/extensions';\nimport {\n\tassertAuthorityInfoAccessProfile,\n\tassertCrlDistributionPointsProfile,\n\tassertExtensionCriticality,\n\tassertNameConstraintsProfile,\n\tbuildSubjectKeyIdentifier,\n\tencodeAuthorityInfoAccess,\n\tencodeBasicConstraints,\n\tencodeCertificatePolicies,\n\tencodeCrlDistributionPoints,\n\tencodeExtendedKeyUsage,\n\tencodeInhibitAnyPolicy,\n\tencodeKeyUsage,\n\tencodeNameConstraints,\n\tencodePolicyConstraints,\n\tencodePolicyMappings,\n\tencodeSubjectAltName,\n} from '#micro509/x509/extensions';\nimport type { ParsedDistributionPoint } from '#micro509/x509/parse';\nimport {\n\tparseAuthorityInfoAccess,\n\tparseAuthorityKeyIdentifier,\n\tparseBasicConstraints,\n\tparseCertificatePolicies,\n\tparseCrlDistributionPoints,\n\tparseExtendedKeyUsage,\n\tparseInhibitAnyPolicy,\n\tparseKeyUsage,\n\tparseNameConstraints,\n\tparsePolicyConstraints,\n\tparsePolicyMappings,\n\tparseSubjectAltNames,\n} from '#micro509/x509/parse';\n\n/** Whether an extension applies to certificate parsing, CSR parsing, or both. */\nexport type ExtensionRegistryContext = 'certificate' | 'csr';\n\n/**\n * Readonly snapshot of decoded known extensions collected during parsing.\n *\n * Fields mirror the extension slots on {@linkcode ParsedCertificate}.\n */\nexport interface KnownParsedExtensionAccumulator {\n\t/** Basic Constraints (CA flag + optional pathLength). */\n\treadonly basicConstraints?: BasicConstraints;\n\t/** Key Usage flags (digitalSignature, keyCertSign, etc.). */\n\treadonly keyUsage?: ParsedBitFlags<KeyUsage>;\n\t/** Extended Key Usage purposes (serverAuth, clientAuth, etc.). */\n\treadonly extendedKeyUsage?: readonly ExtendedKeyUsage[];\n\t/** Subject Alternative Names (dns, ip, email, uri, srv, directoryName). */\n\treadonly subjectAltNames?: readonly SubjectAltName[];\n\t/** Issuer Alternative Names (RFC 5280 §4.2.1.7, same GeneralNames syntax). */\n\treadonly issuerAltNames?: readonly SubjectAltName[];\n\t/** Name Constraints (permitted/excluded subtrees). */\n\treadonly nameConstraints?: NameConstraints<ParsedNameConstraintForm>;\n\t/** Certificate Policies extension values. */\n\treadonly certificatePolicies?: CertificatePolicies;\n\t/** Policy Mappings from issuer to subject policy domains. */\n\treadonly policyMappings?: PolicyMappings;\n\t/** Policy Constraints (requireExplicitPolicy / inhibitPolicyMapping). */\n\treadonly policyConstraints?: PolicyConstraints;\n\t/** Inhibit Any-Policy skip-certs value. */\n\treadonly inhibitAnyPolicy?: InhibitAnyPolicy;\n\t/** Authority Information Access (OCSP, CA issuers). */\n\treadonly authorityInfoAccess?: readonly AuthorityInformationAccess[];\n\t/** CRL Distribution Points. */\n\treadonly crlDistributionPoints?: readonly ParsedDistributionPoint[];\n\t/** Hex-encoded Subject Key Identifier. */\n\treadonly subjectKeyIdentifier?: string;\n\t/** Hex-encoded Authority Key Identifier. */\n\treadonly authorityKeyIdentifier?: string;\n}\n\n/**\n * Mutable version of {@linkcode KnownParsedExtensionAccumulator} used during\n * extension parsing to progressively fill in decoded values.\n */\nexport type MutableKnownParsedExtensionAccumulator = {\n\t-readonly [Key in keyof KnownParsedExtensionAccumulator]: KnownParsedExtensionAccumulator[Key];\n};\n\n/**\n * Full lifecycle definition for a known X.509 extension: decode, encode,\n * and apply-to-accumulator during parsing.\n *\n * `TParsed` is the type produced when decoding DER; `TInput` is the type\n * accepted when encoding (they may differ, e.g. for NameConstraints).\n */\nexport interface ExtensionDefinition<TParsed, TInput = TParsed> {\n\t/** Dotted-decimal OID of the extension. */\n\treadonly oid: string;\n\t/** Contexts where this extension is valid (`'certificate'`, `'csr'`, or both). */\n\treadonly contexts: readonly ExtensionRegistryContext[];\n\t/** Whether the extension is marked critical by default when encoding. */\n\treadonly defaultCritical: boolean;\n\t/** When true, the extension is computed by the builder (e.g. SKI, AKI) rather than user-supplied. */\n\treadonly autoGenerated?: boolean;\n\t/** Decode the extension's DER extnValue into a typed value. */\n\tdecode(valueDer: Uint8Array): TParsed;\n\t/** Encode a typed input into the extension's DER extnValue. */\n\tencode(value: TInput): Uint8Array;\n\t/**\n\t * Apply the RFC 5280 profile rules this extension's encoder enforces to an\n\t * already-decoded value, throwing a coded encoder error on violation.\n\t *\n\t * Decoding proves a payload's structure; it does not prove the payload obeys\n\t * the profile, because the parser is deliberately tolerant. Builders route a\n\t * `customExtensions` payload carrying a known OID through here so a raw value\n\t * meets the same bar as the typed input for that extension. Implementations\n\t * delegate to the encoder that owns the rule so the two cannot drift.\n\t *\n\t * Parsing never calls this.\n\t */\n\tassertProfile(value: TParsed, critical: boolean): void;\n\t/** Store a decoded value into the parse-time accumulator. */\n\tapplyParsed(accumulator: MutableKnownParsedExtensionAccumulator, value: TParsed): void;\n}\n\n/**\n * An {@linkcode ExtensionDefinition} after registration, carrying the\n * decode-then-validate closure captured when `TParsed` was concrete.\n */\nexport type RegisteredExtensionDefinition<TParsed, TInput = TParsed> = ExtensionDefinition<\n\tTParsed,\n\tTInput\n> & {\n\t/** Decode a DER extnValue and apply this extension's profile rules to it. */\n\tassertDerProfile(valueDer: Uint8Array, critical: boolean): void;\n};\n\n/**\n * Module-internal decode-and-apply closures, captured at definition time.\n *\n * Each entry is keyed by OID and populated by {@linkcode defineExtensionDefinition}\n * when the concrete generic type is known, avoiding the correlated-union problem\n * that would arise from calling `decode` and `applyParsed` through a union type.\n */\nconst extensionAppliers = new Map<\n\tstring,\n\t(accumulator: MutableKnownParsedExtensionAccumulator, valueDer: Uint8Array) => void\n>();\n\n/** Registry entry for Basic Constraints (OID 2.5.29.19). Critical by default. */\nexport const BASIC_CONSTRAINTS_EXTENSION_DEFINITION: RegisteredExtensionDefinition<BasicConstraints> =\n\tdefineExtensionDefinition<BasicConstraints>({\n\t\toid: OIDS.basicConstraints,\n\t\tcontexts: ['certificate', 'csr'],\n\t\tdefaultCritical: true,\n\t\tdecode: (valueDer) => parseBasicConstraints(valueDer),\n\t\tencode: (value) => encodeBasicConstraints(value),\n\t\tassertProfile: (value) => {\n\t\t\tencodeBasicConstraints(value);\n\t\t},\n\t\tapplyParsed: (accumulator, value) => {\n\t\t\taccumulator.basicConstraints = value;\n\t\t},\n\t});\n\n/** Registry entry for Key Usage (OID 2.5.29.15). Critical by default. */\nexport const KEY_USAGE_EXTENSION_DEFINITION: RegisteredExtensionDefinition<\n\tParsedBitFlags<KeyUsage>,\n\treadonly KeyUsage[]\n> = defineExtensionDefinition<ParsedBitFlags<KeyUsage>, readonly KeyUsage[]>({\n\toid: OIDS.keyUsage,\n\tcontexts: ['certificate', 'csr'],\n\tdefaultCritical: true,\n\tdecode: (valueDer) => parseKeyUsage(valueDer),\n\tencode: (value) => encodeKeyUsage(value),\n\tassertProfile: (value) => {\n\t\tencodeKeyUsage(value.flags);\n\t},\n\tapplyParsed: (accumulator, value) => {\n\t\taccumulator.keyUsage = value;\n\t},\n});\n\n/** Registry entry for Extended Key Usage (OID 2.5.29.37). Non-critical by default. */\nexport const EXTENDED_KEY_USAGE_EXTENSION_DEFINITION: RegisteredExtensionDefinition<\n\treadonly ExtendedKeyUsage[]\n> = defineExtensionDefinition<readonly ExtendedKeyUsage[]>({\n\toid: OIDS.extendedKeyUsage,\n\tcontexts: ['certificate', 'csr'],\n\tdefaultCritical: false,\n\tdecode: (valueDer) => parseExtendedKeyUsage(valueDer),\n\tencode: (value) => encodeExtendedKeyUsage(value),\n\tassertProfile: (value) => {\n\t\tencodeExtendedKeyUsage(value);\n\t},\n\tapplyParsed: (accumulator, value) => {\n\t\taccumulator.extendedKeyUsage = value;\n\t},\n});\n\n/** Registry entry for Subject Alternative Name (OID 2.5.29.17). Non-critical by default. */\nexport const SUBJECT_ALT_NAME_EXTENSION_DEFINITION: RegisteredExtensionDefinition<\n\treadonly SubjectAltName[]\n> = defineExtensionDefinition<readonly SubjectAltName[]>({\n\toid: OIDS.subjectAltName,\n\tcontexts: ['certificate', 'csr'],\n\tdefaultCritical: false,\n\tdecode: (valueDer) => parseSubjectAltNames(valueDer),\n\tencode: (value) => sequence(value.map(encodeSubjectAltName)),\n\tassertProfile: (value) => {\n\t\tfor (const name of value) {\n\t\t\tencodeSubjectAltName(name);\n\t\t}\n\t},\n\tapplyParsed: (accumulator, value) => {\n\t\taccumulator.subjectAltNames = value;\n\t},\n});\n\n/** Registry entry for Issuer Alternative Name (OID 2.5.29.18). Non-critical by default. */\nexport const ISSUER_ALT_NAME_EXTENSION_DEFINITION: RegisteredExtensionDefinition<\n\treadonly SubjectAltName[]\n> = defineExtensionDefinition<readonly SubjectAltName[]>({\n\toid: OIDS.issuerAltName,\n\tcontexts: ['certificate'],\n\tdefaultCritical: false,\n\tdecode: (valueDer) => parseSubjectAltNames(valueDer, 'issuerAltName'),\n\tencode: (value) => sequence(value.map(encodeSubjectAltName)),\n\tassertProfile: (value) => {\n\t\tfor (const name of value) {\n\t\t\tencodeSubjectAltName(name);\n\t\t}\n\t},\n\tapplyParsed: (accumulator, value) => {\n\t\taccumulator.issuerAltNames = value;\n\t},\n});\n\n/** Registry entry for Name Constraints (OID 2.5.29.30). Critical by default. */\nexport const NAME_CONSTRAINTS_EXTENSION_DEFINITION: RegisteredExtensionDefinition<\n\tNameConstraints<ParsedNameConstraintForm>,\n\tNameConstraints\n> = defineExtensionDefinition<NameConstraints<ParsedNameConstraintForm>, NameConstraints>({\n\toid: OIDS.nameConstraints,\n\tcontexts: ['certificate', 'csr'],\n\tdefaultCritical: true,\n\tdecode: (valueDer) => parseNameConstraints(valueDer),\n\tencode: (value) => encodeNameConstraints(value),\n\tassertProfile: (value, critical) => {\n\t\tassertNameConstraintsProfile(value);\n\t\tassertExtensionCriticality('nameConstraints', true, critical);\n\t},\n\tapplyParsed: (accumulator, value) => {\n\t\taccumulator.nameConstraints = value;\n\t},\n});\n\n/** Registry entry for Certificate Policies (OID 2.5.29.32). Non-critical by default. */\nexport const CERTIFICATE_POLICIES_EXTENSION_DEFINITION: RegisteredExtensionDefinition<CertificatePolicies> =\n\tdefineExtensionDefinition<CertificatePolicies>({\n\t\toid: OIDS.certificatePolicies,\n\t\tcontexts: ['certificate', 'csr'],\n\t\tdefaultCritical: false,\n\t\tdecode: (valueDer) => parseCertificatePolicies(valueDer),\n\t\tencode: (value) => encodeCertificatePolicies(value),\n\t\tassertProfile: (value) => {\n\t\t\tencodeCertificatePolicies(value);\n\t\t},\n\t\tapplyParsed: (accumulator, value) => {\n\t\t\taccumulator.certificatePolicies = value;\n\t\t},\n\t});\n\n/** Registry entry for Policy Mappings (OID 2.5.29.33). Critical by default. */\nexport const POLICY_MAPPINGS_EXTENSION_DEFINITION: RegisteredExtensionDefinition<PolicyMappings> =\n\tdefineExtensionDefinition<PolicyMappings>({\n\t\toid: OIDS.policyMappings,\n\t\tcontexts: ['certificate', 'csr'],\n\t\tdefaultCritical: true,\n\t\tdecode: (valueDer) => parsePolicyMappings(valueDer),\n\t\tencode: (value) => encodePolicyMappings(value),\n\t\tassertProfile: (value) => {\n\t\t\tencodePolicyMappings(value);\n\t\t},\n\t\tapplyParsed: (accumulator, value) => {\n\t\t\taccumulator.policyMappings = value;\n\t\t},\n\t});\n\n/** Registry entry for Policy Constraints (OID 2.5.29.36). Critical by default. */\nexport const POLICY_CONSTRAINTS_EXTENSION_DEFINITION: RegisteredExtensionDefinition<PolicyConstraints> =\n\tdefineExtensionDefinition<PolicyConstraints>({\n\t\toid: OIDS.policyConstraints,\n\t\tcontexts: ['certificate', 'csr'],\n\t\tdefaultCritical: true,\n\t\tdecode: (valueDer) => parsePolicyConstraints(valueDer),\n\t\tencode: (value) => encodePolicyConstraints(value),\n\t\tassertProfile: (value, critical) => {\n\t\t\tencodePolicyConstraints(value);\n\t\t\tassertExtensionCriticality('policyConstraints', true, critical);\n\t\t},\n\t\tapplyParsed: (accumulator, value) => {\n\t\t\taccumulator.policyConstraints = value;\n\t\t},\n\t});\n\n/** Registry entry for Inhibit anyPolicy (OID 2.5.29.54). Critical by default. */\nexport const INHIBIT_ANY_POLICY_EXTENSION_DEFINITION: RegisteredExtensionDefinition<InhibitAnyPolicy> =\n\tdefineExtensionDefinition<InhibitAnyPolicy>({\n\t\toid: OIDS.inhibitAnyPolicy,\n\t\tcontexts: ['certificate', 'csr'],\n\t\tdefaultCritical: true,\n\t\tdecode: (valueDer) => parseInhibitAnyPolicy(valueDer),\n\t\tencode: (value) => encodeInhibitAnyPolicy(value),\n\t\tassertProfile: (value, critical) => {\n\t\t\tencodeInhibitAnyPolicy(value);\n\t\t\tassertExtensionCriticality('inhibitAnyPolicy', true, critical);\n\t\t},\n\t\tapplyParsed: (accumulator, value) => {\n\t\t\taccumulator.inhibitAnyPolicy = value;\n\t\t},\n\t});\n\n/** Registry entry for Authority Information Access (OID 1.3.6.1.5.5.7.1.1). Non-critical. */\nexport const AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION: RegisteredExtensionDefinition<\n\treadonly AuthorityInformationAccess[],\n\treadonly AuthorityInformationAccessInput[]\n> = defineExtensionDefinition<\n\treadonly AuthorityInformationAccess[],\n\treadonly AuthorityInformationAccessInput[]\n>({\n\toid: OIDS.authorityInfoAccess,\n\tcontexts: ['certificate', 'csr'],\n\tdefaultCritical: false,\n\tdecode: (valueDer) => parseAuthorityInfoAccess(valueDer),\n\tencode: (value) => encodeAuthorityInfoAccess(value),\n\tassertProfile: (value, critical) => {\n\t\tassertAuthorityInfoAccessProfile(value);\n\t\tassertExtensionCriticality('authorityInfoAccess', false, critical);\n\t},\n\tapplyParsed: (accumulator, value) => {\n\t\taccumulator.authorityInfoAccess = value;\n\t},\n});\n\n/** Registry entry for CRL Distribution Points (OID 2.5.29.31). Non-critical by default. */\nexport const CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION: RegisteredExtensionDefinition<\n\treadonly ParsedDistributionPoint[],\n\treadonly DistributionPoint[]\n> = defineExtensionDefinition<readonly ParsedDistributionPoint[], readonly DistributionPoint[]>({\n\toid: OIDS.cRLDistributionPoints,\n\tcontexts: ['certificate', 'csr'],\n\tdefaultCritical: false,\n\tdecode: (valueDer) => parseCrlDistributionPoints(valueDer),\n\tencode: (value) => encodeCrlDistributionPoints(value),\n\tassertProfile: (value) => {\n\t\tassertCrlDistributionPointsProfile(value);\n\t},\n\tapplyParsed: (accumulator, value) => {\n\t\taccumulator.crlDistributionPoints = value;\n\t},\n});\n\n/** Registry entry for Subject Key Identifier (OID 2.5.29.14). Auto-generated; non-critical. */\nexport const SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION: RegisteredExtensionDefinition<\n\tstring,\n\tstring | Uint8Array\n> = defineExtensionDefinition<string, string | Uint8Array>({\n\toid: OIDS.subjectKeyIdentifier,\n\tcontexts: ['certificate'],\n\tdefaultCritical: false,\n\tautoGenerated: true,\n\tdecode: (valueDer) => decodeSubjectKeyIdentifier(valueDer),\n\tencode: (value) => octetString(normalizeKeyIdentifier(value)),\n\tassertProfile: (value, critical) => {\n\t\thexToBytes(value);\n\t\tassertExtensionCriticality('subjectKeyIdentifier', false, critical);\n\t},\n\tapplyParsed: (accumulator, value) => {\n\t\taccumulator.subjectKeyIdentifier = value;\n\t},\n});\n\n/** Registry entry for Authority Key Identifier (OID 2.5.29.35). Auto-generated; non-critical. */\nexport const AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION: RegisteredExtensionDefinition<\n\tstring | undefined,\n\tstring | Uint8Array\n> = defineExtensionDefinition<string | undefined, string | Uint8Array>({\n\toid: OIDS.authorityKeyIdentifier,\n\tcontexts: ['certificate'],\n\tdefaultCritical: false,\n\tautoGenerated: true,\n\tdecode: (valueDer) => parseAuthorityKeyIdentifier(valueDer),\n\tencode: (value) => sequence([implicitPrimitiveContext(0, normalizeKeyIdentifier(value))]),\n\tassertProfile: (value, critical) => {\n\t\tif (value !== undefined) {\n\t\t\thexToBytes(value);\n\t\t}\n\t\tassertExtensionCriticality('authorityKeyIdentifier', false, critical);\n\t},\n\tapplyParsed: (accumulator, value) => {\n\t\tif (value !== undefined) {\n\t\t\taccumulator.authorityKeyIdentifier = value;\n\t\t}\n\t},\n});\n\n/** Union of all built-in extension definition constants. */\nexport type KnownExtensionDefinition =\n\t| typeof BASIC_CONSTRAINTS_EXTENSION_DEFINITION\n\t| typeof KEY_USAGE_EXTENSION_DEFINITION\n\t| typeof EXTENDED_KEY_USAGE_EXTENSION_DEFINITION\n\t| typeof SUBJECT_ALT_NAME_EXTENSION_DEFINITION\n\t| typeof ISSUER_ALT_NAME_EXTENSION_DEFINITION\n\t| typeof NAME_CONSTRAINTS_EXTENSION_DEFINITION\n\t| typeof CERTIFICATE_POLICIES_EXTENSION_DEFINITION\n\t| typeof POLICY_MAPPINGS_EXTENSION_DEFINITION\n\t| typeof POLICY_CONSTRAINTS_EXTENSION_DEFINITION\n\t| typeof INHIBIT_ANY_POLICY_EXTENSION_DEFINITION\n\t| typeof AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION\n\t| typeof CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION\n\t| typeof SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION\n\t| typeof AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION;\n\n/** All built-in extension definitions, in registration order. */\nexport const CERT_CSR_EXTENSION_DEFINITIONS: readonly KnownExtensionDefinition[] = [\n\tBASIC_CONSTRAINTS_EXTENSION_DEFINITION,\n\tKEY_USAGE_EXTENSION_DEFINITION,\n\tEXTENDED_KEY_USAGE_EXTENSION_DEFINITION,\n\tSUBJECT_ALT_NAME_EXTENSION_DEFINITION,\n\tISSUER_ALT_NAME_EXTENSION_DEFINITION,\n\tNAME_CONSTRAINTS_EXTENSION_DEFINITION,\n\tCERTIFICATE_POLICIES_EXTENSION_DEFINITION,\n\tPOLICY_MAPPINGS_EXTENSION_DEFINITION,\n\tPOLICY_CONSTRAINTS_EXTENSION_DEFINITION,\n\tINHIBIT_ANY_POLICY_EXTENSION_DEFINITION,\n\tAUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION,\n\tCRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION,\n\tSUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n\tAUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION,\n];\n\n/** OID-keyed lookup for known extension definitions. */\nconst EXTENSION_DEFINITION_MAP = new Map<string, KnownExtensionDefinition>(\n\tCERT_CSR_EXTENSION_DEFINITIONS.map((definition) => [definition.oid, definition]),\n);\n\n/**\n * Return all known extension definitions, optionally filtered by context.\n *\n * @param context If provided, only definitions valid in that context are returned.\n */\nexport function listExtensionDefinitions(\n\tcontext?: ExtensionRegistryContext,\n): readonly KnownExtensionDefinition[] {\n\tif (context === undefined) {\n\t\treturn CERT_CSR_EXTENSION_DEFINITIONS;\n\t}\n\treturn CERT_CSR_EXTENSION_DEFINITIONS.filter((definition) =>\n\t\tdefinition.contexts.includes(context),\n\t);\n}\n\n/**\n * Look up a known extension definition by OID.\n *\n * Overloaded for each built-in OID constant to return the exact definition type;\n * the generic `string` form returns the union or `undefined`.\n *\n * @param oid Dotted-decimal extension OID.\n * @returns The matching definition, or `undefined` for unrecognized OIDs.\n */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.basicConstraints,\n): typeof BASIC_CONSTRAINTS_EXTENSION_DEFINITION;\n/** Exact definition for the Key Usage extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.keyUsage,\n): typeof KEY_USAGE_EXTENSION_DEFINITION;\n/** Exact definition for the Extended Key Usage extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.extendedKeyUsage,\n): typeof EXTENDED_KEY_USAGE_EXTENSION_DEFINITION;\n/** Exact definition for the Subject Alternative Name extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.subjectAltName,\n): typeof SUBJECT_ALT_NAME_EXTENSION_DEFINITION;\n/** Exact definition for the Issuer Alternative Name extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.issuerAltName,\n): typeof ISSUER_ALT_NAME_EXTENSION_DEFINITION;\n/** Exact definition for the Name Constraints extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.nameConstraints,\n): typeof NAME_CONSTRAINTS_EXTENSION_DEFINITION;\n/** Exact definition for the Certificate Policies extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.certificatePolicies,\n): typeof CERTIFICATE_POLICIES_EXTENSION_DEFINITION;\n/** Exact definition for the Policy Mappings extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.policyMappings,\n): typeof POLICY_MAPPINGS_EXTENSION_DEFINITION;\n/** Exact definition for the Policy Constraints extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.policyConstraints,\n): typeof POLICY_CONSTRAINTS_EXTENSION_DEFINITION;\n/** Exact definition for the Inhibit Any-Policy extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.inhibitAnyPolicy,\n): typeof INHIBIT_ANY_POLICY_EXTENSION_DEFINITION;\n/** Exact definition for the Authority Information Access extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.authorityInfoAccess,\n): typeof AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION;\n/** Exact definition for the CRL Distribution Points extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.cRLDistributionPoints,\n): typeof CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION;\n/** Exact definition for the Subject Key Identifier extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.subjectKeyIdentifier,\n): typeof SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION;\n/** Exact definition for the Authority Key Identifier extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.authorityKeyIdentifier,\n): typeof AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION;\n/** Generic lookup: returns the matching definition, or `undefined` for unrecognized OIDs. */\nexport function getExtensionDefinition(oid: string): KnownExtensionDefinition | undefined;\nexport function getExtensionDefinition(oid: string): KnownExtensionDefinition | undefined {\n\treturn EXTENSION_DEFINITION_MAP.get(oid);\n}\n\n/**\n * If `oid` matches a known extension valid in `context`, decode its DER\n * value and store the result in the accumulator.\n *\n * @returns `true` if the extension was recognized and applied.\n */\nexport function decodeAndApplyKnownExtension(\n\tcontext: ExtensionRegistryContext,\n\toid: string,\n\taccumulator: MutableKnownParsedExtensionAccumulator,\n\tvalueDer: Uint8Array,\n): boolean {\n\tconst definition = getExtensionDefinition(oid);\n\tif (definition === undefined || !definition.contexts.includes(context)) {\n\t\treturn false;\n\t}\n\tconst applier = extensionAppliers.get(oid);\n\tif (applier === undefined) {\n\t\treturn false;\n\t}\n\tapplier(accumulator, valueDer);\n\treturn true;\n}\n\n/**\n * Compute a Subject Key Identifier (SHA-1 of the public key bits) from\n * a DER-encoded SubjectPublicKeyInfo.\n */\nexport function buildSubjectKeyIdentifierFromSubjectPublicKeyInfo(\n\tsubjectPublicKeyInfo: Uint8Array,\n): Uint8Array {\n\treturn buildSubjectKeyIdentifier(subjectPublicKeyInfo);\n}\n\n/**\n * Register an {@linkcode ExtensionDefinition} literal, capturing its\n * decode-and-apply and decode-and-validate closures.\n *\n * Both closures are built here, where `TParsed` is concrete, so that\n * `decodeAndApplyKnownExtension` and `assertDerProfile` can be called through the\n * union-typed `KnownExtensionDefinition` without hitting TypeScript's\n * correlated-union limitation.\n */\nfunction defineExtensionDefinition<TParsed, TInput = TParsed>(\n\tdefinition: ExtensionDefinition<TParsed, TInput>,\n): RegisteredExtensionDefinition<TParsed, TInput> {\n\textensionAppliers.set(definition.oid, (accumulator, valueDer) => {\n\t\tdefinition.applyParsed(accumulator, definition.decode(valueDer));\n\t});\n\treturn {\n\t\t...definition,\n\t\tassertDerProfile: (valueDer, critical) => {\n\t\t\tdefinition.assertProfile(definition.decode(valueDer), critical);\n\t\t},\n\t};\n}\n\n/** Accept hex string or Uint8Array and return raw bytes. */\nfunction normalizeKeyIdentifier(value: string | Uint8Array): Uint8Array {\n\treturn typeof value === 'string' ? hexToBytes(value) : value;\n}\n\n/** Decode an SKI extension value DER to a hex string. */\nfunction decodeSubjectKeyIdentifier(valueDer: Uint8Array): string {\n\tconst element = readRootElement(valueDer, { maxDepth: DEFAULT_MAX_DER_DEPTH });\n\tif (element.tag !== 0x04) {\n\t\tthrow new Error('SubjectKeyIdentifier must be an OCTET STRING');\n\t}\n\treturn toHex(element.value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA4KA,MAAM,oBAAoB,IAAI,IAG5B,GAGW,IACZ,0BAA4C;CAC3C,KAAK,EAAK;CACV,UAAU,CAAC,eAAe,KAAK;CAC/B,iBAAiB;CACjB,SAAS,MAAa,EAAsB,CAAQ;CACpD,SAAS,MAAU,EAAuB,CAAK;CAC/C,gBAAgB,MAAU;EACzB,EAAuB,CAAK;CAC7B;CACA,cAAc,GAAa,MAAU;EACpC,EAAY,mBAAmB;CAChC;AACD,CAAC,GAGW,IAGT,0BAAyE;CAC5E,KAAK,EAAK;CACV,UAAU,CAAC,eAAe,KAAK;CAC/B,iBAAiB;CACjB,SAAS,MAAa,EAAc,CAAQ;CAC5C,SAAS,MAAU,EAAe,CAAK;CACvC,gBAAgB,MAAU;EACzB,EAAe,EAAM,KAAK;CAC3B;CACA,cAAc,GAAa,MAAU;EACpC,EAAY,WAAW;CACxB;AACD,CAAC,GAGY,IAET,0BAAuD;CAC1D,KAAK,EAAK;CACV,UAAU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yB,IAAI,CAAG;AACxC;;;;;;;AAQA,SAAgB,6BACf,GACA,GACA,GACA,GACU;CACV,IAAM,IAAa,uBAAuB,CAAG;CAC7C,IAAI,MAAe,KAAA,KAAa,CAAC,EAAW,SAAS,SAAS,CAAO,GACpE,OAAO;CAER,IAAM,IAAU,EAAkB,IAAI,CAAG;CAKzC,OAJI,MAAY,KAAA,IACR,MAER,EAAQ,GAAa,CAAQ,GACtB;AACR;;;;;;;;;;AAqBA,SAAS,0BACR,GACiD;CAIjD,OAHA,EAAkB,IAAI,EAAW,MAAM,GAAa,MAAa;EAChE,EAAW,YAAY,GAAa,EAAW,OAAO,CAAQ,CAAC;CAChE,CAAC,GACM;EACN,GAAG;EACH,mBAAmB,GAAU,MAAa;GACzC,EAAW,cAAc,EAAW,OAAO,CAAQ,GAAG,CAAQ;EAC/D;CACD;AACD;;AAGA,SAAS,uBAAuB,GAAwC;CACvE,OAAO,OAAO,KAAU,WAAW,EAAW,CAAK,IAAI;AACxD;;AAGA,SAAS,2BAA2B,GAA8B;CACjE,IAAM,IAAU,EAAgB,GAAU,EAAE,UAAA,GAAgC,CAAC;CAC7E,IAAI,EAAQ,QAAQ,GACnB,MAAU,MAAM,8CAA8C;CAE/D,OAAO,EAAM,EAAQ,KAAK;AAC3B"}
@@ -0,0 +1,28 @@
1
+ //#region src/internal/x509/general-name-tags.ts
2
+ /**
3
+ * The DER wire tags of the nine GeneralName CHOICE alternatives (RFC 5280
4
+ * §4.2.1.6), fixing tag class, number, and constructedness.
5
+ *
6
+ * @module
7
+ */
8
+ /**
9
+ * Valid GeneralName tags: `otherName [0]`, `rfc822Name [1]`, `dNSName [2]`,
10
+ * `x400Address [3]`, `directoryName [4]`, `ediPartyName [5]`,
11
+ * `uniformResourceIdentifier [6]`, `iPAddress [7]`, `registeredID [8]`. Any
12
+ * other tag, class, or constructedness is not a GeneralName.
13
+ */
14
+ const e = /* @__PURE__ */ new Set([
15
+ 160,
16
+ 129,
17
+ 130,
18
+ 163,
19
+ 164,
20
+ 165,
21
+ 134,
22
+ 135,
23
+ 136
24
+ ]);
25
+ //#endregion
26
+ export { e as GENERAL_NAME_WIRE_TAGS };
27
+
28
+ //# sourceMappingURL=general-name-tags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"general-name-tags.js","names":[],"sources":["../../../src/internal/x509/general-name-tags.ts"],"sourcesContent":["/**\n * The DER wire tags of the nine GeneralName CHOICE alternatives (RFC 5280\n * §4.2.1.6), fixing tag class, number, and constructedness.\n *\n * @module\n */\n\n/**\n * Valid GeneralName tags: `otherName [0]`, `rfc822Name [1]`, `dNSName [2]`,\n * `x400Address [3]`, `directoryName [4]`, `ediPartyName [5]`,\n * `uniformResourceIdentifier [6]`, `iPAddress [7]`, `registeredID [8]`. Any\n * other tag, class, or constructedness is not a GeneralName.\n */\nexport const GENERAL_NAME_WIRE_TAGS: ReadonlySet<number> = new Set([\n\t0xa0, 0x81, 0x82, 0xa3, 0xa4, 0xa5, 0x86, 0x87, 0x88,\n]);\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,oBAA8C,IAAI,IAAI;CAClE;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;AACjD,CAAC"}
@@ -0,0 +1,97 @@
1
+ import { childrenOf as e, decodeObjectIdentifier as t, decodeString as n, toHex as r } from "../asn1/asn1.js";
2
+ import { OIDS as i } from "../asn1/oids2.js";
3
+ import { readDirectoryNameTlv as a } from "./directory-name.js";
4
+ import { decodeIpAddress as o } from "../shared/ip.js";
5
+ import { GENERAL_NAME_WIRE_TAGS as s } from "./general-name-tags.js";
6
+ //#region src/internal/x509/general-name.ts
7
+ /**
8
+ * The canonical RFC 5280 §4.2.1.6 GeneralName decoder, shared by certificate
9
+ * and CRL parsing so both layers agree on the representation of every
10
+ * alternative.
11
+ *
12
+ * @module
13
+ */
14
+ /** Decode a SEQUENCE OF GeneralName. */
15
+ function parseGeneralNames(t, n) {
16
+ let r = e(t, n);
17
+ if (r.length === 0) throw Error("GeneralNames must not be empty");
18
+ for (let e of r) if ((e.tag & 192) != 128) throw Error("GeneralNames must contain GeneralName entries");
19
+ return r.map((e) => parseGeneralName(t, e));
20
+ }
21
+ /**
22
+ * Decode an IA5String GeneralName alternative, rejecting a zero-length value.
23
+ *
24
+ * RFC 5280 §4.2.1.6 forbids empty GeneralName fields, and a certificate carrying
25
+ * one presents no usable identity.
26
+ */
27
+ function requireNonEmptyIa5(e, t) {
28
+ if (e.value.length === 0) throw Error(`GeneralName ${t} must not be empty`);
29
+ return n(22, e.value);
30
+ }
31
+ /** Decode a single GeneralName from its implicit context tag. */
32
+ function parseGeneralName(e, t) {
33
+ switch (t.tag) {
34
+ case 160: {
35
+ let n = parseOtherName(e, t);
36
+ return n === void 0 ? {
37
+ type: "unknown",
38
+ tag: t.tag,
39
+ value: e.slice(t.start, t.end)
40
+ } : n;
41
+ }
42
+ case 129: return {
43
+ type: "email",
44
+ value: requireNonEmptyIa5(t, "rfc822Name")
45
+ };
46
+ case 130: return {
47
+ type: "dns",
48
+ value: requireNonEmptyIa5(t, "dNSName")
49
+ };
50
+ case 134: return {
51
+ type: "uri",
52
+ value: requireNonEmptyIa5(t, "uniformResourceIdentifier")
53
+ };
54
+ case 135: return {
55
+ type: "ip",
56
+ value: o(t.value)
57
+ };
58
+ case 164: return {
59
+ type: "directoryName",
60
+ derHex: r(a(t))
61
+ };
62
+ default:
63
+ if (!s.has(t.tag)) throw Error(`Invalid GeneralName tag: ${t.tag}`);
64
+ return {
65
+ type: "unknown",
66
+ tag: t.tag,
67
+ value: e.slice(t.start, t.end)
68
+ };
69
+ }
70
+ }
71
+ /**
72
+ * Decode an otherName [0] as a known type (currently only SRV-ID).
73
+ *
74
+ * `otherName [0] OtherName` is in the IMPLICIT-TAGS module, so the [0] tag
75
+ * replaces OtherName's SEQUENCE tag: the type-id and `value [0] EXPLICIT` are
76
+ * the direct children, with no inner SEQUENCE. A malformed envelope, or a
77
+ * malformed payload of a recognised OID, throws. A structurally valid OtherName
78
+ * with an unsupported OID returns `undefined`, so the caller preserves it as
79
+ * `{ type: 'unknown' }`.
80
+ */
81
+ function parseOtherName(r, a) {
82
+ let o = e(r, a), s = o[0], c = o[1];
83
+ if (o.length !== 2 || s === void 0 || c === void 0 || s.tag !== 6 || c.tag !== 160) throw Error("Malformed otherName");
84
+ let l = e(r, c), u = l[0];
85
+ if (l.length !== 1 || u === void 0) throw Error("otherName value [0] must wrap exactly one element");
86
+ if (t(s.value) === i.idOnDnsSrv) {
87
+ if (u.tag !== 22 || u.value.length === 0) throw Error("SRV-ID otherName must wrap a non-empty IA5String");
88
+ return {
89
+ type: "srv",
90
+ value: n(u.tag, u.value)
91
+ };
92
+ }
93
+ }
94
+ //#endregion
95
+ export { parseGeneralName, parseGeneralNames };
96
+
97
+ //# sourceMappingURL=general-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"general-name.js","names":[],"sources":["../../../src/internal/x509/general-name.ts"],"sourcesContent":["/**\n * The canonical RFC 5280 §4.2.1.6 GeneralName decoder, shared by certificate\n * and CRL parsing so both layers agree on the representation of every\n * alternative.\n *\n * @module\n */\n\nimport {\n\tchildrenOf,\n\tdecodeObjectIdentifier,\n\tdecodeString,\n\ttoHex,\n} from '#micro509/internal/asn1/asn1';\nimport type { DerElement } from '#micro509/internal/asn1/der';\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport { decodeIpAddress } from '#micro509/internal/shared/ip';\nimport { readDirectoryNameTlv } from '#micro509/internal/x509/directory-name';\nimport { GENERAL_NAME_WIRE_TAGS } from '#micro509/internal/x509/general-name-tags';\nimport type { GeneralName, SubjectAltName } from '#micro509/x509/extensions';\n\n/** Decode a SEQUENCE OF GeneralName. */\nexport function parseGeneralNames(source: Uint8Array, element: DerElement): readonly GeneralName[] {\n\tconst names = childrenOf(source, element);\n\tif (names.length === 0) {\n\t\tthrow new Error('GeneralNames must not be empty');\n\t}\n\tfor (const name of names) {\n\t\tif ((name.tag & 0xc0) !== 0x80) {\n\t\t\tthrow new Error('GeneralNames must contain GeneralName entries');\n\t\t}\n\t}\n\treturn names.map((name) => parseGeneralName(source, name));\n}\n\n/**\n * Decode an IA5String GeneralName alternative, rejecting a zero-length value.\n *\n * RFC 5280 §4.2.1.6 forbids empty GeneralName fields, and a certificate carrying\n * one presents no usable identity.\n */\nfunction requireNonEmptyIa5(element: DerElement, alternative: string): string {\n\tif (element.value.length === 0) {\n\t\tthrow new Error(`GeneralName ${alternative} must not be empty`);\n\t}\n\treturn decodeString(0x16, element.value);\n}\n\n/** Decode a single GeneralName from its implicit context tag. */\nexport function parseGeneralName(source: Uint8Array, element: DerElement): GeneralName {\n\tswitch (element.tag) {\n\t\tcase 0xa0: {\n\t\t\tconst otherName = parseOtherName(source, element);\n\t\t\tif (otherName !== undefined) {\n\t\t\t\treturn otherName;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\ttype: 'unknown' as const,\n\t\t\t\ttag: element.tag,\n\t\t\t\tvalue: source.slice(element.start, element.end),\n\t\t\t};\n\t\t}\n\t\tcase 0x81:\n\t\t\treturn { type: 'email' as const, value: requireNonEmptyIa5(element, 'rfc822Name') };\n\t\tcase 0x82:\n\t\t\treturn { type: 'dns' as const, value: requireNonEmptyIa5(element, 'dNSName') };\n\t\tcase 0x86:\n\t\t\treturn {\n\t\t\t\ttype: 'uri' as const,\n\t\t\t\tvalue: requireNonEmptyIa5(element, 'uniformResourceIdentifier'),\n\t\t\t};\n\t\tcase 0x87:\n\t\t\treturn { type: 'ip' as const, value: decodeIpAddress(element.value) };\n\t\tcase 0xa4:\n\t\t\treturn {\n\t\t\t\ttype: 'directoryName' as const,\n\t\t\t\tderHex: toHex(readDirectoryNameTlv(element)),\n\t\t\t};\n\t\tdefault:\n\t\t\t// x400Address [3], ediPartyName [5], and registeredID [8] are valid but\n\t\t\t// unsupported; any other tag/class/constructedness is not a GeneralName.\n\t\t\tif (!GENERAL_NAME_WIRE_TAGS.has(element.tag)) {\n\t\t\t\tthrow new Error(`Invalid GeneralName tag: ${element.tag}`);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\ttype: 'unknown' as const,\n\t\t\t\ttag: element.tag,\n\t\t\t\tvalue: source.slice(element.start, element.end),\n\t\t\t};\n\t}\n}\n\n/**\n * Decode an otherName [0] as a known type (currently only SRV-ID).\n *\n * `otherName [0] OtherName` is in the IMPLICIT-TAGS module, so the [0] tag\n * replaces OtherName's SEQUENCE tag: the type-id and `value [0] EXPLICIT` are\n * the direct children, with no inner SEQUENCE. A malformed envelope, or a\n * malformed payload of a recognised OID, throws. A structurally valid OtherName\n * with an unsupported OID returns `undefined`, so the caller preserves it as\n * `{ type: 'unknown' }`.\n */\nfunction parseOtherName(source: Uint8Array, element: DerElement): SubjectAltName | undefined {\n\tconst children = childrenOf(source, element);\n\tconst typeId = children[0];\n\tconst valueElement = children[1];\n\tif (\n\t\tchildren.length !== 2 ||\n\t\ttypeId === undefined ||\n\t\tvalueElement === undefined ||\n\t\ttypeId.tag !== 0x06 ||\n\t\tvalueElement.tag !== 0xa0\n\t) {\n\t\tthrow new Error('Malformed otherName');\n\t}\n\tconst valueChildren = childrenOf(source, valueElement);\n\tconst value = valueChildren[0];\n\tif (valueChildren.length !== 1 || value === undefined) {\n\t\tthrow new Error('otherName value [0] must wrap exactly one element');\n\t}\n\tif (decodeObjectIdentifier(typeId.value) !== OIDS.idOnDnsSrv) {\n\t\treturn undefined;\n\t}\n\tif (value.tag !== 0x16 || value.value.length === 0) {\n\t\tthrow new Error('SRV-ID otherName must wrap a non-empty IA5String');\n\t}\n\treturn { type: 'srv', value: decodeString(value.tag, value.value) };\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,SAAgB,kBAAkB,GAAoB,GAA6C;CAClG,IAAM,IAAQ,EAAW,GAAQ,CAAO;CACxC,IAAI,EAAM,WAAW,GACpB,MAAU,MAAM,gCAAgC;CAEjD,KAAK,IAAM,KAAQ,GAClB,KAAK,EAAK,MAAM,QAAU,KACzB,MAAU,MAAM,+CAA+C;CAG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EAAO,QAAQ,KACf,EAAa,QAAQ,KAErB,MAAU,MAAM,qBAAqB;CAEtC,IAAM,IAAgB,EAAW,GAAQ,CAAY,GAC/C,IAAQ,EAAc;CAC5B,IAAI,EAAc,WAAW,KAAK,MAAU,KAAA,GAC3C,MAAU,MAAM,mDAAmD;CAEhE,MAAuB,EAAO,KAAK,MAAM,EAAK,YAGlD;MAAI,EAAM,QAAQ,MAAQ,EAAM,MAAM,WAAW,GAChD,MAAU,MAAM,kDAAkD;EAEnE,OAAO;GAAE,MAAM;GAAO,OAAO,EAAa,EAAM,KAAK,EAAM,KAAK;EAAE;CAFC;AAGpE"}
@@ -16,15 +16,18 @@ import { OIDS as r } from "../asn1/oids2.js";
16
16
  const i = {
17
17
  commonName: {
18
18
  oid: r.commonName,
19
- encode: n
19
+ encode: n,
20
+ maxLength: 64
20
21
  },
21
22
  surname: {
22
23
  oid: r.surname,
23
- encode: n
24
+ encode: n,
25
+ maxLength: 32768
24
26
  },
25
27
  serialNumber: {
26
28
  oid: r.serialNumber,
27
- encode: t
29
+ encode: t,
30
+ maxLength: 64
28
31
  },
29
32
  country: {
30
33
  oid: r.countryName,
@@ -32,11 +35,13 @@ const i = {
32
35
  },
33
36
  locality: {
34
37
  oid: r.localityName,
35
- encode: n
38
+ encode: n,
39
+ maxLength: 128
36
40
  },
37
41
  state: {
38
42
  oid: r.stateOrProvinceName,
39
- encode: n
43
+ encode: n,
44
+ maxLength: 128
40
45
  },
41
46
  street: {
42
47
  oid: r.streetAddress,
@@ -44,23 +49,28 @@ const i = {
44
49
  },
45
50
  organization: {
46
51
  oid: r.organizationName,
47
- encode: n
52
+ encode: n,
53
+ maxLength: 64
48
54
  },
49
55
  organizationalUnit: {
50
56
  oid: r.organizationalUnitName,
51
- encode: n
57
+ encode: n,
58
+ maxLength: 64
52
59
  },
53
60
  title: {
54
61
  oid: r.title,
55
- encode: n
62
+ encode: n,
63
+ maxLength: 64
56
64
  },
57
65
  givenName: {
58
66
  oid: r.givenName,
59
- encode: n
67
+ encode: n,
68
+ maxLength: 32768
60
69
  },
61
70
  emailAddress: {
62
71
  oid: r.emailAddress,
63
- encode: e
72
+ encode: e,
73
+ maxLength: 255
64
74
  }
65
75
  }, a = [
66
76
  "country",