micro509 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2064 -0
- package/README.md +105 -225
- package/dist/crypto/crypto.d.ts +42 -11
- package/dist/crypto/crypto.js +53 -22
- package/dist/crypto/crypto.js.map +1 -1
- package/dist/crypto.d.ts +2 -2
- package/dist/crypto.js +1 -2
- package/dist/der/der.d.ts +41 -33
- package/dist/der/der.js +26 -24
- package/dist/der/der.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.js +19 -19
- package/dist/internal/asn1/asn1.d.ts +3 -6
- package/dist/internal/asn1/asn1.js +343 -43
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/ber.js +146 -0
- package/dist/internal/asn1/ber.js.map +1 -0
- package/dist/internal/asn1/decode-refusal.js +29 -0
- package/dist/internal/asn1/decode-refusal.js.map +1 -0
- package/dist/internal/asn1/der.d.ts +38 -41
- package/dist/internal/asn1/der.js +131 -52
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js +83 -53
- package/dist/internal/asn1/oids.js.map +1 -1
- package/dist/internal/asn1/oids2.js +1 -2
- package/dist/internal/asn1/oids2.js.map +1 -1
- package/dist/internal/crypto/algorithm-names.js +1 -2
- package/dist/internal/crypto/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/ecdsa.js +13 -8
- package/dist/internal/crypto/ecdsa.js.map +1 -1
- package/dist/internal/crypto/hash.js +1 -2
- package/dist/internal/crypto/hash.js.map +1 -1
- package/dist/internal/crypto/pbes2.d.ts +24 -11
- package/dist/internal/crypto/pbes2.js +79 -26
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/rsa-pss.js +46 -44
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +4 -7
- package/dist/internal/crypto/sig-verify.js +107 -60
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/crypto/signing.d.ts +1 -4
- package/dist/internal/crypto/signing.js +28 -29
- package/dist/internal/crypto/signing.js.map +1 -1
- package/dist/internal/crypto/webcrypto.js +1 -2
- package/dist/internal/crypto/webcrypto.js.map +1 -1
- package/dist/internal/shared/base64.js +1 -2
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.d.ts +3 -6
- package/dist/internal/shared/dn.js +99 -53
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/idna-tables.js +7217 -0
- package/dist/internal/shared/idna-tables.js.map +1 -0
- package/dist/internal/shared/idna.js +296 -0
- package/dist/internal/shared/idna.js.map +1 -0
- package/dist/internal/shared/ip.d.ts +4 -7
- package/dist/internal/shared/ip.js +1 -2
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/shared/mailbox.js +26 -0
- package/dist/internal/shared/mailbox.js.map +1 -0
- package/dist/internal/shared/punycode.js +101 -0
- package/dist/internal/shared/punycode.js.map +1 -0
- package/dist/internal/shared/rfc3454-tables.js +1 -2
- package/dist/internal/shared/rfc3454-tables.js.map +1 -1
- package/dist/internal/shared/rfc4518-tables.js +119 -0
- package/dist/internal/shared/rfc4518-tables.js.map +1 -0
- package/dist/internal/shared/uri-host.js +102 -0
- package/dist/internal/shared/uri-host.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +246 -131
- package/dist/internal/verify/name-constraints-engine.js.map +1 -1
- package/dist/internal/verify/policy-engine.js +6 -21
- package/dist/internal/verify/policy-engine.js.map +1 -1
- package/dist/internal/verify/verify-path.d.ts +1 -4
- package/dist/internal/verify/verify-path.js +267 -131
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/internal/x509/directory-name.js +1 -2
- package/dist/internal/x509/directory-name.js.map +1 -1
- package/dist/internal/x509/extension-bits.js +2 -3
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.d.ts +1 -4
- package/dist/internal/x509/extension-errors.js +1 -2
- package/dist/internal/x509/extension-errors.js.map +1 -1
- package/dist/internal/x509/extension-registry.js +107 -89
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-profile.js +129 -0
- package/dist/internal/x509/general-name-profile.js.map +1 -0
- package/dist/internal/x509/general-name-tags.js +1 -2
- package/dist/internal/x509/general-name-tags.js.map +1 -1
- package/dist/internal/x509/general-name.js +128 -42
- package/dist/internal/x509/general-name.js.map +1 -1
- package/dist/internal/x509/name-fields.js +1 -2
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/internal/x509/or-address.js +217 -0
- package/dist/internal/x509/or-address.js.map +1 -0
- package/dist/keys/keys.d.ts +112 -97
- package/dist/keys/keys.js +211 -204
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +3 -3
- package/dist/pem/pem.d.ts +14 -17
- package/dist/pem/pem.js +16 -17
- package/dist/pem/pem.js.map +1 -1
- package/dist/pem.js +1 -2
- package/dist/pkcs/pfx.d.ts +57 -32
- package/dist/pkcs/pfx.js +209 -173
- package/dist/pkcs/pfx.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.d.ts +104 -27
- package/dist/pkcs/pkcs12-mac.js +266 -79
- package/dist/pkcs/pkcs12-mac.js.map +1 -1
- package/dist/pkcs/pkcs7.d.ts +43 -37
- package/dist/pkcs/pkcs7.js +218 -217
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +4 -3
- package/dist/result/result.d.ts +27 -20
- package/dist/result/result.js +8 -3
- package/dist/result/result.js.map +1 -1
- package/dist/result.d.ts +2 -2
- package/dist/result.js +1 -2
- package/dist/revocation/chain.d.ts +101 -23
- package/dist/revocation/chain.js +436 -182
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +131 -67
- package/dist/revocation/crl.js +444 -323
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +94 -59
- package/dist/revocation/ocsp.js +331 -293
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +47 -35
- package/dist/revocation/revocation.js +88 -57
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +3 -3
- package/dist/verify/identity.d.ts +16 -19
- package/dist/verify/identity.js +118 -89
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/name-constraints.d.ts +1 -4
- package/dist/verify/policy.d.ts +9 -7
- package/dist/verify/verify.d.ts +84 -46
- package/dist/verify/verify.js +300 -152
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +2 -2
- package/dist/x509/certificate.d.ts +20 -21
- package/dist/x509/certificate.js +62 -46
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.d.ts +5 -7
- package/dist/x509/csr.js +10 -11
- package/dist/x509/csr.js.map +1 -1
- package/dist/x509/extensions.d.ts +154 -66
- package/dist/x509/extensions.js +317 -151
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.d.ts +4 -7
- package/dist/x509/fingerprint.js +1 -2
- package/dist/x509/fingerprint.js.map +1 -1
- package/dist/x509/name-text.d.ts +7 -9
- package/dist/x509/name-text.js +18 -4
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.d.ts +9 -11
- package/dist/x509/name.js +18 -19
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +84 -69
- package/dist/x509/parse.js +421 -400
- package/dist/x509/parse.js.map +1 -1
- package/dist/x509.d.ts +2 -2
- package/package.json +76 -59
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { implicitPrimitiveContext as e,
|
|
2
|
-
import { hexToBytes as
|
|
3
|
-
import { OIDS as
|
|
4
|
-
import { assertAuthorityInfoAccessProfile as
|
|
5
|
-
import { parseAuthorityInfoAccess as
|
|
6
|
-
|
|
1
|
+
import { implicitPrimitiveContext as e, nullValue as t, octetString as n, readRootElement as r, sequence as i } from "../asn1/der.js";
|
|
2
|
+
import { hexToBytes as a, toHex as o } from "../asn1/asn1.js";
|
|
3
|
+
import { OIDS as s } from "../asn1/oids2.js";
|
|
4
|
+
import { assertAuthorityInfoAccessProfile as c, assertCrlDistributionPointsProfile as l, assertExtensionCriticality as u, assertNameConstraintsProfile as d, assertStoredSubjectAltName as f, encodeAuthorityInfoAccess as p, encodeBasicConstraints as m, encodeCertificatePolicies as h, encodeCrlDistributionPoints as g, encodeExtendedKeyUsage as _, encodeInhibitAnyPolicy as v, encodeKeyUsage as y, encodeNameConstraints as b, encodePolicyConstraints as x, encodePolicyMappings as S, encodeSubjectAltName as C } from "../../x509/extensions.js";
|
|
5
|
+
import { parseAuthorityInfoAccess as w, parseAuthorityKeyIdentifier as T, parseBasicConstraints as E, parseCertificatePolicies as D, parseCrlDistributionPoints as O, parseExtendedKeyUsage as k, parseInhibitAnyPolicy as A, parseKeyUsage as j, parseNameConstraints as M, parsePolicyConstraints as N, parsePolicyMappings as P, parseSubjectAltNames as F } from "../../x509/parse.js";
|
|
6
|
+
// src/internal/x509/extension-registry.ts
|
|
7
7
|
/**
|
|
8
8
|
* Internal extension registry for certificate and CSR parsing.
|
|
9
9
|
*
|
|
@@ -20,179 +20,189 @@ import { parseAuthorityInfoAccess as S, parseAuthorityKeyIdentifier as C, 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
|
|
24
|
-
oid:
|
|
23
|
+
const I = /* @__PURE__ */ new Map(), L = defineExtensionDefinition({
|
|
24
|
+
oid: s.basicConstraints,
|
|
25
25
|
contexts: ["certificate", "csr"],
|
|
26
26
|
defaultCritical: !0,
|
|
27
|
-
decode: (e) =>
|
|
28
|
-
encode: (e) =>
|
|
27
|
+
decode: (e) => E(e),
|
|
28
|
+
encode: (e) => m(e),
|
|
29
29
|
assertProfile: (e) => {
|
|
30
|
-
|
|
30
|
+
m(e);
|
|
31
31
|
},
|
|
32
32
|
applyParsed: (e, t) => {
|
|
33
33
|
e.basicConstraints = t;
|
|
34
34
|
}
|
|
35
|
-
}),
|
|
36
|
-
oid:
|
|
35
|
+
}), R = defineExtensionDefinition({
|
|
36
|
+
oid: s.keyUsage,
|
|
37
37
|
contexts: ["certificate", "csr"],
|
|
38
38
|
defaultCritical: !0,
|
|
39
|
-
decode: (e) =>
|
|
40
|
-
encode: (e) =>
|
|
39
|
+
decode: (e) => j(e),
|
|
40
|
+
encode: (e) => y(e),
|
|
41
41
|
assertProfile: (e) => {
|
|
42
|
-
|
|
42
|
+
y(e.flags);
|
|
43
43
|
},
|
|
44
44
|
applyParsed: (e, t) => {
|
|
45
45
|
e.keyUsage = t;
|
|
46
46
|
}
|
|
47
|
-
}),
|
|
48
|
-
oid:
|
|
47
|
+
}), z = defineExtensionDefinition({
|
|
48
|
+
oid: s.extendedKeyUsage,
|
|
49
49
|
contexts: ["certificate", "csr"],
|
|
50
50
|
defaultCritical: !1,
|
|
51
|
-
decode: (e) =>
|
|
52
|
-
encode: (e) =>
|
|
51
|
+
decode: (e) => k(e),
|
|
52
|
+
encode: (e) => _(e),
|
|
53
53
|
assertProfile: (e) => {
|
|
54
|
-
|
|
54
|
+
_(e);
|
|
55
55
|
},
|
|
56
56
|
applyParsed: (e, t) => {
|
|
57
57
|
e.extendedKeyUsage = t;
|
|
58
58
|
}
|
|
59
|
-
}),
|
|
60
|
-
oid:
|
|
59
|
+
}), B = defineExtensionDefinition({
|
|
60
|
+
oid: s.subjectAltName,
|
|
61
61
|
contexts: ["certificate", "csr"],
|
|
62
62
|
defaultCritical: !1,
|
|
63
|
-
decode: (e) =>
|
|
64
|
-
encode: (e) =>
|
|
63
|
+
decode: (e) => F(e),
|
|
64
|
+
encode: (e) => i(e.map(C)),
|
|
65
65
|
assertProfile: (e) => {
|
|
66
|
-
for (let t of e)
|
|
66
|
+
for (let t of e) f(t);
|
|
67
67
|
},
|
|
68
68
|
applyParsed: (e, t) => {
|
|
69
69
|
e.subjectAltNames = t;
|
|
70
70
|
}
|
|
71
|
-
}),
|
|
72
|
-
oid:
|
|
71
|
+
}), V = defineExtensionDefinition({
|
|
72
|
+
oid: s.issuerAltName,
|
|
73
73
|
contexts: ["certificate"],
|
|
74
74
|
defaultCritical: !1,
|
|
75
|
-
decode: (e) =>
|
|
76
|
-
encode: (e) =>
|
|
75
|
+
decode: (e) => F(e, "issuerAltName"),
|
|
76
|
+
encode: (e) => i(e.map(C)),
|
|
77
77
|
assertProfile: (e) => {
|
|
78
|
-
for (let t of e)
|
|
78
|
+
for (let t of e) f(t);
|
|
79
79
|
},
|
|
80
80
|
applyParsed: (e, t) => {
|
|
81
81
|
e.issuerAltNames = t;
|
|
82
82
|
}
|
|
83
|
-
}),
|
|
84
|
-
oid:
|
|
83
|
+
}), H = defineExtensionDefinition({
|
|
84
|
+
oid: s.nameConstraints,
|
|
85
85
|
contexts: ["certificate", "csr"],
|
|
86
86
|
defaultCritical: !0,
|
|
87
|
-
decode: (e) =>
|
|
88
|
-
encode: (e) =>
|
|
87
|
+
decode: (e) => M(e),
|
|
88
|
+
encode: (e) => b(e),
|
|
89
89
|
assertProfile: (e, t) => {
|
|
90
|
-
|
|
90
|
+
d(e), u("nameConstraints", !0, t);
|
|
91
91
|
},
|
|
92
92
|
applyParsed: (e, t) => {
|
|
93
93
|
e.nameConstraints = t;
|
|
94
94
|
}
|
|
95
|
-
}),
|
|
96
|
-
oid:
|
|
95
|
+
}), U = defineExtensionDefinition({
|
|
96
|
+
oid: s.certificatePolicies,
|
|
97
97
|
contexts: ["certificate", "csr"],
|
|
98
98
|
defaultCritical: !1,
|
|
99
|
-
decode: (e) =>
|
|
100
|
-
encode: (e) =>
|
|
99
|
+
decode: (e) => D(e),
|
|
100
|
+
encode: (e) => h(e),
|
|
101
101
|
assertProfile: (e) => {
|
|
102
|
-
|
|
102
|
+
h(e);
|
|
103
103
|
},
|
|
104
104
|
applyParsed: (e, t) => {
|
|
105
105
|
e.certificatePolicies = t;
|
|
106
106
|
}
|
|
107
|
-
}),
|
|
108
|
-
oid:
|
|
107
|
+
}), W = defineExtensionDefinition({
|
|
108
|
+
oid: s.policyMappings,
|
|
109
109
|
contexts: ["certificate", "csr"],
|
|
110
110
|
defaultCritical: !0,
|
|
111
|
-
decode: (e) =>
|
|
112
|
-
encode: (e) =>
|
|
111
|
+
decode: (e) => P(e),
|
|
112
|
+
encode: (e) => S(e),
|
|
113
113
|
assertProfile: (e) => {
|
|
114
|
-
|
|
114
|
+
S(e);
|
|
115
115
|
},
|
|
116
116
|
applyParsed: (e, t) => {
|
|
117
117
|
e.policyMappings = t;
|
|
118
118
|
}
|
|
119
|
-
}),
|
|
120
|
-
oid:
|
|
119
|
+
}), G = defineExtensionDefinition({
|
|
120
|
+
oid: s.policyConstraints,
|
|
121
121
|
contexts: ["certificate", "csr"],
|
|
122
122
|
defaultCritical: !0,
|
|
123
|
-
decode: (e) =>
|
|
124
|
-
encode: (e) =>
|
|
123
|
+
decode: (e) => N(e),
|
|
124
|
+
encode: (e) => x(e),
|
|
125
125
|
assertProfile: (e, t) => {
|
|
126
|
-
|
|
126
|
+
x(e), u("policyConstraints", !0, t);
|
|
127
127
|
},
|
|
128
128
|
applyParsed: (e, t) => {
|
|
129
129
|
e.policyConstraints = t;
|
|
130
130
|
}
|
|
131
|
-
}),
|
|
132
|
-
oid:
|
|
131
|
+
}), K = defineExtensionDefinition({
|
|
132
|
+
oid: s.inhibitAnyPolicy,
|
|
133
133
|
contexts: ["certificate", "csr"],
|
|
134
134
|
defaultCritical: !0,
|
|
135
|
-
decode: (e) =>
|
|
136
|
-
encode: (e) =>
|
|
135
|
+
decode: (e) => A(e),
|
|
136
|
+
encode: (e) => v(e),
|
|
137
137
|
assertProfile: (e, t) => {
|
|
138
|
-
|
|
138
|
+
v(e), u("inhibitAnyPolicy", !0, t);
|
|
139
139
|
},
|
|
140
140
|
applyParsed: (e, t) => {
|
|
141
141
|
e.inhibitAnyPolicy = t;
|
|
142
142
|
}
|
|
143
|
-
}),
|
|
144
|
-
oid:
|
|
143
|
+
}), q = defineExtensionDefinition({
|
|
144
|
+
oid: s.authorityInfoAccess,
|
|
145
145
|
contexts: ["certificate", "csr"],
|
|
146
146
|
defaultCritical: !1,
|
|
147
|
-
decode: (e) =>
|
|
148
|
-
encode: (e) =>
|
|
147
|
+
decode: (e) => w(e),
|
|
148
|
+
encode: (e) => p(e),
|
|
149
149
|
assertProfile: (e, t) => {
|
|
150
|
-
|
|
150
|
+
c(e), u("authorityInfoAccess", !1, t);
|
|
151
151
|
},
|
|
152
152
|
applyParsed: (e, t) => {
|
|
153
153
|
e.authorityInfoAccess = t;
|
|
154
154
|
}
|
|
155
|
-
}),
|
|
156
|
-
oid:
|
|
155
|
+
}), J = defineExtensionDefinition({
|
|
156
|
+
oid: s.cRLDistributionPoints,
|
|
157
157
|
contexts: ["certificate", "csr"],
|
|
158
158
|
defaultCritical: !1,
|
|
159
|
-
decode: (e) =>
|
|
160
|
-
encode: (e) =>
|
|
159
|
+
decode: (e) => O(e),
|
|
160
|
+
encode: (e) => g(e),
|
|
161
161
|
assertProfile: (e) => {
|
|
162
|
-
|
|
162
|
+
l(e);
|
|
163
163
|
},
|
|
164
164
|
applyParsed: (e, t) => {
|
|
165
165
|
e.crlDistributionPoints = t;
|
|
166
166
|
}
|
|
167
|
-
}),
|
|
168
|
-
oid:
|
|
167
|
+
}), Y = defineExtensionDefinition({
|
|
168
|
+
oid: s.noRevAvail,
|
|
169
|
+
contexts: ["certificate", "csr"],
|
|
170
|
+
defaultCritical: !1,
|
|
171
|
+
decode: (e) => decodeNoRevAvail(e),
|
|
172
|
+
encode: () => t(),
|
|
173
|
+
assertProfile: (e, t) => {
|
|
174
|
+
u("noRevAvail", !1, t);
|
|
175
|
+
},
|
|
176
|
+
applyParsed: (e, t) => {
|
|
177
|
+
e.noRevAvail = t;
|
|
178
|
+
}
|
|
179
|
+
}), X = defineExtensionDefinition({
|
|
180
|
+
oid: s.subjectKeyIdentifier,
|
|
169
181
|
contexts: ["certificate"],
|
|
170
182
|
defaultCritical: !1,
|
|
171
183
|
autoGenerated: !0,
|
|
172
184
|
decode: (e) => decodeSubjectKeyIdentifier(e),
|
|
173
|
-
encode: (e) =>
|
|
185
|
+
encode: (e) => n(normalizeKeyIdentifier(e)),
|
|
174
186
|
assertProfile: (e, t) => {
|
|
175
|
-
|
|
187
|
+
a(e), u("subjectKeyIdentifier", !1, t);
|
|
176
188
|
},
|
|
177
189
|
applyParsed: (e, t) => {
|
|
178
190
|
e.subjectKeyIdentifier = t;
|
|
179
191
|
}
|
|
180
|
-
}),
|
|
181
|
-
oid:
|
|
192
|
+
}), Z = defineExtensionDefinition({
|
|
193
|
+
oid: s.authorityKeyIdentifier,
|
|
182
194
|
contexts: ["certificate"],
|
|
183
195
|
defaultCritical: !1,
|
|
184
196
|
autoGenerated: !0,
|
|
185
|
-
decode: (e) =>
|
|
186
|
-
encode: (t) =>
|
|
197
|
+
decode: (e) => T(e),
|
|
198
|
+
encode: (t) => i([e(0, normalizeKeyIdentifier(t))]),
|
|
187
199
|
assertProfile: (e, t) => {
|
|
188
|
-
e !== void 0 &&
|
|
200
|
+
e !== void 0 && a(e), u("authorityKeyIdentifier", !1, t);
|
|
189
201
|
},
|
|
190
202
|
applyParsed: (e, t) => {
|
|
191
203
|
t !== void 0 && (e.authorityKeyIdentifier = t);
|
|
192
204
|
}
|
|
193
|
-
}),
|
|
194
|
-
F,
|
|
195
|
-
I,
|
|
205
|
+
}), Q = [
|
|
196
206
|
L,
|
|
197
207
|
R,
|
|
198
208
|
z,
|
|
@@ -204,10 +214,13 @@ const P = /* @__PURE__ */ new Map(), F = defineExtensionDefinition({
|
|
|
204
214
|
G,
|
|
205
215
|
K,
|
|
206
216
|
q,
|
|
207
|
-
J
|
|
208
|
-
|
|
217
|
+
J,
|
|
218
|
+
Y,
|
|
219
|
+
X,
|
|
220
|
+
Z
|
|
221
|
+
], $ = new Map(Q.map((e) => [e.oid, e]));
|
|
209
222
|
function getExtensionDefinition(e) {
|
|
210
|
-
return
|
|
223
|
+
return $.get(e);
|
|
211
224
|
}
|
|
212
225
|
/**
|
|
213
226
|
* If `oid` matches a known extension valid in `context`, decode its DER
|
|
@@ -218,8 +231,8 @@ function getExtensionDefinition(e) {
|
|
|
218
231
|
function decodeAndApplyKnownExtension(e, t, n, r) {
|
|
219
232
|
let i = getExtensionDefinition(t);
|
|
220
233
|
if (i === void 0 || !i.contexts.includes(e)) return !1;
|
|
221
|
-
let a =
|
|
222
|
-
return a
|
|
234
|
+
let a = I.get(t);
|
|
235
|
+
return a !== void 0 && (a(n, r), !0);
|
|
223
236
|
}
|
|
224
237
|
/**
|
|
225
238
|
* Register an {@linkcode ExtensionDefinition} literal, capturing its
|
|
@@ -231,7 +244,7 @@ function decodeAndApplyKnownExtension(e, t, n, r) {
|
|
|
231
244
|
* correlated-union limitation.
|
|
232
245
|
*/
|
|
233
246
|
function defineExtensionDefinition(e) {
|
|
234
|
-
return
|
|
247
|
+
return I.set(e.oid, (t, n) => {
|
|
235
248
|
e.applyParsed(t, e.decode(n));
|
|
236
249
|
}), {
|
|
237
250
|
...e,
|
|
@@ -242,15 +255,20 @@ function defineExtensionDefinition(e) {
|
|
|
242
255
|
}
|
|
243
256
|
/** Accept hex string or Uint8Array and return raw bytes. */
|
|
244
257
|
function normalizeKeyIdentifier(e) {
|
|
245
|
-
return typeof e == "string" ?
|
|
258
|
+
return typeof e == "string" ? a(e) : e;
|
|
259
|
+
}
|
|
260
|
+
/** Decode a noRevAvail extension value, which RFC 9608 §2 defines as NULL. */
|
|
261
|
+
function decodeNoRevAvail(e) {
|
|
262
|
+
let t = r(e, { maxDepth: 64 });
|
|
263
|
+
if (t.tag !== 5 || t.value.length !== 0) throw Error("noRevAvail must be NULL");
|
|
264
|
+
return !0;
|
|
246
265
|
}
|
|
247
266
|
/** Decode an SKI extension value DER to a hex string. */
|
|
248
267
|
function decodeSubjectKeyIdentifier(e) {
|
|
249
|
-
let t =
|
|
268
|
+
let t = r(e, { maxDepth: 64 });
|
|
250
269
|
if (t.tag !== 4) throw Error("SubjectKeyIdentifier must be an OCTET STRING");
|
|
251
|
-
return
|
|
270
|
+
return o(t.value);
|
|
252
271
|
}
|
|
253
|
-
|
|
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 };
|
|
272
|
+
export { q as AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION, Z as AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION, L as BASIC_CONSTRAINTS_EXTENSION_DEFINITION, U as CERTIFICATE_POLICIES_EXTENSION_DEFINITION, Q as CERT_CSR_EXTENSION_DEFINITIONS, J as CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION, z as EXTENDED_KEY_USAGE_EXTENSION_DEFINITION, K as INHIBIT_ANY_POLICY_EXTENSION_DEFINITION, V as ISSUER_ALT_NAME_EXTENSION_DEFINITION, R as KEY_USAGE_EXTENSION_DEFINITION, H as NAME_CONSTRAINTS_EXTENSION_DEFINITION, Y as NO_REV_AVAIL_EXTENSION_DEFINITION, G as POLICY_CONSTRAINTS_EXTENSION_DEFINITION, W as POLICY_MAPPINGS_EXTENSION_DEFINITION, B as SUBJECT_ALT_NAME_EXTENSION_DEFINITION, X as SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION, decodeAndApplyKnownExtension, getExtensionDefinition };
|
|
255
273
|
|
|
256
274
|
//# 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\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;EAC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ASIC_CONSTRAINTS_EXTENSION_DEFINITION","OIDS","parseBasicConstraints","valueDer","encodeBasicConstraints","value","KEY_USAGE_EXTENSION_DEFINITION","parseKeyUsage","encodeKeyUsage","EXTENDED_KEY_USAGE_EXTENSION_DEFINITION","parseExtendedKeyUsage","encodeExtendedKeyUsage","SUBJECT_ALT_NAME_EXTENSION_DEFINITION","parseSubjectAltNames","sequence","encodeSubjectAltName","name","ISSUER_ALT_NAME_EXTENSION_DEFINITION","NAME_CONSTRAINTS_EXTENSION_DEFINITION","parseNameConstraints","encodeNameConstraints","assertNameConstraintsProfile","assertExtensionCriticality","critical","CERTIFICATE_POLICIES_EXTENSION_DEFINITION","parseCertificatePolicies","encodeCertificatePolicies","POLICY_MAPPINGS_EXTENSION_DEFINITION","parsePolicyMappings","encodePolicyMappings","POLICY_CONSTRAINTS_EXTENSION_DEFINITION","parsePolicyConstraints","encodePolicyConstraints","INHIBIT_ANY_POLICY_EXTENSION_DEFINITION","parseInhibitAnyPolicy","encodeInhibitAnyPolicy","AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION","parseAuthorityInfoAccess","encodeAuthorityInfoAccess","assertAuthorityInfoAccessProfile","CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION","parseCrlDistributionPoints","encodeCrlDistributionPoints","NO_REV_AVAIL_EXTENSION_DEFINITION","nullValue","SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION","octetString","hexToBytes","AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION","parseAuthorityKeyIdentifier","implicitPrimitiveContext","CERT_CSR_EXTENSION_DEFINITIONS","EXTENSION_DEFINITION_MAP","definition","oid","context","applier","accumulator","element","readRootElement","toHex"],"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\tnullValue,\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\tassertStoredSubjectAltName,\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/** No Revocation Available (RFC 9608 §2). */\n\treadonly noRevAvail?: true;\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\tassertStoredSubjectAltName(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\tassertStoredSubjectAltName(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 No Revocation Available (OID 2.5.29.56, RFC 9608 §2). Non-critical. */\nexport const NO_REV_AVAIL_EXTENSION_DEFINITION: RegisteredExtensionDefinition<true> =\n\tdefineExtensionDefinition<true>({\n\t\toid: OIDS.noRevAvail,\n\t\tcontexts: ['certificate', 'csr'],\n\t\tdefaultCritical: false,\n\t\tdecode: (valueDer) => decodeNoRevAvail(valueDer),\n\t\tencode: () => nullValue(),\n\t\tassertProfile: (_value, critical) => {\n\t\t\tassertExtensionCriticality('noRevAvail', false, critical);\n\t\t},\n\t\tapplyParsed: (accumulator, value) => {\n\t\t\taccumulator.noRevAvail = value;\n\t\t},\n\t});\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 NO_REV_AVAIL_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\tNO_REV_AVAIL_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 No Revocation Available extension. */\nexport function getExtensionDefinition(\n\toid: typeof OIDS.noRevAvail,\n): typeof NO_REV_AVAIL_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 a noRevAvail extension value, which RFC 9608 §2 defines as NULL. */\nfunction decodeNoRevAvail(valueDer: Uint8Array): true {\n\tconst element = readRootElement(valueDer, { maxDepth: DEFAULT_MAX_DER_DEPTH });\n\tif (element.tag !== 0x05 || element.value.length !== 0) {\n\t\tthrow new Error('noRevAvail must be NULL');\n\t}\n\treturn true;\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":";;;;;;;;;;;;;;;;;;;;;;AAgLA,MAAMA,oBAAoB,IAAI,IAG5B,GAGWC,IACZ,0BAA4C;CAC3C,KAAKC,EAAK;CACV,UAAU,CAAC,eAAe,KAAK;CAC/B,iBAAiB;CACjB,SAAS,MAAaC,EAAsBC,CAAQ;CACpD,SAAS,MAAUC,EAAuBC,CAAK;CAC/C,gBAAgB,MAAU;EACzB,EAAuBA,CAAK;CAC7B;CACA,cAAc,GAAa,MAAU;EACpC,EAAY,mBAAmBA;CAChC;AACD,CAAC,GAGWC,IAGT,0BAAyE;CAC5E,KAAKL,EAAK;CACV,UAAU,CAAC,eAAe,KAAK;CAC/B,iBAAiB;CACjB,SAAS,MAAaM,EAAcJ,CAAQ;CAC5C,SAAS,MAAUK,EAAeH,CAAK;CACvC,gBAAgB,MAAU;EACzB,EAAeA,EAAM,KAAK;CAC3B;CACA,cAAc,GAAa,MAAU;EACpC,EAAY,WAAWA;CACxB;AACD,CAAC,GAGYI,IAET,0BAAuD;CAC1D,KAAKR,EAAK;CACV,UAAU,CAAC,eAAe,KAAK;CAC/B,iBAAiB;CACjB,SAAS,MAAaS,EAAsBP,CAAQ;CACpD,SAAS,MAAUQ,EAAuBN,CAAK;CAC/C,gBAAgB,MAAU;EACzB,EAAuBA,CAAK;CAC7B;CACA,cAAc,GAAa,MAAU;EACpC,EAAY,mBAAmBA;CAChC;AACD,CAAC,GAGYO,IAET,0BAAqD;CACxD,KAAKX,EAAK;CACV,UAAU,CAAC,eAAe,KAAK;CAC/B,iBAAiB;CACjB,SAAS,MAAaY,EAAqBV,CAAQ;CACnD,SAAS,MAAUW,EAAST,EAAM,I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|
+
import { readRootElement as e } from "../asn1/der.js";
|
|
2
|
+
import { checkStrictDer as t, childrenOf as n, decodeString as r } from "../asn1/asn1.js";
|
|
3
|
+
import { domainToAscii as i, presentedDomainToAscii as a } from "../shared/idna.js";
|
|
4
|
+
import { isIpv4Address as o } from "../shared/uri-host.js";
|
|
5
|
+
import { checkOrAddressFields as s } from "./or-address.js";
|
|
6
|
+
// src/internal/x509/general-name-profile.ts
|
|
7
|
+
/**
|
|
8
|
+
* Profile validation for GeneralName alternatives whose content micro509
|
|
9
|
+
* checks beyond DER framing: SRVName (RFC 4985, RFC 6335), the URI name
|
|
10
|
+
* constraint, DirectoryString, EDIPartyName, and ORAddress (RFC 5280).
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
/** U+3002, U+FF0E and U+FF61, the label separators RFC 4985 §3 stores as U+002E. */
|
|
15
|
+
const c = /[。.。]/g;
|
|
16
|
+
/** Replaces each RFC 4985 §3 label separator with U+002E. */
|
|
17
|
+
function normalizeLabelSeparators(e) {
|
|
18
|
+
return e.replace(c, ".");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* RFC 6335 §5.1 service name behind the underscore of a `_Service` label: 1 to
|
|
22
|
+
* 15 letters, digits, and hyphens, at least one letter, and no hyphen at either
|
|
23
|
+
* end or beside another hyphen.
|
|
24
|
+
*/
|
|
25
|
+
function isServiceLabel(e) {
|
|
26
|
+
let t = e.slice(1);
|
|
27
|
+
return e.startsWith("_") && /^[A-Za-z0-9-]{1,15}$/.test(t) && /[A-Za-z]/.test(t) && !t.startsWith("-") && !t.endsWith("-") && !t.includes("--");
|
|
28
|
+
}
|
|
29
|
+
/** RFC 1034 §3.1: an absolute domain name with the dot of its terminal root label removed. */
|
|
30
|
+
function withoutRootLabel(e) {
|
|
31
|
+
return e.endsWith(".") ? e.slice(0, -1) : e;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* RFC 4985 §3 Name under `UseSTD3ASCIIRules`: at most 253 octets of LDH labels
|
|
35
|
+
* of 1 to 63 octets that start and end with a letter or digit, with every
|
|
36
|
+
* `xn--` label an IDNA2008 A-label.
|
|
37
|
+
*/
|
|
38
|
+
function isSrvDomainName(e) {
|
|
39
|
+
return e.length <= 253 && e.split(".").every((e) => /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$/.test(e)) && i(e, "lookup").ok;
|
|
40
|
+
}
|
|
41
|
+
function splitSrvName(e) {
|
|
42
|
+
if (!e.startsWith("_")) return {
|
|
43
|
+
service: "",
|
|
44
|
+
name: withoutRootLabel(e)
|
|
45
|
+
};
|
|
46
|
+
let t = e.indexOf(".");
|
|
47
|
+
return t < 0 ? {
|
|
48
|
+
service: e,
|
|
49
|
+
name: ""
|
|
50
|
+
} : {
|
|
51
|
+
service: e.slice(0, t),
|
|
52
|
+
name: withoutRootLabel(e.slice(t + 1))
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** RFC 4985 §4: a restriction is `_Service.Name`, `_Service`, or `Name`. */
|
|
56
|
+
function parseSrvNameRestriction(e) {
|
|
57
|
+
let t = splitSrvName(e), n = t.service.length === 0 || isServiceLabel(t.service), r = t.service.length > 0 && !e.includes(".") || isSrvDomainName(t.name);
|
|
58
|
+
return n && r ? t : void 0;
|
|
59
|
+
}
|
|
60
|
+
/** RFC 4985 §2: a presented SRVName is `_Service.Name`. */
|
|
61
|
+
function parsePresentedSrvName(e) {
|
|
62
|
+
let t = splitSrvName(e);
|
|
63
|
+
return isServiceLabel(t.service) && isSrvDomainName(t.name) ? t : void 0;
|
|
64
|
+
}
|
|
65
|
+
/** RFC 5280 §4.2.1.10 and Appendix B: a URI constraint holds a DNS name, not a URI. */
|
|
66
|
+
function parseUriNameConstraint(e) {
|
|
67
|
+
if (e.length === 0) return { type: "any" };
|
|
68
|
+
let t = e.startsWith("."), n = /^[\x21-\x7e]+$/.test(e) ? a(t ? e.slice(1) : e) : void 0;
|
|
69
|
+
if (!(n === void 0 || o(n))) return t ? {
|
|
70
|
+
type: "subdomains",
|
|
71
|
+
name: n
|
|
72
|
+
} : {
|
|
73
|
+
type: "host",
|
|
74
|
+
name: n
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const l = { ok: !0 }, u = {
|
|
78
|
+
ok: !1,
|
|
79
|
+
reason: "malformed"
|
|
80
|
+
}, d = {
|
|
81
|
+
ok: !1,
|
|
82
|
+
reason: "unsupported"
|
|
83
|
+
}, f = /* @__PURE__ */ new Set([
|
|
84
|
+
19,
|
|
85
|
+
28,
|
|
86
|
+
12,
|
|
87
|
+
30
|
|
88
|
+
]);
|
|
89
|
+
/** RFC 5280 DirectoryString, each alternative `SIZE (1..MAX)`, with TeletexString unsupported. */
|
|
90
|
+
function checkDirectoryString(e) {
|
|
91
|
+
if (e.tag === 20) return d;
|
|
92
|
+
if (!f.has(e.tag) || e.value.length === 0) return u;
|
|
93
|
+
try {
|
|
94
|
+
return r(e.tag, e.value), l;
|
|
95
|
+
} catch {
|
|
96
|
+
return u;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* RFC 5280 §4.2.1.6: `EDIPartyName ::= SEQUENCE { nameAssigner [0]
|
|
101
|
+
* DirectoryString OPTIONAL, partyName [1] DirectoryString }`, each tag
|
|
102
|
+
* explicit around its CHOICE.
|
|
103
|
+
*/
|
|
104
|
+
function checkEdiPartyName(e) {
|
|
105
|
+
return checkStructuredGeneralName(e, (e, t) => e.at(-1)?.tag !== 161 || !(e.length === 1 || e.length === 2 && e[0]?.tag === 160) ? u : firstFailure(e.map((e) => {
|
|
106
|
+
let r = n(t, e), i = r[0];
|
|
107
|
+
return r.length === 1 && i !== void 0 ? checkDirectoryString(i) : u;
|
|
108
|
+
})));
|
|
109
|
+
}
|
|
110
|
+
/** RFC 5280 Appendix A.1 ORAddress, with its fields checked against their schema. */
|
|
111
|
+
function checkOrAddress(e) {
|
|
112
|
+
return checkStructuredGeneralName(e, s);
|
|
113
|
+
}
|
|
114
|
+
function checkStructuredGeneralName(r, i) {
|
|
115
|
+
let a = t(r);
|
|
116
|
+
if (a === "malformed") return u;
|
|
117
|
+
try {
|
|
118
|
+
let t = i(n(r, e(r)), r);
|
|
119
|
+
return t.ok && a === "unsupported" ? d : t;
|
|
120
|
+
} catch {
|
|
121
|
+
return u;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function firstFailure(e) {
|
|
125
|
+
return e.find((e) => !e.ok) ?? l;
|
|
126
|
+
}
|
|
127
|
+
export { checkDirectoryString, checkEdiPartyName, checkOrAddress, normalizeLabelSeparators, parsePresentedSrvName, parseSrvNameRestriction, parseUriNameConstraint };
|
|
128
|
+
|
|
129
|
+
//# sourceMappingURL=general-name-profile.js.map
|