micro509 0.17.1 → 0.19.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 +165 -6
- package/dist/crypto/crypto.d.ts +12 -4
- package/dist/crypto/crypto.js +30 -17
- package/dist/crypto/crypto.js.map +1 -1
- package/dist/crypto.d.ts +8 -2
- package/dist/der/der.d.ts +14 -4
- package/dist/der/der.js +19 -19
- package/dist/der/der.js.map +1 -1
- package/dist/der.d.ts +26 -2
- package/dist/der.js +4 -4
- package/dist/index.d.ts +84 -16
- package/dist/index.js +19 -19
- package/dist/internal/asn1/asn1.d.ts +1 -2
- package/dist/internal/asn1/asn1.js +10 -2
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/ber.js.map +1 -1
- package/dist/internal/asn1/decode-refusal.js.map +1 -1
- package/dist/internal/asn1/der.d.ts +1 -2
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js +71 -353
- package/dist/internal/asn1/oids.js.map +1 -1
- package/dist/internal/asn1/oids.json.js +357 -0
- package/dist/internal/asn1/oids.json.js.map +1 -0
- package/dist/internal/crypto/algorithm-names.js +1 -1
- package/dist/internal/crypto/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/ecdsa.js.map +1 -1
- package/dist/internal/crypto/hash.js.map +1 -1
- package/dist/internal/crypto/pbes2.d.ts +1 -2
- package/dist/internal/crypto/pbes2.js +70 -70
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/prime-ec.js +37 -0
- package/dist/internal/crypto/prime-ec.js.map +1 -0
- package/dist/internal/crypto/rsa-pss.js +50 -50
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +41 -2
- package/dist/internal/crypto/sig-verify.js +125 -38
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/crypto/signing.d.ts +1 -2
- package/dist/internal/crypto/signing.js +26 -26
- package/dist/internal/crypto/signing.js.map +1 -1
- package/dist/internal/jose/base64url.js.map +1 -1
- package/dist/internal/jose/json-data.js +108 -0
- package/dist/internal/jose/json-data.js.map +1 -0
- package/dist/internal/jose/strict-json.d.ts +1 -2
- package/dist/internal/jose/strict-json.js.map +1 -1
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.d.ts +1 -2
- package/dist/internal/shared/dn.js +1 -1
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/idna.js.map +1 -1
- package/dist/internal/shared/ip.d.ts +1 -2
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/shared/mailbox.js.map +1 -1
- package/dist/internal/shared/punycode.js.map +1 -1
- package/dist/internal/shared/uri-host.js.map +1 -1
- package/dist/internal/verify/name-constraints-engine.js +64 -64
- package/dist/internal/verify/name-constraints-engine.js.map +1 -1
- package/dist/internal/verify/policy-engine.js +1 -1
- package/dist/internal/verify/policy-engine.js.map +1 -1
- package/dist/internal/verify/spki-distrust.js.map +1 -1
- package/dist/internal/verify/verify-path.d.ts +1 -2
- package/dist/internal/verify/verify-path.js +234 -128
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/internal/x509/directory-name.js +10 -10
- package/dist/internal/x509/directory-name.js.map +1 -1
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.d.ts +1 -2
- package/dist/internal/x509/extension-errors.js.map +1 -1
- package/dist/internal/x509/extension-registry.js +18 -18
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-profile.js +9 -9
- package/dist/internal/x509/general-name-profile.js.map +1 -1
- package/dist/internal/x509/general-name.js +32 -32
- package/dist/internal/x509/general-name.js.map +1 -1
- package/dist/internal/x509/name-fields.js +1 -1
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/internal/x509/or-address.js.map +1 -1
- package/dist/jose/base64url.d.ts +4 -0
- package/dist/jose/base64url.js +14 -0
- package/dist/jose/base64url.js.map +1 -0
- package/dist/jose/errors.d.ts +9 -3
- package/dist/jose/errors.js.map +1 -1
- package/dist/jose/jwe.d.ts +64 -0
- package/dist/jose/jwe.js +188 -0
- package/dist/jose/jwe.js.map +1 -0
- package/dist/jose/jwks.d.ts +38 -10
- package/dist/jose/jwks.js +156 -96
- package/dist/jose/jwks.js.map +1 -1
- package/dist/jose/jws.d.ts +8 -6
- package/dist/jose/jws.js +216 -170
- package/dist/jose/jws.js.map +1 -1
- package/dist/jose/jwt.d.ts +8 -2
- package/dist/jose/jwt.js +98 -98
- package/dist/jose/jwt.js.map +1 -1
- package/dist/jose/remote-jwks.d.ts +1 -2
- package/dist/jose/remote-jwks.js +106 -108
- package/dist/jose/remote-jwks.js.map +1 -1
- package/dist/jose.d.ts +15 -4
- package/dist/jose.js +7 -5
- package/dist/kdf/argon2-arithmetic.js.map +1 -1
- package/dist/kdf/argon2-core.js.map +1 -1
- package/dist/kdf/argon2-memory.js.map +1 -1
- package/dist/kdf/argon2-portable.js.map +1 -1
- package/dist/kdf/argon2.d.ts +7 -2
- package/dist/kdf/argon2.js.map +1 -1
- package/dist/kdf.d.ts +6 -0
- package/dist/keys/keys.d.ts +31 -6
- package/dist/keys/keys.js +315 -233
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +11 -2
- package/dist/keys.js +2 -2
- package/dist/pem/pem.d.ts +1 -2
- package/dist/pem/pem.js +40 -25
- package/dist/pem/pem.js.map +1 -1
- package/dist/pem.d.ts +6 -0
- package/dist/pkcs/pfx.d.ts +2 -3
- package/dist/pkcs/pfx.js +142 -142
- package/dist/pkcs/pfx.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.d.ts +1 -2
- package/dist/pkcs/pkcs12-mac.js +122 -122
- package/dist/pkcs/pkcs12-mac.js.map +1 -1
- package/dist/pkcs/pkcs7.d.ts +24 -3
- package/dist/pkcs/pkcs7.js +294 -256
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +10 -1
- package/dist/pkcs.js +4 -4
- package/dist/result/result.d.ts +1 -2
- package/dist/result/result.js.map +1 -1
- package/dist/result.d.ts +6 -0
- package/dist/revocation/chain.d.ts +69 -16
- package/dist/revocation/chain.js +431 -303
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +67 -14
- package/dist/revocation/crl.js +656 -366
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +78 -24
- package/dist/revocation/ocsp.js +622 -436
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +68 -14
- package/dist/revocation/revocation.js +195 -74
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +14 -5
- package/dist/revocation.js +4 -4
- package/dist/ssh/ssh.d.ts +2 -3
- package/dist/ssh/ssh.js +165 -170
- package/dist/ssh/ssh.js.map +1 -1
- package/dist/ssh/wire.d.ts +1 -2
- package/dist/ssh/wire.js +10 -10
- package/dist/ssh/wire.js.map +1 -1
- package/dist/ssh.d.ts +8 -0
- package/dist/verify/identity.d.ts +3 -4
- package/dist/verify/identity.js +33 -33
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/name-constraints.d.ts +9 -2
- package/dist/verify/policy.d.ts +9 -2
- package/dist/verify/verify.d.ts +85 -34
- package/dist/verify/verify.js +276 -226
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +12 -2
- package/dist/x509/certificate.d.ts +4 -5
- package/dist/x509/certificate.js +40 -40
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.d.ts +3 -4
- package/dist/x509/csr.js +15 -15
- package/dist/x509/csr.js.map +1 -1
- package/dist/x509/extensions.d.ts +1 -2
- package/dist/x509/extensions.js +165 -165
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.d.ts +1 -2
- package/dist/x509/fingerprint.js.map +1 -1
- package/dist/x509/name-text.d.ts +1 -2
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.d.ts +1 -2
- package/dist/x509/name.js +15 -15
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +9 -6
- package/dist/x509/parse.js +394 -394
- package/dist/x509/parse.js.map +1 -1
- package/dist/x509.d.ts +17 -4
- package/dist/x509.js +8 -8
- package/package.json +32 -33
- package/dist/internal/asn1/oids2.js +0 -75
- package/dist/internal/asn1/oids2.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { nullValue as e, objectIdentifier as t, sequence as n } from "../asn1/der.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { OIDS as r } from "../asn1/oids.js";
|
|
3
|
+
import { ecdsaSignatureToDer as i } from "./ecdsa.js";
|
|
4
4
|
import { encodeRsaPssParameters as a, rsaPssParametersForHash as o } from "./rsa-pss.js";
|
|
5
5
|
import { getCrypto as s } from "./webcrypto.js";
|
|
6
6
|
// src/internal/crypto/signing.ts
|
|
@@ -12,35 +12,35 @@ import { getCrypto as s } from "./webcrypto.js";
|
|
|
12
12
|
*/
|
|
13
13
|
/** Resolve a private key and optional profile into a {@linkcode SignatureAlgorithmIdentifier}. */
|
|
14
14
|
function getSignatureAlgorithm(t, n = {}) {
|
|
15
|
-
let
|
|
15
|
+
let i = t.algorithm;
|
|
16
16
|
if (n.kind === "rsa-pss") return getRsaPssSignatureAlgorithm(t, n.saltLength);
|
|
17
|
-
if (
|
|
18
|
-
if (!hasHash(
|
|
19
|
-
switch (
|
|
17
|
+
if (i.name === "RSASSA-PKCS1-v1_5") {
|
|
18
|
+
if (!hasHash(i)) throw Error("RSA key is missing hash metadata");
|
|
19
|
+
switch (i.hash.name) {
|
|
20
20
|
case "SHA-256": return {
|
|
21
|
-
algorithmOid:
|
|
21
|
+
algorithmOid: r.sha256WithRSAEncryption,
|
|
22
22
|
parameters: e(),
|
|
23
23
|
signParams: { name: "RSASSA-PKCS1-v1_5" }
|
|
24
24
|
};
|
|
25
25
|
case "SHA-384": return {
|
|
26
|
-
algorithmOid:
|
|
26
|
+
algorithmOid: r.sha384WithRSAEncryption,
|
|
27
27
|
parameters: e(),
|
|
28
28
|
signParams: { name: "RSASSA-PKCS1-v1_5" }
|
|
29
29
|
};
|
|
30
30
|
case "SHA-512": return {
|
|
31
|
-
algorithmOid:
|
|
31
|
+
algorithmOid: r.sha512WithRSAEncryption,
|
|
32
32
|
parameters: e(),
|
|
33
33
|
signParams: { name: "RSASSA-PKCS1-v1_5" }
|
|
34
34
|
};
|
|
35
|
-
default: throw Error(`Unsupported RSA hash: ${
|
|
35
|
+
default: throw Error(`Unsupported RSA hash: ${i.hash.name}`);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
if (
|
|
39
|
-
if (
|
|
40
|
-
if (!hasNamedCurve(
|
|
41
|
-
switch (
|
|
38
|
+
if (i.name === "RSA-PSS") throw Error("RSA-PSS signing requires an explicit signature profile");
|
|
39
|
+
if (i.name === "ECDSA") {
|
|
40
|
+
if (!hasNamedCurve(i)) throw Error("ECDSA key is missing namedCurve metadata");
|
|
41
|
+
switch (i.namedCurve) {
|
|
42
42
|
case "P-256": return {
|
|
43
|
-
algorithmOid:
|
|
43
|
+
algorithmOid: r.ecdsaWithSHA256,
|
|
44
44
|
signParams: {
|
|
45
45
|
name: "ECDSA",
|
|
46
46
|
hash: "SHA-256"
|
|
@@ -48,7 +48,7 @@ function getSignatureAlgorithm(t, n = {}) {
|
|
|
48
48
|
ecdsaRawSignatureBytes: 64
|
|
49
49
|
};
|
|
50
50
|
case "P-384": return {
|
|
51
|
-
algorithmOid:
|
|
51
|
+
algorithmOid: r.ecdsaWithSHA384,
|
|
52
52
|
signParams: {
|
|
53
53
|
name: "ECDSA",
|
|
54
54
|
hash: "SHA-384"
|
|
@@ -56,31 +56,31 @@ function getSignatureAlgorithm(t, n = {}) {
|
|
|
56
56
|
ecdsaRawSignatureBytes: 96
|
|
57
57
|
};
|
|
58
58
|
case "P-521": return {
|
|
59
|
-
algorithmOid:
|
|
59
|
+
algorithmOid: r.ecdsaWithSHA512,
|
|
60
60
|
signParams: {
|
|
61
61
|
name: "ECDSA",
|
|
62
62
|
hash: "SHA-512"
|
|
63
63
|
},
|
|
64
64
|
ecdsaRawSignatureBytes: 132
|
|
65
65
|
};
|
|
66
|
-
default: throw Error(`Unsupported curve: ${
|
|
66
|
+
default: throw Error(`Unsupported curve: ${i.namedCurve}`);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
if (
|
|
70
|
-
algorithmOid:
|
|
69
|
+
if (i.name === "Ed25519") return {
|
|
70
|
+
algorithmOid: r.ed25519,
|
|
71
71
|
signParams: { name: "Ed25519" }
|
|
72
72
|
};
|
|
73
|
-
throw Error(`Unsupported signing key algorithm: ${
|
|
73
|
+
throw Error(`Unsupported signing key algorithm: ${i.name}`);
|
|
74
74
|
}
|
|
75
75
|
/** Build an RSA-PSS {@linkcode SignatureAlgorithmIdentifier} from an RSA-PSS private key. */
|
|
76
76
|
function getRsaPssSignatureAlgorithm(e, t) {
|
|
77
77
|
let n = e.algorithm;
|
|
78
78
|
if (n.name !== "RSA-PSS") throw Error("RSA-PSS signature profile requires an RSA-PSS private key");
|
|
79
79
|
if (!hasHash(n)) throw Error("RSA-PSS key is missing hash metadata");
|
|
80
|
-
let
|
|
81
|
-
if (t !== void 0 && t !== s.saltLength) throw Error(`Unsupported RSA-PSS saltLength ${t} for ${
|
|
80
|
+
let i = rsaPssHashFromWebCryptoName(n.hash.name), s = o(i);
|
|
81
|
+
if (t !== void 0 && t !== s.saltLength) throw Error(`Unsupported RSA-PSS saltLength ${t} for ${i}; expected ${s.saltLength}`);
|
|
82
82
|
return {
|
|
83
|
-
algorithmOid:
|
|
83
|
+
algorithmOid: r.rsassaPss,
|
|
84
84
|
parameters: a(s),
|
|
85
85
|
signParams: {
|
|
86
86
|
name: "RSA-PSS",
|
|
@@ -95,8 +95,8 @@ function encodeAlgorithmIdentifier(e) {
|
|
|
95
95
|
}
|
|
96
96
|
/** Sign `data` and return a DER-encoded signature. ECDSA raw signatures are auto-converted to DER. */
|
|
97
97
|
async function signBytes(e, t, n) {
|
|
98
|
-
let
|
|
99
|
-
return t.ecdsaRawSignatureBytes === void 0 ? a :
|
|
98
|
+
let r = new Uint8Array(n), a = new Uint8Array(await s().subtle.sign(t.signParams, e, r));
|
|
99
|
+
return t.ecdsaRawSignatureBytes === void 0 ? a : i(a, t.ecdsaRawSignatureBytes);
|
|
100
100
|
}
|
|
101
101
|
/** Type guard: does this key algorithm carry a `hash` property (RSA keys). */
|
|
102
102
|
function hasHash(e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signing.js","names":["
|
|
1
|
+
{"version":3,"file":"signing.js","names":["nullValue","objectIdentifier","sequence","OIDS","ecdsaSignatureToDer","encodeRsaPssParameters","rsaPssParametersForHash","getCrypto","privateKey","profile","algorithm","saltLength","hash","parameters","input","parts","data","view","signature"],"sources":["../../../src/internal/crypto/signing.ts"],"sourcesContent":["/**\n * Signing helpers that map WebCrypto keys and signature profiles to on-wire\n * `AlgorithmIdentifier` values. Used by certificate and CSR builders.\n *\n * @module\n */\n\nimport { nullValue, objectIdentifier, sequence } from '#micro509/internal/asn1/der';\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport { ecdsaSignatureToDer } from '#micro509/internal/crypto/ecdsa';\nimport type { RsaPssHash } from '#micro509/internal/crypto/rsa-pss';\nimport { encodeRsaPssParameters, rsaPssParametersForHash } from '#micro509/internal/crypto/rsa-pss';\nimport { getCrypto } from '#micro509/internal/crypto/webcrypto';\n\n/**\n * Controls how the signature algorithm is chosen.\n *\n * `'auto'` (default) infers the algorithm from the key. `'rsa-pss'` forces RSA-PSS\n * padding and requires an RSA-PSS private key.\n */\nexport type SignatureProfileInput =\n\t| {\n\t\t\t/** Infer the signature algorithm from the private key. */\n\t\t\treadonly kind?: 'auto';\n\t }\n\t| {\n\t\t\t/** Force RSA-PSS padding. */\n\t\t\treadonly kind: 'rsa-pss';\n\t\t\t/** Salt length in bytes. Must match the key's hash digest size. */\n\t\t\treadonly saltLength?: 32 | 48 | 64;\n\t };\n\n/** Resolved signature algorithm: the OID/parameters for DER encoding and the WebCrypto sign params. */\nexport interface SignatureAlgorithmIdentifier {\n\t/** ASN.1 OID of the signature algorithm (e.g. sha256WithRSAEncryption). */\n\treadonly algorithmOid: string;\n\t/** DER-encoded algorithm parameters, if the algorithm requires them (e.g. RSA-PSS). */\n\treadonly parameters?: Uint8Array;\n\t/** WebCrypto `sign()` algorithm parameter. */\n\treadonly signParams: Algorithm | EcdsaParams | RsaPssParams;\n\t/** When set, the raw ECDSA signature is this many bytes and must be DER-converted. */\n\treadonly ecdsaRawSignatureBytes?: number;\n}\n\n/** Resolve a private key and optional profile into a {@linkcode SignatureAlgorithmIdentifier}. */\nexport function getSignatureAlgorithm(\n\tprivateKey: CryptoKey,\n\tprofile: SignatureProfileInput = {},\n): SignatureAlgorithmIdentifier {\n\tconst algorithm = privateKey.algorithm;\n\tif (profile.kind === 'rsa-pss') {\n\t\treturn getRsaPssSignatureAlgorithm(privateKey, profile.saltLength);\n\t}\n\tif (algorithm.name === 'RSASSA-PKCS1-v1_5') {\n\t\tif (!hasHash(algorithm)) {\n\t\t\tthrow new Error('RSA key is missing hash metadata');\n\t\t}\n\t\tswitch (algorithm.hash.name) {\n\t\t\tcase 'SHA-256':\n\t\t\t\treturn {\n\t\t\t\t\talgorithmOid: OIDS.sha256WithRSAEncryption,\n\t\t\t\t\tparameters: nullValue(),\n\t\t\t\t\tsignParams: { name: 'RSASSA-PKCS1-v1_5' },\n\t\t\t\t};\n\t\t\tcase 'SHA-384':\n\t\t\t\treturn {\n\t\t\t\t\talgorithmOid: OIDS.sha384WithRSAEncryption,\n\t\t\t\t\tparameters: nullValue(),\n\t\t\t\t\tsignParams: { name: 'RSASSA-PKCS1-v1_5' },\n\t\t\t\t};\n\t\t\tcase 'SHA-512':\n\t\t\t\treturn {\n\t\t\t\t\talgorithmOid: OIDS.sha512WithRSAEncryption,\n\t\t\t\t\tparameters: nullValue(),\n\t\t\t\t\tsignParams: { name: 'RSASSA-PKCS1-v1_5' },\n\t\t\t\t};\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unsupported RSA hash: ${algorithm.hash.name}`);\n\t\t}\n\t}\n\n\tif (algorithm.name === 'RSA-PSS') {\n\t\tthrow new Error('RSA-PSS signing requires an explicit signature profile');\n\t}\n\n\tif (algorithm.name === 'ECDSA') {\n\t\tif (!hasNamedCurve(algorithm)) {\n\t\t\tthrow new Error('ECDSA key is missing namedCurve metadata');\n\t\t}\n\t\tswitch (algorithm.namedCurve) {\n\t\t\tcase 'P-256':\n\t\t\t\treturn {\n\t\t\t\t\talgorithmOid: OIDS.ecdsaWithSHA256,\n\t\t\t\t\tsignParams: { name: 'ECDSA', hash: 'SHA-256' },\n\t\t\t\t\tecdsaRawSignatureBytes: 64,\n\t\t\t\t};\n\t\t\tcase 'P-384':\n\t\t\t\treturn {\n\t\t\t\t\talgorithmOid: OIDS.ecdsaWithSHA384,\n\t\t\t\t\tsignParams: { name: 'ECDSA', hash: 'SHA-384' },\n\t\t\t\t\tecdsaRawSignatureBytes: 96,\n\t\t\t\t};\n\t\t\tcase 'P-521':\n\t\t\t\treturn {\n\t\t\t\t\talgorithmOid: OIDS.ecdsaWithSHA512,\n\t\t\t\t\tsignParams: { name: 'ECDSA', hash: 'SHA-512' },\n\t\t\t\t\tecdsaRawSignatureBytes: 132,\n\t\t\t\t};\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unsupported curve: ${algorithm.namedCurve}`);\n\t\t}\n\t}\n\n\tif (algorithm.name === 'Ed25519') {\n\t\treturn {\n\t\t\talgorithmOid: OIDS.ed25519,\n\t\t\tsignParams: { name: 'Ed25519' },\n\t\t};\n\t}\n\n\tthrow new Error(`Unsupported signing key algorithm: ${algorithm.name}`);\n}\n\n/** Build an RSA-PSS {@linkcode SignatureAlgorithmIdentifier} from an RSA-PSS private key. */\nfunction getRsaPssSignatureAlgorithm(\n\tprivateKey: CryptoKey,\n\tsaltLength: number | undefined,\n): SignatureAlgorithmIdentifier {\n\tconst algorithm = privateKey.algorithm;\n\tif (algorithm.name !== 'RSA-PSS') {\n\t\tthrow new Error('RSA-PSS signature profile requires an RSA-PSS private key');\n\t}\n\tif (!hasHash(algorithm)) {\n\t\tthrow new Error('RSA-PSS key is missing hash metadata');\n\t}\n\tconst hash = rsaPssHashFromWebCryptoName(algorithm.hash.name);\n\tconst parameters = rsaPssParametersForHash(hash);\n\tif (saltLength !== undefined && saltLength !== parameters.saltLength) {\n\t\tthrow new Error(\n\t\t\t`Unsupported RSA-PSS saltLength ${saltLength} for ${hash}; expected ${parameters.saltLength}`,\n\t\t);\n\t}\n\treturn {\n\t\talgorithmOid: OIDS.rsassaPss,\n\t\tparameters: encodeRsaPssParameters(parameters),\n\t\tsignParams: {\n\t\t\tname: 'RSA-PSS',\n\t\t\tsaltLength: parameters.saltLength,\n\t\t},\n\t};\n}\n\n/** DER-encode a {@linkcode SignatureAlgorithmIdentifier} as an ASN.1 `AlgorithmIdentifier` SEQUENCE. */\nexport function encodeAlgorithmIdentifier(input: SignatureAlgorithmIdentifier): Uint8Array {\n\tconst parts = [objectIdentifier(input.algorithmOid)];\n\tif (input.parameters !== undefined) {\n\t\tparts.push(input.parameters);\n\t}\n\treturn sequence(parts);\n}\n\n/** Sign `data` and return a DER-encoded signature. ECDSA raw signatures are auto-converted to DER. */\nexport async function signBytes(\n\tprivateKey: CryptoKey,\n\talgorithm: SignatureAlgorithmIdentifier,\n\tdata: Uint8Array,\n): Promise<Uint8Array> {\n\tconst view = new Uint8Array(data);\n\tconst signature = new Uint8Array(\n\t\tawait getCrypto().subtle.sign(algorithm.signParams, privateKey, view),\n\t);\n\tif (algorithm.ecdsaRawSignatureBytes !== undefined) {\n\t\treturn ecdsaSignatureToDer(signature, algorithm.ecdsaRawSignatureBytes);\n\t}\n\treturn signature;\n}\n\n/** Type guard: does this key algorithm carry a `hash` property (RSA keys). */\nfunction hasHash(algorithm: KeyAlgorithm): algorithm is RsaHashedKeyAlgorithm {\n\treturn 'hash' in algorithm;\n}\n\n/** Type guard: does this key algorithm carry a `namedCurve` property (EC keys). */\nfunction hasNamedCurve(algorithm: KeyAlgorithm): algorithm is EcKeyAlgorithm {\n\treturn 'namedCurve' in algorithm;\n}\n\n/** Narrow a WebCrypto hash name string to the supported {@linkcode RsaPssHash} union. */\nfunction rsaPssHashFromWebCryptoName(hash: string): RsaPssHash {\n\tswitch (hash) {\n\t\tcase 'SHA-256':\n\t\t\treturn 'SHA-256';\n\t\tcase 'SHA-384':\n\t\t\treturn 'SHA-384';\n\t\tcase 'SHA-512':\n\t\t\treturn 'SHA-512';\n\t\tdefault:\n\t\t\tthrow new Error(`Unsupported RSA hash: ${hash}`);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;AA6CA,SAAgB,sBACfQ,GACAC,IAAiC,CAAC,GACH;CAC/B,IAAMC,IAAYF,EAAW;CAC7B,IAAIC,EAAQ,SAAS,WACpB,OAAO,4BAA4BD,GAAYC,EAAQ,UAAU;CAElE,IAAIC,EAAU,SAAS,qBAAqB;EAC3C,IAAI,CAAC,QAAQA,CAAS,GACrB,MAAU,MAAM,kCAAkC;EAEnD,QAAQA,EAAU,KAAK,MAAvB;GACC,KAAK,WACJ,OAAO;IACN,cAAcP,EAAK;IACnB,YAAYH,EAAU;IACtB,YAAY,EAAE,MAAM,oBAAoB;GACzC;GACD,KAAK,WACJ,OAAO;IACN,cAAcG,EAAK;IACnB,YAAYH,EAAU;IACtB,YAAY,EAAE,MAAM,oBAAoB;GACzC;GACD,KAAK,WACJ,OAAO;IACN,cAAcG,EAAK;IACnB,YAAYH,EAAU;IACtB,YAAY,EAAE,MAAM,oBAAoB;GACzC;GACD,SACC,MAAU,MAAM,yBAAyBU,EAAU,KAAK,MAAM;EAChE;CACD;CAEA,IAAIA,EAAU,SAAS,WACtB,MAAU,MAAM,wDAAwD;CAGzE,IAAIA,EAAU,SAAS,SAAS;EAC/B,IAAI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B;;AAGA,eAAsB,UACrBP,GACAE,GACAM,GACsB;CACtB,IAAMC,IAAO,IAAI,WAAWD,CAAI,GAC1BE,IAAY,IAAI,WACrB,MAAMX,EAAU,CAAC,CAAC,OAAO,KAAKG,EAAU,YAAYF,GAAYS,CAAI,CACrE;CAIA,OAHIP,EAAU,2BAA2B,KAAA,IAGlCQ,IAFCd,EAAoBc,GAAWR,EAAU,sBAAsB;AAGxE;;AAGA,SAAS,QAAQA,GAA6D;CAC7E,OAAO,UAAUA;AAClB;;AAGA,SAAS,cAAcA,GAAsD;CAC5E,OAAO,gBAAgBA;AACxB;;AAGA,SAAS,4BAA4BE,GAA0B;CAC9D,QAAQA,GAAR;EACC,KAAK,WACJ,OAAO;EACR,KAAK,WACJ,OAAO;EACR,KAAK,WACJ,OAAO;EACR,SACC,MAAU,MAAM,yBAAyBA,GAAM;CACjD;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64url.js","names":["ALPHABET","DECODE_TABLE","table","index","
|
|
1
|
+
{"version":3,"file":"base64url.js","names":["ALPHABET","DECODE_TABLE","table","index","bytes","out","chunk","remaining","value","written","buffer","bits","code","sextet"],"sources":["../../../src/internal/jose/base64url.ts"],"sourcesContent":["const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';\n\nconst DECODE_TABLE: Int8Array = (() => {\n\tconst table = new Int8Array(128).fill(-1);\n\tfor (let index = 0; index < ALPHABET.length; index++) {\n\t\ttable[ALPHABET.charCodeAt(index)] = index;\n\t}\n\treturn table;\n})();\n\n/** Encodes bytes as unpadded base64url (RFC 4648 §5, RFC 7515 §2). */\nexport function base64UrlEncode(bytes: Uint8Array): string {\n\tlet out = '';\n\tlet index = 0;\n\tfor (; index + 2 < bytes.length; index += 3) {\n\t\tconst chunk =\n\t\t\t(bytes[index] ?? 0) * 65536 + (bytes[index + 1] ?? 0) * 256 + (bytes[index + 2] ?? 0);\n\t\tout += ALPHABET[(chunk >> 18) & 63] ?? '';\n\t\tout += ALPHABET[(chunk >> 12) & 63] ?? '';\n\t\tout += ALPHABET[(chunk >> 6) & 63] ?? '';\n\t\tout += ALPHABET[chunk & 63] ?? '';\n\t}\n\tconst remaining = bytes.length - index;\n\tif (remaining === 1) {\n\t\tconst chunk = (bytes[index] ?? 0) * 65536;\n\t\tout += ALPHABET[(chunk >> 18) & 63] ?? '';\n\t\tout += ALPHABET[(chunk >> 12) & 63] ?? '';\n\t} else if (remaining === 2) {\n\t\tconst chunk = (bytes[index] ?? 0) * 65536 + (bytes[index + 1] ?? 0) * 256;\n\t\tout += ALPHABET[(chunk >> 18) & 63] ?? '';\n\t\tout += ALPHABET[(chunk >> 12) & 63] ?? '';\n\t\tout += ALPHABET[(chunk >> 6) & 63] ?? '';\n\t}\n\treturn out;\n}\n\n/**\n * Decodes canonical unpadded base64url. Returns `undefined` for any character outside the URL-safe\n * alphabet, padding, whitespace, an impossible length, or non-zero trailing bits.\n */\nexport function base64UrlDecode(value: string): Uint8Array | undefined {\n\tconst remainder = value.length % 4;\n\tif (remainder === 1) return undefined;\n\tconst bytes = new Uint8Array(Math.floor((value.length * 3) / 4));\n\tlet written = 0;\n\tlet buffer = 0;\n\tlet bits = 0;\n\tfor (let index = 0; index < value.length; index++) {\n\t\tconst code = value.charCodeAt(index);\n\t\tconst sextet = code < 128 ? (DECODE_TABLE[code] ?? -1) : -1;\n\t\tif (sextet < 0) return undefined;\n\t\tbuffer = (buffer << 6) | sextet;\n\t\tbits += 6;\n\t\tif (bits >= 8) {\n\t\t\tbits -= 8;\n\t\t\tbytes[written++] = (buffer >> bits) & 0xff;\n\t\t\tbuffer &= (1 << bits) - 1;\n\t\t}\n\t}\n\tif (buffer !== 0) return undefined;\n\treturn bytes;\n}\n"],"mappings":";AAAA,MAAMA,IAAW,oEAEXC,WAAiC;CACtC,IAAMC,qBAAQ,IAAI,UAAU,GAAG,EAAA,CAAE,KAAK,EAAE;CACxC,KAAK,IA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AAM;EACzD,IAAIC,IAAS,GAAG;EAChBH,IAAUA,KAAU,IAAKG,GACzBF,KAAQ,GACJA,KAAQ,MACXA,KAAQ,GACRP,EAAMK,OAAcC,KAAUC,IAAQ,KACtCD,MAAW,KAAKC,KAAQ;CAE1B;CACA,IAAID,MAAW,GACf,OAAON;AACR"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// src/internal/jose/json-data.ts
|
|
2
|
+
const e = Symbol("JSON data refusal");
|
|
3
|
+
function refuse(t) {
|
|
4
|
+
throw {
|
|
5
|
+
marker: e,
|
|
6
|
+
code: t
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function isRefusal(t) {
|
|
10
|
+
return typeof t == "object" && !!t && "marker" in t && t.marker === e;
|
|
11
|
+
}
|
|
12
|
+
function bytes(e, t) {
|
|
13
|
+
e.bytes += t, e.bytes > e.maxBytes && refuse("limit_exceeded");
|
|
14
|
+
}
|
|
15
|
+
function node(e) {
|
|
16
|
+
++e.nodes > e.maxNodes && refuse("limit_exceeded");
|
|
17
|
+
}
|
|
18
|
+
/** Counts the UTF-8 bytes of the shortest JSON string spelling without allocating it. */
|
|
19
|
+
function string(e, t) {
|
|
20
|
+
t.length > e.maxBytes - e.bytes && refuse("limit_exceeded"), bytes(e, 2);
|
|
21
|
+
for (let n = 0; n < t.length; n++) {
|
|
22
|
+
let r = t.charCodeAt(n);
|
|
23
|
+
if (r >= 55296 && r <= 56319) {
|
|
24
|
+
let r = t.charCodeAt(++n);
|
|
25
|
+
r >= 56320 && r <= 57343 || refuse("invalid_json"), bytes(e, 4);
|
|
26
|
+
} else bytes(e, characterBytes(r));
|
|
27
|
+
}
|
|
28
|
+
return t;
|
|
29
|
+
}
|
|
30
|
+
function characterBytes(e) {
|
|
31
|
+
return e >= 56320 && e <= 57343 && refuse("invalid_json"), e === 34 || e === 92 ? 2 : e < 32 ? [
|
|
32
|
+
8,
|
|
33
|
+
9,
|
|
34
|
+
10,
|
|
35
|
+
12,
|
|
36
|
+
13
|
|
37
|
+
].includes(e) ? 2 : 6 : e < 128 ? 1 : e < 2048 ? 2 : 3;
|
|
38
|
+
}
|
|
39
|
+
/** Reflection can execute proxy traps or encounter a revoked proxy; that is an input refusal. */
|
|
40
|
+
function inspect(e) {
|
|
41
|
+
try {
|
|
42
|
+
return e();
|
|
43
|
+
} catch {
|
|
44
|
+
return refuse("invalid_json");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function arrayLength(e, t) {
|
|
48
|
+
let n = inspect(() => Object.getOwnPropertyDescriptor(e, "length"))?.value;
|
|
49
|
+
return (typeof n != "number" || !Number.isSafeInteger(n) || n < 0) && refuse("invalid_json"), n > t.maxNodes - t.nodes && refuse("limit_exceeded"), n;
|
|
50
|
+
}
|
|
51
|
+
function dataMember(e, t) {
|
|
52
|
+
let n = inspect(() => Object.getOwnPropertyDescriptor(e, t));
|
|
53
|
+
return n !== void 0 && "value" in n && n.enumerable || refuse("invalid_json"), n.value;
|
|
54
|
+
}
|
|
55
|
+
function checkPrototype(e, t) {
|
|
56
|
+
let n = inspect(() => Object.getPrototypeOf(e));
|
|
57
|
+
(t ? n !== Array.prototype : n !== null && n !== Object.prototype) && refuse("invalid_json");
|
|
58
|
+
}
|
|
59
|
+
function copy(e, t, n) {
|
|
60
|
+
if (node(t), e === null || typeof e == "boolean") return bytes(t, e === null || e ? 4 : 5), e;
|
|
61
|
+
if (typeof e == "string") return string(t, e);
|
|
62
|
+
if (typeof e == "number") return Number.isFinite(e) || refuse("invalid_json"), bytes(t, String(e).length), e;
|
|
63
|
+
typeof e != "object" && refuse("invalid_json"), n >= t.maxDepth && refuse("limit_exceeded"), t.active.has(e) && refuse("invalid_json");
|
|
64
|
+
let r = inspect(() => Array.isArray(e));
|
|
65
|
+
checkPrototype(e, r), t.active.add(e), r && arrayLength(e, t);
|
|
66
|
+
let i = inspect(() => Reflect.ownKeys(e));
|
|
67
|
+
i.length > t.maxNodes - t.nodes + +!!r && refuse("limit_exceeded"), bytes(t, 2);
|
|
68
|
+
let a = r ? copyArray(e, i, t, n) : copyObject(e, i, t, n);
|
|
69
|
+
return t.active.delete(e), a;
|
|
70
|
+
}
|
|
71
|
+
function copyArray(e, t, n, r) {
|
|
72
|
+
let i = arrayLength(e, n);
|
|
73
|
+
t.length !== i + 1 && refuse("invalid_json");
|
|
74
|
+
let a = [];
|
|
75
|
+
for (let t = 0; t < i; t++) t > 0 && bytes(n, 1), a.push(copy(dataMember(e, String(t)), n, r + 1));
|
|
76
|
+
return Object.freeze(a);
|
|
77
|
+
}
|
|
78
|
+
function copyObject(e, t, n, r) {
|
|
79
|
+
let i = {};
|
|
80
|
+
for (let [a, o] of t.entries()) typeof o != "string" && refuse("invalid_json"), node(n), string(n, o), bytes(n, a > 0 ? 2 : 1), Object.defineProperty(i, o, {
|
|
81
|
+
value: copy(dataMember(e, o), n, r + 1),
|
|
82
|
+
enumerable: !0
|
|
83
|
+
});
|
|
84
|
+
return Object.freeze(i);
|
|
85
|
+
}
|
|
86
|
+
/** Copies plain JSON data without invoking getters, coercion or `toJSON`. */
|
|
87
|
+
function snapshotJsonData(e, t) {
|
|
88
|
+
try {
|
|
89
|
+
return {
|
|
90
|
+
ok: !0,
|
|
91
|
+
value: copy(e, {
|
|
92
|
+
...t,
|
|
93
|
+
bytes: 0,
|
|
94
|
+
nodes: 0,
|
|
95
|
+
active: /* @__PURE__ */ new Set()
|
|
96
|
+
}, 0)
|
|
97
|
+
};
|
|
98
|
+
} catch (e) {
|
|
99
|
+
if (isRefusal(e)) return {
|
|
100
|
+
ok: !1,
|
|
101
|
+
code: e.code
|
|
102
|
+
};
|
|
103
|
+
throw e;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export { snapshotJsonData };
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=json-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-data.js","names":["refusalMarker","code","value","budget","size","i","c","next","operation","length","name","descriptor","array","prototype","depth","names","result","items","record","limits","error"],"sources":["../../../src/internal/jose/json-data.ts"],"sourcesContent":["/** Bounded, descriptor-based snapshots of an already parsed JSON data model. @module */\n\nimport type { JsonValue } from '#micro509/internal/jose/strict-json';\n\ninterface Budget {\n\tbytes: number;\n\tnodes: number;\n\treadonly maxBytes: number;\n\treadonly maxNodes: number;\n\treadonly maxDepth: number;\n\treadonly active: Set<object>;\n}\n\ninterface Refusal {\n\treadonly marker: typeof refusalMarker;\n\treadonly code: 'invalid_json' | 'limit_exceeded';\n}\nconst refusalMarker: unique symbol = Symbol('JSON data refusal');\n\nfunction refuse(code: Refusal['code']): never {\n\tthrow { marker: refusalMarker, code } satisfies Refusal;\n}\nfunction isRefusal(value: unknown): value is Refusal {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\t'marker' in value &&\n\t\tvalue.marker === refusalMarker\n\t);\n}\nfunction bytes(budget: Budget, size: number): void {\n\tbudget.bytes += size;\n\tif (budget.bytes > budget.maxBytes) refuse('limit_exceeded');\n}\nfunction node(budget: Budget): void {\n\tif (++budget.nodes > budget.maxNodes) refuse('limit_exceeded');\n}\n/** Counts the UTF-8 bytes of the shortest JSON string spelling without allocating it. */\nfunction string(budget: Budget, value: string): string {\n\tif (value.length > budget.maxBytes - budget.bytes) refuse('limit_exceeded');\n\tbytes(budget, 2);\n\tfor (let i = 0; i < value.length; i++) {\n\t\tconst c = value.charCodeAt(i);\n\t\tif (c >= 0xd800 && c <= 0xdbff) {\n\t\t\tconst next = value.charCodeAt(++i);\n\t\t\tif (!(next >= 0xdc00 && next <= 0xdfff)) refuse('invalid_json');\n\t\t\tbytes(budget, 4);\n\t\t} else bytes(budget, characterBytes(c));\n\t}\n\treturn value;\n}\nfunction characterBytes(c: number): number {\n\tif (c >= 0xdc00 && c <= 0xdfff) refuse('invalid_json');\n\tif (c === 0x22 || c === 0x5c) return 2;\n\tif (c < 0x20) return [8, 9, 10, 12, 13].includes(c) ? 2 : 6;\n\treturn c < 0x80 ? 1 : c < 0x800 ? 2 : 3;\n}\n/** Reflection can execute proxy traps or encounter a revoked proxy; that is an input refusal. */\nfunction inspect<T>(operation: () => T): T {\n\ttry {\n\t\treturn operation();\n\t} catch {\n\t\treturn refuse('invalid_json');\n\t}\n}\nfunction arrayLength(value: object, budget: Budget): number {\n\tconst descriptor = inspect(() => Object.getOwnPropertyDescriptor(value, 'length'));\n\tconst length: unknown = descriptor?.value;\n\tif (typeof length !== 'number' || !Number.isSafeInteger(length) || length < 0)\n\t\trefuse('invalid_json');\n\tif (length > budget.maxNodes - budget.nodes) refuse('limit_exceeded');\n\treturn length;\n}\nfunction dataMember(value: object, name: string): unknown {\n\tconst descriptor = inspect(() => Object.getOwnPropertyDescriptor(value, name));\n\tif (descriptor === undefined || !('value' in descriptor) || !descriptor.enumerable)\n\t\trefuse('invalid_json');\n\treturn descriptor.value;\n}\nfunction checkPrototype(value: object, array: boolean): void {\n\tconst prototype = inspect(() => Object.getPrototypeOf(value));\n\tif (array ? prototype !== Array.prototype : prototype !== null && prototype !== Object.prototype)\n\t\trefuse('invalid_json');\n}\nfunction copy(value: unknown, budget: Budget, depth: number): JsonValue {\n\tnode(budget);\n\tif (value === null || typeof value === 'boolean') {\n\t\tbytes(budget, value === null ? 4 : value ? 4 : 5);\n\t\treturn value;\n\t}\n\tif (typeof value === 'string') return string(budget, value);\n\tif (typeof value === 'number') {\n\t\tif (!Number.isFinite(value)) refuse('invalid_json');\n\t\tbytes(budget, String(value).length);\n\t\treturn value;\n\t}\n\tif (typeof value !== 'object') refuse('invalid_json');\n\tif (depth >= budget.maxDepth) refuse('limit_exceeded');\n\tif (budget.active.has(value)) refuse('invalid_json');\n\tconst array = inspect(() => Array.isArray(value));\n\tcheckPrototype(value, array);\n\tbudget.active.add(value);\n\t// Refuse oversized arrays BEFORE allocating the list of all their indices.\n\tif (array) arrayLength(value, budget);\n\tconst names = inspect(() => Reflect.ownKeys(value));\n\tif (names.length > budget.maxNodes - budget.nodes + (array ? 1 : 0)) refuse('limit_exceeded');\n\tbytes(budget, 2);\n\tconst result = array\n\t\t? copyArray(value, names, budget, depth)\n\t\t: copyObject(value, names, budget, depth);\n\tbudget.active.delete(value);\n\treturn result;\n}\n\nfunction copyArray(\n\tvalue: object,\n\tnames: readonly PropertyKey[],\n\tbudget: Budget,\n\tdepth: number,\n): JsonValue {\n\tconst length = arrayLength(value, budget);\n\tif (names.length !== length + 1) refuse('invalid_json');\n\tconst items: JsonValue[] = [];\n\tfor (let i = 0; i < length; i++) {\n\t\tif (i > 0) bytes(budget, 1);\n\t\titems.push(copy(dataMember(value, String(i)), budget, depth + 1));\n\t}\n\treturn Object.freeze(items);\n}\nfunction copyObject(\n\tvalue: object,\n\tnames: readonly PropertyKey[],\n\tbudget: Budget,\n\tdepth: number,\n): JsonValue {\n\tconst record: Record<string, JsonValue> = {};\n\tfor (const [i, name] of names.entries()) {\n\t\tif (typeof name !== 'string') refuse('invalid_json');\n\t\tnode(budget);\n\t\tstring(budget, name);\n\t\tbytes(budget, i > 0 ? 2 : 1);\n\t\tObject.defineProperty(record, name, {\n\t\t\tvalue: copy(dataMember(value, name), budget, depth + 1),\n\t\t\tenumerable: true,\n\t\t});\n\t}\n\treturn Object.freeze(record);\n}\n\n/** Copies plain JSON data without invoking getters, coercion or `toJSON`. */\nexport function snapshotJsonData(\n\tvalue: unknown,\n\tlimits: { readonly maxBytes: number; readonly maxDepth: number; readonly maxNodes: number },\n):\n\t| { readonly ok: true; readonly value: JsonValue }\n\t| { readonly ok: false; readonly code: Refusal['code'] } {\n\ttry {\n\t\treturn {\n\t\t\tok: true,\n\t\t\tvalue: copy(value, { ...limits, bytes: 0, nodes: 0, active: new Set() }, 0),\n\t\t};\n\t} catch (error) {\n\t\tif (isRefusal(error)) return { ok: false, code: error.code };\n\t\tthrow error;\n\t}\n}\n"],"mappings":";AAiBA,MAAMA,IAA+B,OAAO,mBAAmB;AAE/D,SAAS,OAAOC,GAA8B;CAC7C,MAAM;EAAE,QAA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AK,GAAG,OAAO;GAAE,IAAI;GAAO,MAAMA,EAAM;EAAK;EAC3D,MAAMA;CACP;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strict-json.js","names":["failureBrand","value","cursor","text","error","char","depth","literal","NUMBER_PATTERN","match","items","members","name","object","HEX4","out","runStart","code","SIMPLE_ESCAPES","marker","simple","unit","low"],"sources":["../../../src/internal/jose/strict-json.ts"],"sourcesContent":["/** A parsed JSON value. Objects are plain records whose members are all own data properties. */\nexport type JsonValue =\n\t| null\n\t| boolean\n\t| number\n\t| string\n\t| readonly JsonValue[]\n\t| { readonly [member: string]: JsonValue };\n\n/** A parsed JSON object. */\nexport type JsonObject = { readonly [member: string]: JsonValue };\n\n/** Reason strict JSON parsing refused its input. */\nexport type StrictJsonFailureCode = 'invalid_json' | 'duplicate_member' | 'limit_exceeded';\n\n/** Failure of {@linkcode parseStrictJson}. */\nexport interface StrictJsonFailure {\n\treadonly ok: false;\n\treadonly code: StrictJsonFailureCode;\n\treadonly message: string;\n}\n\n/** Result of {@linkcode parseStrictJson}. */\nexport type StrictJsonResult = { readonly ok: true; readonly value: JsonValue } | StrictJsonFailure;\n\n/** Bounds applied while parsing. */\nexport interface StrictJsonLimits {\n\t/** Maximum array and object nesting. */\n\treadonly maxDepth: number;\n\t/** Maximum number of values (scalars, arrays, objects and members) in the document. */\n\treadonly maxNodes: number;\n}\n\ninterface Cursor {\n\treadonly text: string;\n\tindex: number;\n\tnodes: number;\n\treadonly limits: StrictJsonLimits;\n}\n\nconst failureBrand = Symbol('micro509.jose.strictJsonFailure');\n\ninterface Refusal {\n\treadonly [failureBrand]: true;\n\treadonly code: StrictJsonFailureCode;\n\treadonly message: string;\n}\n\nfunction refuse(code: StrictJsonFailureCode, message: string): never {\n\tconst refusal: Refusal = { [failureBrand]: true, code, message };\n\tthrow refusal;\n}\n\nfunction isRefusal(value: unknown): value is Refusal {\n\treturn typeof value === 'object' && value !== null && failureBrand in value;\n}\n\n/**\n * Parses RFC 8259 JSON text, refusing duplicate object member names, lone surrogate escapes,\n * non-finite numbers, and documents beyond the given depth and node bounds.\n */\nexport function parseStrictJson(text: string, limits: StrictJsonLimits): StrictJsonResult {\n\tconst cursor: Cursor = { text, index: 0, nodes: 0, limits };\n\ttry {\n\t\tskipWhitespace(cursor);\n\t\tconst value = parseValue(cursor, 0);\n\t\tskipWhitespace(cursor);\n\t\tif (cursor.index !== text.length)\n\t\t\trefuse('invalid_json', 'Trailing characters after JSON value');\n\t\treturn { ok: true, value };\n\t} catch (error) {\n\t\tif (isRefusal(error)) return { ok: false, code: error.code, message: error.message };\n\t\tthrow error;\n\t}\n}\n\nfunction skipWhitespace(cursor: Cursor): void {\n\twhile (cursor.index < cursor.text.length) {\n\t\tconst char = cursor.text.charCodeAt(cursor.index);\n\t\tif (char !== 0x20 && char !== 0x09 && char !== 0x0a && char !== 0x0d) return;\n\t\tcursor.index++;\n\t}\n}\n\nfunction countNode(cursor: Cursor): void {\n\tcursor.nodes++;\n\tif (cursor.nodes > cursor.limits.maxNodes) {\n\t\trefuse('limit_exceeded', 'JSON document exceeds the node limit');\n\t}\n}\n\nfunction parseValue(cursor: Cursor, depth: number): JsonValue {\n\tcountNode(cursor);\n\tconst char = cursor.text[cursor.index];\n\tswitch (char) {\n\t\tcase '{':\n\t\t\treturn parseObject(cursor, depth + 1);\n\t\tcase '[':\n\t\t\treturn parseArray(cursor, depth + 1);\n\t\tcase '\"':\n\t\t\treturn parseString(cursor);\n\t\tcase 't':\n\t\t\treturn parseLiteral(cursor, 'true', true);\n\t\tcase 'f':\n\t\t\treturn parseLiteral(cursor, 'false', false);\n\t\tcase 'n':\n\t\t\treturn parseLiteral(cursor, 'null', null);\n\t\tdefault:\n\t\t\treturn parseNumber(cursor);\n\t}\n}\n\nfunction parseLiteral<TValue extends boolean | null>(\n\tcursor: Cursor,\n\tliteral: string,\n\tvalue: TValue,\n): TValue {\n\tif (!cursor.text.startsWith(literal, cursor.index)) {\n\t\trefuse('invalid_json', 'Unexpected token in JSON');\n\t}\n\tcursor.index += literal.length;\n\treturn value;\n}\n\nconst NUMBER_PATTERN = /-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/y;\n\nfunction parseNumber(cursor: Cursor): number {\n\tNUMBER_PATTERN.lastIndex = cursor.index;\n\tconst match = NUMBER_PATTERN.exec(cursor.text);\n\tif (match === null) refuse('invalid_json', 'Unexpected token in JSON');\n\tcursor.index += match[0].length;\n\tconst value = Number(match[0]);\n\tif (!Number.isFinite(value)) refuse('invalid_json', 'JSON number is not finite');\n\treturn value;\n}\n\nfunction enter(cursor: Cursor, depth: number): void {\n\tif (depth > cursor.limits.maxDepth) {\n\t\trefuse('limit_exceeded', 'JSON document exceeds the nesting limit');\n\t}\n}\n\nfunction parseArray(cursor: Cursor, depth: number): readonly JsonValue[] {\n\tenter(cursor, depth);\n\tcursor.index++;\n\tconst items: JsonValue[] = [];\n\tskipWhitespace(cursor);\n\tif (cursor.text[cursor.index] === ']') {\n\t\tcursor.index++;\n\t\treturn items;\n\t}\n\tfor (;;) {\n\t\tskipWhitespace(cursor);\n\t\titems.push(parseValue(cursor, depth));\n\t\tskipWhitespace(cursor);\n\t\tconst char = cursor.text[cursor.index++];\n\t\tif (char === ']') return items;\n\t\tif (char !== ',') refuse('invalid_json', 'Expected \",\" or \"]\" in JSON array');\n\t}\n}\n\nfunction parseObject(cursor: Cursor, depth: number): JsonObject {\n\tenter(cursor, depth);\n\tcursor.index++;\n\tconst members = new Map<string, JsonValue>();\n\tskipWhitespace(cursor);\n\tif (cursor.text[cursor.index] === '}') {\n\t\tcursor.index++;\n\t\treturn {};\n\t}\n\tfor (;;) {\n\t\tskipWhitespace(cursor);\n\t\tif (cursor.text[cursor.index] !== '\"')\n\t\t\trefuse('invalid_json', 'Expected member name in JSON object');\n\t\tcountNode(cursor);\n\t\tconst name = parseString(cursor);\n\t\tif (members.has(name)) refuse('duplicate_member', 'JSON object repeats a member name');\n\t\tskipWhitespace(cursor);\n\t\tif (cursor.text[cursor.index++] !== ':') refuse('invalid_json', 'Expected \":\" in JSON object');\n\t\tskipWhitespace(cursor);\n\t\tmembers.set(name, parseValue(cursor, depth));\n\t\tskipWhitespace(cursor);\n\t\tconst char = cursor.text[cursor.index++];\n\t\tif (char === '}') break;\n\t\tif (char !== ',') refuse('invalid_json', 'Expected \",\" or \"}\" in JSON object');\n\t}\n\tconst object: Record<string, JsonValue> = {};\n\tfor (const [name, value] of members) {\n\t\tObject.defineProperty(object, name, {\n\t\t\tvalue,\n\t\t\tenumerable: true,\n\t\t\twritable: true,\n\t\t\tconfigurable: true,\n\t\t});\n\t}\n\treturn object;\n}\n\nconst HEX4 = /[0-9a-fA-F]{4}/y;\n\nfunction readEscapedUnit(cursor: Cursor): number {\n\tHEX4.lastIndex = cursor.index;\n\tconst match = HEX4.exec(cursor.text);\n\tif (match === null) refuse('invalid_json', 'Invalid unicode escape in JSON string');\n\tcursor.index += 4;\n\treturn Number.parseInt(match[0], 16);\n}\n\nfunction parseString(cursor: Cursor): string {\n\tcursor.index++;\n\tlet out = '';\n\tlet runStart = cursor.index;\n\tfor (;;) {\n\t\tif (cursor.index >= cursor.text.length) refuse('invalid_json', 'Unterminated JSON string');\n\t\tconst code = cursor.text.charCodeAt(cursor.index);\n\t\tif (code === 0x22) {\n\t\t\tout += cursor.text.slice(runStart, cursor.index);\n\t\t\tcursor.index++;\n\t\t\treturn out;\n\t\t}\n\t\tif (code < 0x20) refuse('invalid_json', 'Control character in JSON string');\n\t\tif (code !== 0x5c) {\n\t\t\tcursor.index++;\n\t\t\tcontinue;\n\t\t}\n\t\tout += cursor.text.slice(runStart, cursor.index);\n\t\tcursor.index++;\n\t\tout += parseEscape(cursor);\n\t\trunStart = cursor.index;\n\t}\n}\n\nconst SIMPLE_ESCAPES: Readonly<Record<string, string>> = {\n\t'\"': '\"',\n\t'\\\\': '\\\\',\n\t'/': '/',\n\tb: '\\b',\n\tf: '\\f',\n\tn: '\\n',\n\tr: '\\r',\n\tt: '\\t',\n};\n\nfunction parseEscape(cursor: Cursor): string {\n\tconst marker = cursor.text[cursor.index++];\n\tif (marker === undefined) refuse('invalid_json', 'Unterminated JSON string');\n\tif (marker !== 'u') {\n\t\tconst simple = Object.hasOwn(SIMPLE_ESCAPES, marker) ? SIMPLE_ESCAPES[marker] : undefined;\n\t\tif (simple === undefined) refuse('invalid_json', 'Invalid escape in JSON string');\n\t\treturn simple;\n\t}\n\tconst unit = readEscapedUnit(cursor);\n\tif (unit >= 0xdc00 && unit <= 0xdfff) {\n\t\trefuse('invalid_json', 'Lone low surrogate escape in JSON string');\n\t}\n\tif (unit < 0xd800 || unit > 0xdbff) return String.fromCharCode(unit);\n\tif (!cursor.text.startsWith('\\\\u', cursor.index)) {\n\t\trefuse('invalid_json', 'Lone high surrogate escape in JSON string');\n\t}\n\tcursor.index += 2;\n\tconst low = readEscapedUnit(cursor);\n\tif (low < 0xdc00 || low > 0xdfff) {\n\t\trefuse('invalid_json', 'High surrogate escape without a low surrogate');\n\t}\n\treturn String.fromCharCode(unit, low);\n}\n\n/** Narrows a parsed value to a JSON object. */\nexport function isJsonObject(value: JsonValue | undefined): value is JsonObject {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** Narrows a parsed value to a JSON array. */\nexport function isJsonArray(value: JsonValue | undefined): value is readonly JsonValue[] {\n\treturn Array.isArray(value);\n}\n"],"mappings":";AAwCA,MAAMA,IAAe,OAAO,iCAAiC;AAQ7D,SAAS,OAAO,GAA6B,GAAwB;CAEpE,MAAM;GADsBA,IAAe;EAAM;EAAM;CAC3C;AACb;AAEA,SAAS,UAAU,GAAkC;CACpD,OAAO,OAAOC,KAAU,cAAYA,KAAkBD,KAAgBC;AACvE;;;;;AAMA,SAAgB,gBAAgB,GAAc,GAA4C;CACzF,IAAMC,IAAiB;EAAE;EAAM,OAAO;EAAG,OAAO;EAAG;CAAO;CAC1D,IAAI;EACH,eAAeA,CAAM;EACr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GAAG;CACH,GAAG;CACH,GAAG;AACJ;AAEA,SAAS,YAAY,GAAwB;CAC5C,IAAMC,IAASjB,EAAO,KAAK,EAAO;CAElC,IADIiB,MAAW,KAAA,KAAW,OAAO,gBAAgB,0BAA0B,GACvEA,MAAW,KAAK;EACnB,IAAMC,IAAS,OAAO,OAAOF,GAAgBC,CAAM,IAAID,EAAeC,KAAU,KAAA;EAEhF,OADIC,MAAW,KAAA,KAAW,OAAO,gBAAgB,+BAA+B,GACzEA;CACR;CACA,IAAMC,IAAO,gBAAgBnB,CAAM;CAInC,IAHImB,KAAQ,SAAUA,KAAQ,SAC7B,OAAO,gBAAgB,0CAA0C,GAE9DA,IAAO,SAAUA,IAAO,OAAQ,OAAO,OAAO,aAAaA,CAAI;CAInE,AAHKnB,EAAO,KAAK,WAAW,OAAOA,EAAO,KAAK,KAC9C,OAAO,gBAAgB,2CAA2C,GAEnE,EAAO,SAAS;CAChB,IAAMoB,IAAM,gBAAgBpB,CAAM;CAIlC,QAHIoB,IAAM,SAAUA,IAAM,UACzB,OAAO,gBAAgB,+CAA+C,GAEhE,OAAO,aAAaD,GAAMC,CAAG;AACrC;;AAGA,SAAgB,aAAa,GAAmD;CAC/E,OAAO,OAAOrB,KAAU,cAAYA,KAAkB,CAAC,MAAM,QAAQA,CAAK;AAC3E;;AAGA,SAAgB,YAAY,GAA6D;CACxF,OAAO,MAAM,QAAQA,CAAK;AAC3B"}
|
|
1
|
+
{"version":3,"file":"strict-json.js","names":["failureBrand","code","message","value","text","limits","cursor","error","char","depth","literal","NUMBER_PATTERN","match","items","members","name","object","HEX4","out","runStart","SIMPLE_ESCAPES","marker","simple","unit","low"],"sources":["../../../src/internal/jose/strict-json.ts"],"sourcesContent":["/** A parsed JSON value. Objects are plain records whose members are all own data properties. */\nexport type JsonValue =\n\t| null\n\t| boolean\n\t| number\n\t| string\n\t| readonly JsonValue[]\n\t| { readonly [member: string]: JsonValue };\n\n/** A parsed JSON object. */\nexport type JsonObject = { readonly [member: string]: JsonValue };\n\n/** Reason strict JSON parsing refused its input. */\nexport type StrictJsonFailureCode = 'invalid_json' | 'duplicate_member' | 'limit_exceeded';\n\n/** Failure of {@linkcode parseStrictJson}. */\nexport interface StrictJsonFailure {\n\treadonly ok: false;\n\treadonly code: StrictJsonFailureCode;\n\treadonly message: string;\n}\n\n/** Result of {@linkcode parseStrictJson}. */\nexport type StrictJsonResult = { readonly ok: true; readonly value: JsonValue } | StrictJsonFailure;\n\n/** Bounds applied while parsing. */\nexport interface StrictJsonLimits {\n\t/** Maximum array and object nesting. */\n\treadonly maxDepth: number;\n\t/** Maximum number of values (scalars, arrays, objects and members) in the document. */\n\treadonly maxNodes: number;\n}\n\ninterface Cursor {\n\treadonly text: string;\n\tindex: number;\n\tnodes: number;\n\treadonly limits: StrictJsonLimits;\n}\n\nconst failureBrand = Symbol('micro509.jose.strictJsonFailure');\n\ninterface Refusal {\n\treadonly [failureBrand]: true;\n\treadonly code: StrictJsonFailureCode;\n\treadonly message: string;\n}\n\nfunction refuse(code: StrictJsonFailureCode, message: string): never {\n\tconst refusal: Refusal = { [failureBrand]: true, code, message };\n\tthrow refusal;\n}\n\nfunction isRefusal(value: unknown): value is Refusal {\n\treturn typeof value === 'object' && value !== null && failureBrand in value;\n}\n\n/**\n * Parses RFC 8259 JSON text, refusing duplicate object member names, lone surrogate escapes,\n * non-finite numbers, and documents beyond the given depth and node bounds.\n */\nexport function parseStrictJson(text: string, limits: StrictJsonLimits): StrictJsonResult {\n\tconst cursor: Cursor = { text, index: 0, nodes: 0, limits };\n\ttry {\n\t\tskipWhitespace(cursor);\n\t\tconst value = parseValue(cursor, 0);\n\t\tskipWhitespace(cursor);\n\t\tif (cursor.index !== text.length)\n\t\t\trefuse('invalid_json', 'Trailing characters after JSON value');\n\t\treturn { ok: true, value };\n\t} catch (error) {\n\t\tif (isRefusal(error)) return { ok: false, code: error.code, message: error.message };\n\t\tthrow error;\n\t}\n}\n\nfunction skipWhitespace(cursor: Cursor): void {\n\twhile (cursor.index < cursor.text.length) {\n\t\tconst char = cursor.text.charCodeAt(cursor.index);\n\t\tif (char !== 0x20 && char !== 0x09 && char !== 0x0a && char !== 0x0d) return;\n\t\tcursor.index++;\n\t}\n}\n\nfunction countNode(cursor: Cursor): void {\n\tcursor.nodes++;\n\tif (cursor.nodes > cursor.limits.maxNodes) {\n\t\trefuse('limit_exceeded', 'JSON document exceeds the node limit');\n\t}\n}\n\nfunction parseValue(cursor: Cursor, depth: number): JsonValue {\n\tcountNode(cursor);\n\tconst char = cursor.text[cursor.index];\n\tswitch (char) {\n\t\tcase '{':\n\t\t\treturn parseObject(cursor, depth + 1);\n\t\tcase '[':\n\t\t\treturn parseArray(cursor, depth + 1);\n\t\tcase '\"':\n\t\t\treturn parseString(cursor);\n\t\tcase 't':\n\t\t\treturn parseLiteral(cursor, 'true', true);\n\t\tcase 'f':\n\t\t\treturn parseLiteral(cursor, 'false', false);\n\t\tcase 'n':\n\t\t\treturn parseLiteral(cursor, 'null', null);\n\t\tdefault:\n\t\t\treturn parseNumber(cursor);\n\t}\n}\n\nfunction parseLiteral<TValue extends boolean | null>(\n\tcursor: Cursor,\n\tliteral: string,\n\tvalue: TValue,\n): TValue {\n\tif (!cursor.text.startsWith(literal, cursor.index)) {\n\t\trefuse('invalid_json', 'Unexpected token in JSON');\n\t}\n\tcursor.index += literal.length;\n\treturn value;\n}\n\nconst NUMBER_PATTERN = /-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/y;\n\nfunction parseNumber(cursor: Cursor): number {\n\tNUMBER_PATTERN.lastIndex = cursor.index;\n\tconst match = NUMBER_PATTERN.exec(cursor.text);\n\tif (match === null) refuse('invalid_json', 'Unexpected token in JSON');\n\tcursor.index += match[0].length;\n\tconst value = Number(match[0]);\n\tif (!Number.isFinite(value)) refuse('invalid_json', 'JSON number is not finite');\n\treturn value;\n}\n\nfunction enter(cursor: Cursor, depth: number): void {\n\tif (depth > cursor.limits.maxDepth) {\n\t\trefuse('limit_exceeded', 'JSON document exceeds the nesting limit');\n\t}\n}\n\nfunction parseArray(cursor: Cursor, depth: number): readonly JsonValue[] {\n\tenter(cursor, depth);\n\tcursor.index++;\n\tconst items: JsonValue[] = [];\n\tskipWhitespace(cursor);\n\tif (cursor.text[cursor.index] === ']') {\n\t\tcursor.index++;\n\t\treturn items;\n\t}\n\tfor (;;) {\n\t\tskipWhitespace(cursor);\n\t\titems.push(parseValue(cursor, depth));\n\t\tskipWhitespace(cursor);\n\t\tconst char = cursor.text[cursor.index++];\n\t\tif (char === ']') return items;\n\t\tif (char !== ',') refuse('invalid_json', 'Expected \",\" or \"]\" in JSON array');\n\t}\n}\n\nfunction parseObject(cursor: Cursor, depth: number): JsonObject {\n\tenter(cursor, depth);\n\tcursor.index++;\n\tconst members = new Map<string, JsonValue>();\n\tskipWhitespace(cursor);\n\tif (cursor.text[cursor.index] === '}') {\n\t\tcursor.index++;\n\t\treturn {};\n\t}\n\tfor (;;) {\n\t\tskipWhitespace(cursor);\n\t\tif (cursor.text[cursor.index] !== '\"')\n\t\t\trefuse('invalid_json', 'Expected member name in JSON object');\n\t\tcountNode(cursor);\n\t\tconst name = parseString(cursor);\n\t\tif (members.has(name)) refuse('duplicate_member', 'JSON object repeats a member name');\n\t\tskipWhitespace(cursor);\n\t\tif (cursor.text[cursor.index++] !== ':') refuse('invalid_json', 'Expected \":\" in JSON object');\n\t\tskipWhitespace(cursor);\n\t\tmembers.set(name, parseValue(cursor, depth));\n\t\tskipWhitespace(cursor);\n\t\tconst char = cursor.text[cursor.index++];\n\t\tif (char === '}') break;\n\t\tif (char !== ',') refuse('invalid_json', 'Expected \",\" or \"}\" in JSON object');\n\t}\n\tconst object: Record<string, JsonValue> = {};\n\tfor (const [name, value] of members) {\n\t\tObject.defineProperty(object, name, {\n\t\t\tvalue,\n\t\t\tenumerable: true,\n\t\t\twritable: true,\n\t\t\tconfigurable: true,\n\t\t});\n\t}\n\treturn object;\n}\n\nconst HEX4 = /[0-9a-fA-F]{4}/y;\n\nfunction readEscapedUnit(cursor: Cursor): number {\n\tHEX4.lastIndex = cursor.index;\n\tconst match = HEX4.exec(cursor.text);\n\tif (match === null) refuse('invalid_json', 'Invalid unicode escape in JSON string');\n\tcursor.index += 4;\n\treturn Number.parseInt(match[0], 16);\n}\n\nfunction parseString(cursor: Cursor): string {\n\tcursor.index++;\n\tlet out = '';\n\tlet runStart = cursor.index;\n\tfor (;;) {\n\t\tif (cursor.index >= cursor.text.length) refuse('invalid_json', 'Unterminated JSON string');\n\t\tconst code = cursor.text.charCodeAt(cursor.index);\n\t\tif (code === 0x22) {\n\t\t\tout += cursor.text.slice(runStart, cursor.index);\n\t\t\tcursor.index++;\n\t\t\treturn out;\n\t\t}\n\t\tif (code < 0x20) refuse('invalid_json', 'Control character in JSON string');\n\t\tif (code !== 0x5c) {\n\t\t\tcursor.index++;\n\t\t\tcontinue;\n\t\t}\n\t\tout += cursor.text.slice(runStart, cursor.index);\n\t\tcursor.index++;\n\t\tout += parseEscape(cursor);\n\t\trunStart = cursor.index;\n\t}\n}\n\nconst SIMPLE_ESCAPES: Readonly<Record<string, string>> = {\n\t'\"': '\"',\n\t'\\\\': '\\\\',\n\t'/': '/',\n\tb: '\\b',\n\tf: '\\f',\n\tn: '\\n',\n\tr: '\\r',\n\tt: '\\t',\n};\n\nfunction parseEscape(cursor: Cursor): string {\n\tconst marker = cursor.text[cursor.index++];\n\tif (marker === undefined) refuse('invalid_json', 'Unterminated JSON string');\n\tif (marker !== 'u') {\n\t\tconst simple = Object.hasOwn(SIMPLE_ESCAPES, marker) ? SIMPLE_ESCAPES[marker] : undefined;\n\t\tif (simple === undefined) refuse('invalid_json', 'Invalid escape in JSON string');\n\t\treturn simple;\n\t}\n\tconst unit = readEscapedUnit(cursor);\n\tif (unit >= 0xdc00 && unit <= 0xdfff) {\n\t\trefuse('invalid_json', 'Lone low surrogate escape in JSON string');\n\t}\n\tif (unit < 0xd800 || unit > 0xdbff) return String.fromCharCode(unit);\n\tif (!cursor.text.startsWith('\\\\u', cursor.index)) {\n\t\trefuse('invalid_json', 'Lone high surrogate escape in JSON string');\n\t}\n\tcursor.index += 2;\n\tconst low = readEscapedUnit(cursor);\n\tif (low < 0xdc00 || low > 0xdfff) {\n\t\trefuse('invalid_json', 'High surrogate escape without a low surrogate');\n\t}\n\treturn String.fromCharCode(unit, low);\n}\n\n/** Narrows a parsed value to a JSON object. */\nexport function isJsonObject(value: JsonValue | undefined): value is JsonObject {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** Narrows a parsed value to a JSON array. */\nexport function isJsonArray(value: JsonValue | undefined): value is readonly JsonValue[] {\n\treturn Array.isArray(value);\n}\n"],"mappings":";AAwCA,MAAMA,IAAe,OAAO,iCAAiC;AAQ7D,SAAS,OAAOC,GAA6BC,GAAwB;CAEpE,MAAM;GADsBF,IAAe;EAAMC;EAAMC;CAC3C;AACb;AAEA,SAAS,UAAUC,GAAkC;CACpD,OAAO,OAAOA,KAAU,cAAYA,KAAkBH,KAAgBG;AACvE;;;;;AAMA,SAAgB,gBAAgBC,GAAcC,GAA4C;CACzF,IAAMC,IAAiB;EAAEF;EAAM,OAAO;EAAG,OAAO;EAAGC;CAAO;CAC1D,IAAI;EACH,eAAeC,CAAM;EACrB,IAAMH,IAAQ,WAAWG,GAAQ,CAAC;EAIlC,OAHA,eAAeA,CAAM,GACjBA,EAAO,UAAUF,EAAK,UACzB,OAAO,gBAAgB,sCAAsC,GACvD;GAAE,IAAI;GAAMD;EAAM;CAC1B,SAASI,GAAO;EACf,IAAI,UAAUA,CAAK,GAAG,OAAO;GAAE,IAAI;GAAO,MAAMA,EAAM;GAAM,SAASA,EAAM;EAAQ;EACnF,MAAMA;CACP;AACD;AAEA,SAAS,eAAeD,GAAsB;CAC7C,OAAOA,EAAO,QAAQA,EAAO,KAAK,SAAQ;EACzC,IAAME,IAAOF,EAAO,KAAK,WAAWA,EAAO,KAAK;EAChD,IAAIE,MAAS,MAAQ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O,aAAaA,CAAI;CAC9DjB,EAAO,KAAK,WAAW,OAAOA,EAAO,KAAK,KAC9C,OAAO,gBAAgB,2CAA2C,GAEnEA,EAAO,SAAS;CAChB,IAAMkB,IAAM,gBAAgBlB,CAAM;CAIlC,QAHIkB,IAAM,SAAUA,IAAM,UACzB,OAAO,gBAAgB,+CAA+C,GAEhE,OAAO,aAAaD,GAAMC,CAAG;AACrC;;AAGA,SAAgB,aAAarB,GAAmD;CAC/E,OAAO,OAAOA,KAAU,cAAYA,KAAkB,CAAC,MAAM,QAAQA,CAAK;AAC3E;;AAGA,SAAgB,YAAYA,GAA6D;CACxF,OAAO,MAAM,QAAQA,CAAK;AAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.js","names":["parts","byte","
|
|
1
|
+
{"version":3,"file":"base64.js","names":["bytes","parts","byte","value","binary","i","compact"],"sources":["../../../src/internal/shared/base64.ts"],"sourcesContent":["/** Encode raw bytes as standard base64 without line breaks. */\nexport function base64Encode(bytes: Uint8Array): string {\n\tconst parts: string[] = [];\n\tfor (const byte of bytes) {\n\t\tparts.push(String.fromCharCode(byte));\n\t}\n\treturn btoa(parts.join(''));\n}\n\n/** Decode a standard base64 string into raw bytes. */\nexport function base64Decode(value: string): Uint8Array {\n\tconst binary = atob(value);\n\tconst bytes = new Uint8Array(binary.length);\n\tfor (let i = 0; i < binary.length; i++) {\n\t\tbytes[i] = binary.charCodeAt(i);\n\t}\n\tassertCanonicalFinalQuantum(value, bytes);\n\treturn bytes;\n}\n\n/** RFC 4648 §4 completes a final quantum with pad characters and bits of value zero. */\nfunction assertCanonicalFinalQuantum(value: string, bytes: Uint8Array): void {\n\tconst compact = value.replace(/[\\t\\n\\f\\r ]/g, '');\n\tif (compact.length % 4 !== 0) {\n\t\tthrow new Error('Base64 final quantum is missing its padding');\n\t}\n\tif (compact.length === 0) {\n\t\treturn;\n\t}\n\tconst finalQuantum = bytes.slice(bytes.length - (((bytes.length - 1) % 3) + 1));\n\tif (base64Encode(finalQuantum) !== compact.slice(-4)) {\n\t\tthrow new Error('Base64 final quantum has non-zero pad bits');\n\t}\n}\n"],"mappings":";;AACA,SAAgB,aAAaA,GAA2B;CACvD,IAAMC,IAAkB,CAAC;CACzB,KAAK,IAAMC,KAAQF,GAClBC,EAAM,KAAK,OAAO,aAAaC,CAAI,CAAC;CAErC,OAAO,KAAKD,EAAM,KAAK,EAAE,CAAC;AAC3B;;AAGA,SAAgB,aAAaE,GAA2B;CACvD,IAAMC,IAAS,KAAKD,CAAK,GACnBH,IAAQ,IAAI,WAAWI,EAAO,MAAM;CAC1C,KAAK,IAAIC,IAAI,GAAGA,IAAID,EAAO,QAAQC,KAClCL,EAAMK,KAAKD,EAAO,WAAWC,CAAC;CAG/B,OADA,4BAA4BF,GAAOH,CAAK,GACjCA;AACR;;AAGA,SAAS,4BAA4BG,GAAeH,GAAyB;CAC5E,IAAMM,IAAUH,EAAM,QAAQ,gBAAgB,EAAE;CAChD,IAAIG,EAAQ,SAAS,KAAM,GAC1B,MAAU,MAAM,6CAA6C;CAE9D,IAAIA,EAAQ,WAAW,KAInB,aADiBN,EAAM,MAAMA,EAAM,WAAYA,EAAM,SAAS,KAAK,IAAK,EAChD,CAAC,MAAMM,EAAQ,MAAM,EAAE,GAClD,MAAU,MAAM,4CAA4C;AAE9D"}
|
|
@@ -9,5 +9,4 @@ export declare function compareDistinguishedNames(left: ParsedName, right: Parse
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function canonicalDnKey(name: ParsedName): string;
|
|
11
11
|
/** True when `subject` equals or is subordinate to `constraint` (RDN prefix match). */
|
|
12
|
-
export declare function isWithinDirectoryNameSubtree(subject: ParsedName, constraint: ParsedName): boolean;
|
|
13
|
-
//# sourceMappingURL=dn.d.ts.map
|
|
12
|
+
export declare function isWithinDirectoryNameSubtree(subject: ParsedName, constraint: ParsedName): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OIDS as e } from "../asn1/
|
|
1
|
+
import { OIDS as e } from "../asn1/oids.js";
|
|
2
2
|
import { A1_UNASSIGNED_RANGES as t, B2_CASE_FOLD as n, NFKC_3_2_CORRECTIONS as r } from "./rfc3454-tables.js";
|
|
3
3
|
import { COMBINING_MARK_RANGES as i } from "./rfc4518-tables.js";
|
|
4
4
|
// src/internal/shared/dn.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dn.js","names":["left","right","index","leftRdn","rightRdn","name","subject","constraint","undetermined","subjectRdn","constraintRdn","match","leftClasses","rightClasses","comparisonClass","leftClass","rightClass","classes","attribute","attributes","comparison","unpaired","key","count","from","to","INCOMPARABLE","OIDS","prepared","value","tag","MAP_TO_NOTHING","MAP_TO_SPACE","ranges","first","last","codePoint","ch","A1_UNASSIGNED_RANGES","mapped","NFKC_3_2_CORRECTIONS","out","B2_CASE_FOLD","collapsed","nextIndex","nextCodePoint","COMBINING_MARK_RANGES","normalized","rdn","val","attr"],"sources":["../../../src/internal/shared/dn.ts"],"sourcesContent":["/**\n * Distinguished name comparison utilities implementing RFC 5280 §7.1, which\n * defers string preparation to the RFC 4518 LDAP profile.\n *\n * {@linkcode prepareNameCompareString} runs the RFC 4518 Map, Normalize,\n * Prohibit, and Insignificant Space steps with RFC 3454 Appendix B.2 case\n * folding. The Prohibit step rejects code points unassigned in the running\n * Unicode version; RFC 3454 Table A.1 pins that set to Unicode 3.2.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc4518 | RFC 4518}\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#section-7.1 | RFC 5280 §7.1}\n * @module\n */\n\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport type { CodePointRange } from '#micro509/internal/shared/rfc3454-tables';\nimport {\n\tA1_UNASSIGNED_RANGES,\n\tB2_CASE_FOLD,\n\tNFKC_3_2_CORRECTIONS,\n} from '#micro509/internal/shared/rfc3454-tables';\nimport { COMBINING_MARK_RANGES } from '#micro509/internal/shared/rfc4518-tables';\nimport type {\n\tParsedName,\n\tParsedNameAttribute,\n\tParsedRelativeDistinguishedName,\n} from '#micro509/x509/parse';\n\n// Public API\n\n/** RFC 5280 [§7.1](https://datatracker.ietf.org/doc/html/rfc5280#section-7.1) semantic equality: same RDN count, each pair matches attribute-by-attribute. */\nexport function compareDistinguishedNames(left: ParsedName, right: ParsedName): boolean {\n\tif (left.rdns.length !== right.rdns.length) {\n\t\treturn false;\n\t}\n\tfor (let index = 0; index < left.rdns.length; index += 1) {\n\t\tconst leftRdn = left.rdns[index];\n\t\tconst rightRdn = right.rdns[index];\n\t\tif (leftRdn === undefined || rightRdn === undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!compareRelativeDistinguishedNames(leftRdn, rightRdn)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/**\n * Produces a deterministic string key for a parsed DN, suitable as a Map key.\n * Semantically equal DNs (per RFC 5280 [§7.1](https://datatracker.ietf.org/doc/html/rfc5280#section-7.1)) produce identical keys.\n *\n * Format: RDNs joined by `,`, attributes within each RDN sorted by OID then by prepared value, joined by `+`.\n */\nexport function canonicalDnKey(name: ParsedName): string {\n\treturn name.rdns.map(canonicalRdnKey).join(',');\n}\n\n/** True when `subject` equals or is subordinate to `constraint` (RDN prefix match). */\nexport function isWithinDirectoryNameSubtree(subject: ParsedName, constraint: ParsedName): boolean {\n\treturn directoryNameSubtreeMatch(subject, constraint) === 'match';\n}\n\n/**\n * Outcome of an RFC 5280 §7.1 name comparison. `undetermined` is the RFC 4518\n * Undefined result: a DirectoryString value that string preparation refuses.\n */\nexport type NameMatch = 'match' | 'mismatch' | 'undetermined';\n\n/** {@linkcode isWithinDirectoryNameSubtree}, keeping an undetermined comparison apart from a mismatch. */\nexport function directoryNameSubtreeMatch(subject: ParsedName, constraint: ParsedName): NameMatch {\n\tif (constraint.rdns.length > subject.rdns.length) {\n\t\treturn 'mismatch';\n\t}\n\tlet undetermined = false;\n\tfor (let index = 0; index < constraint.rdns.length; index += 1) {\n\t\tconst subjectRdn = subject.rdns[index];\n\t\tconst constraintRdn = constraint.rdns[index];\n\t\tif (subjectRdn === undefined || constraintRdn === undefined) {\n\t\t\treturn 'mismatch';\n\t\t}\n\t\tconst match = relativeDistinguishedNameMatch(subjectRdn, constraintRdn);\n\t\tif (match === 'mismatch') {\n\t\t\treturn 'mismatch';\n\t\t}\n\t\tundetermined ||= match === 'undetermined';\n\t}\n\treturn undetermined ? 'undetermined' : 'match';\n}\n\n// RDN / attribute comparison\n\n/** Order-independent RDN equality: same attribute count, each pair matched exactly once. */\nexport function compareRelativeDistinguishedNames(\n\tleft: ParsedRelativeDistinguishedName,\n\tright: ParsedRelativeDistinguishedName,\n): boolean {\n\treturn relativeDistinguishedNameMatch(left, right) === 'match';\n}\n\n/**\n * `match` when the two RDNs' attributes pair one to one with every pair\n * matching, else `undetermined` when they pair with Undefined pairs allowed.\n */\nfunction relativeDistinguishedNameMatch(\n\tleft: ParsedRelativeDistinguishedName,\n\tright: ParsedRelativeDistinguishedName,\n): NameMatch {\n\tif (left.attributes.length !== right.attributes.length) {\n\t\treturn 'mismatch';\n\t}\n\tconst leftClasses = comparisonClasses(left.attributes);\n\tconst rightClasses = comparisonClasses(right.attributes);\n\tif (leftClasses === undefined || rightClasses === undefined) {\n\t\treturn 'mismatch';\n\t}\n\tlet undetermined = false;\n\tfor (const [comparisonClass, leftClass] of leftClasses) {\n\t\tconst rightClass = rightClasses.get(comparisonClass);\n\t\tif (rightClass === undefined || rightClass.size !== leftClass.size) {\n\t\t\treturn 'mismatch';\n\t\t}\n\t\tif (\n\t\t\tunpairedKeys(leftClass, rightClass) > rightClass.unprepared ||\n\t\t\tunpairedKeys(rightClass, leftClass) > leftClass.unprepared\n\t\t) {\n\t\t\treturn 'mismatch';\n\t\t}\n\t\tundetermined ||= leftClass.unprepared > 0 || rightClass.unprepared > 0;\n\t}\n\treturn undetermined ? 'undetermined' : 'match';\n}\n\n/** The attributes of one comparison class in an RDN. */\ninterface ComparisonClass {\n\treadonly keys: Map<string, number>;\n\tunprepared: number;\n\tsize: number;\n}\n\n/** An RDN's attributes by comparison class, or `undefined` when one of them is incomparable. */\nfunction comparisonClasses(\n\tattributes: readonly ParsedNameAttribute[],\n): Map<string, ComparisonClass> | undefined {\n\tconst classes = new Map<string, ComparisonClass>();\n\tfor (const attribute of attributes) {\n\t\tconst comparison = attributeComparison(attribute);\n\t\tif (comparison.type === 'incomparable') {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst comparisonClass = classes.get(comparison.comparisonClass) ?? {\n\t\t\tkeys: new Map<string, number>(),\n\t\t\tunprepared: 0,\n\t\t\tsize: 0,\n\t\t};\n\t\tcomparisonClass.size += 1;\n\t\tif (comparison.type === 'unprepared') {\n\t\t\tcomparisonClass.unprepared += 1;\n\t\t} else {\n\t\t\tcomparisonClass.keys.set(comparison.key, (comparisonClass.keys.get(comparison.key) ?? 0) + 1);\n\t\t}\n\t\tclasses.set(comparison.comparisonClass, comparisonClass);\n\t}\n\treturn classes;\n}\n\n/** How many keyed attributes of `from` find no equal key left in `to`. */\nfunction unpairedKeys(from: ComparisonClass, to: ComparisonClass): number {\n\tlet unpaired = 0;\n\tfor (const [key, count] of from.keys) {\n\t\tunpaired += Math.max(0, count - (to.keys.get(key) ?? 0));\n\t}\n\treturn unpaired;\n}\n\n/** Compares two AttributeTypeAndValue pairs using RFC 5280 [§7.1](https://datatracker.ietf.org/doc/html/rfc5280#section-7.1) string-prep for DirectoryString tags. */\nexport function compareNameAttributeValue(\n\tleft: ParsedNameAttribute,\n\tright: ParsedNameAttribute,\n): boolean {\n\treturn nameAttributeValueMatch(left, right) === 'match';\n}\n\nfunction nameAttributeValueMatch(left: ParsedNameAttribute, right: ParsedNameAttribute): NameMatch {\n\tconst leftComparison = attributeComparison(left);\n\tconst rightComparison = attributeComparison(right);\n\tif (\n\t\tleftComparison.type === 'incomparable' ||\n\t\trightComparison.type === 'incomparable' ||\n\t\tleftComparison.comparisonClass !== rightComparison.comparisonClass\n\t) {\n\t\treturn 'mismatch';\n\t}\n\tif (leftComparison.type === 'keyed' && rightComparison.type === 'keyed') {\n\t\treturn leftComparison.key === rightComparison.key ? 'match' : 'mismatch';\n\t}\n\treturn 'undetermined';\n}\n\n/**\n * How an attribute value takes part in matching. Two attributes match when\n * they share a comparison class and a key, a value string preparation refuses\n * is Undefined against every value of its class, and an incomparable value\n * matches nothing.\n */\ntype AttributeComparison =\n\t| { readonly type: 'keyed'; readonly comparisonClass: string; readonly key: string }\n\t| { readonly type: 'unprepared'; readonly comparisonClass: string }\n\t| { readonly type: 'incomparable' };\n\nconst INCOMPARABLE: AttributeComparison = { type: 'incomparable' };\n\nfunction attributeComparison(attribute: ParsedNameAttribute): AttributeComparison {\n\tif (attribute.oid === OIDS.domainComponent) {\n\t\t// RFC 5280 §7.3 / RFC 4519 caseIgnoreIA5Match: domainComponent is\n\t\t// IA5String, prepared and compared case-insensitively with insignificant\n\t\t// spaces collapsed.\n\t\treturn attribute.valueTag === 0x16 && isAscii(attribute.value)\n\t\t\t? preparedComparison(`${attribute.oid} ia5`, attribute.value)\n\t\t\t: INCOMPARABLE;\n\t}\n\t// RFC 5280 §4.1.2.6 and RFC 2985 §6.1 pkcs9CaseIgnoreMatch: emailAddress is\n\t// IA5String, matched character by character without regard to case and\n\t// without the RFC 4518 space collapsing a DirectoryString attribute gets.\n\t// Under any other tag the value falls through to the general comparison.\n\tif (\n\t\tattribute.oid === OIDS.emailAddress &&\n\t\tattribute.valueTag === 0x16 &&\n\t\tisAscii(attribute.value)\n\t) {\n\t\treturn {\n\t\t\ttype: 'keyed',\n\t\t\tcomparisonClass: `${attribute.oid} exact`,\n\t\t\tkey: `ia5 ${attribute.value.toLowerCase()}`,\n\t\t};\n\t}\n\tif (isDirectoryStringTag(attribute.valueTag)) {\n\t\treturn preparedComparison(`${attribute.oid} directory`, attribute.value);\n\t}\n\treturn {\n\t\ttype: 'keyed',\n\t\tcomparisonClass: `${attribute.oid} exact`,\n\t\tkey: `${attribute.valueTag} ${attribute.value}`,\n\t};\n}\n\nfunction preparedComparison(comparisonClass: string, value: string): AttributeComparison {\n\tconst prepared = prepareNameCompareString(value);\n\treturn prepared === undefined\n\t\t? { type: 'unprepared', comparisonClass }\n\t\t: { type: 'keyed', comparisonClass, key: prepared };\n}\n\n// Helpers\n\n/**\n * True for the DirectoryString alternatives compared after RFC 4518\n * preparation: UTF8String (0x0C), PrintableString (0x13), TeletexString (0x14,\n * transcoded by RFC 4518 §2.1's local mapping at decode time), UniversalString\n * (0x1C), and BMPString (0x1E).\n */\nexport function isDirectoryStringTag(tag: number): boolean {\n\treturn tag === 0x0c || tag === 0x13 || tag === 0x14 || tag === 0x1c || tag === 0x1e;\n}\n\n/** RFC 4518 §2.2: code points deleted (Cc/Cf controls, joiners, ignorables). */\nconst MAP_TO_NOTHING: readonly CodePointRange[] = [\n\t[0x0000, 0x0008], // C0 controls NUL..BS\n\t[0x000e, 0x001f], // C0 controls SO..US\n\t[0x007f, 0x0084], // DEL, C1 controls\n\t[0x0086, 0x009f], // C1 controls\n\t[0x00ad, 0x00ad], // SOFT HYPHEN\n\t[0x034f, 0x034f], // COMBINING GRAPHEME JOINER\n\t[0x06dd, 0x06dd], // ARABIC END OF AYAH\n\t[0x070f, 0x070f], // SYRIAC ABBREVIATION MARK\n\t[0x1806, 0x1806], // MONGOLIAN TODO SOFT HYPHEN\n\t[0x180b, 0x180e], // variation selectors, MONGOLIAN VOWEL SEPARATOR\n\t[0x200b, 0x200f], // ZWSP, ZWNJ, ZWJ, LRM, RLM\n\t[0x202a, 0x202e], // bidi embedding/override controls\n\t[0x2060, 0x2063], // WORD JOINER, invisible operators\n\t[0x206a, 0x206f], // deprecated format controls\n\t[0xfe00, 0xfe0f], // variation selectors\n\t[0xfeff, 0xfeff], // ZERO WIDTH NO-BREAK SPACE (BOM)\n\t[0xfff9, 0xfffc], // interlinear annotations, OBJECT REPLACEMENT CHARACTER\n\t[0x1d173, 0x1d17a], // musical symbol format controls\n\t[0xe0001, 0xe0001], // LANGUAGE TAG\n\t[0xe0020, 0xe007f], // tag characters\n];\n\n/** RFC 4518 §2.2: code points mapped to SPACE (control whitespace and Zs/Zl/Zp). */\nconst MAP_TO_SPACE: readonly CodePointRange[] = [\n\t[0x0009, 0x000d], // TAB, LF, VT, FF, CR\n\t[0x0085, 0x0085], // NEL\n\t[0x00a0, 0x00a0], // NO-BREAK SPACE\n\t[0x1680, 0x1680], // OGHAM SPACE MARK\n\t[0x2000, 0x200a], // EN QUAD .. HAIR SPACE\n\t[0x2028, 0x2029], // LINE SEPARATOR, PARAGRAPH SEPARATOR\n\t[0x202f, 0x202f], // NARROW NO-BREAK SPACE\n\t[0x205f, 0x205f], // MEDIUM MATHEMATICAL SPACE\n\t[0x3000, 0x3000], // IDEOGRAPHIC SPACE\n];\n\n/** True when `codePoint` falls in one of the inclusive `ranges`. */\nfunction inRanges(codePoint: number, ranges: readonly CodePointRange[]): boolean {\n\treturn ranges.some(([first, last]) => codePoint >= first && codePoint <= last);\n}\n\n/** True when every code point in `value` is ASCII. */\nfunction isAscii(value: string): boolean {\n\tfor (const ch of value) {\n\t\tconst codePoint = ch.codePointAt(0);\n\t\tif (codePoint === undefined || codePoint > 0x7f) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/**\n * RFC 4518 §2.4 Prohibit against the frozen Unicode 3.2 repertoire: code points\n * unassigned in 3.2 (RFC 3454 Table A.1), private use, surrogate, non-character,\n * and the replacement character. `\\p{Cn}` is avoided because it tracks the\n * running Unicode version rather than 3.2.\n */\nfunction isProhibited(codePoint: number): boolean {\n\treturn (\n\t\tinRanges(codePoint, A1_UNASSIGNED_RANGES) ||\n\t\t(codePoint >= 0xe000 && codePoint <= 0xf8ff) ||\n\t\t(codePoint >= 0xf0000 && codePoint <= 0xffffd) ||\n\t\t(codePoint >= 0x100000 && codePoint <= 0x10fffd) ||\n\t\t(codePoint >= 0xd800 && codePoint <= 0xdfff) ||\n\t\t(codePoint >= 0xfdd0 && codePoint <= 0xfdef) ||\n\t\t(codePoint & 0xffff) >= 0xfffe ||\n\t\tcodePoint === 0xfffd\n\t);\n}\n\n/**\n * RFC 4518 §2.2 Map against the Unicode 3.2 repertoire: delete ignorable code\n * points, fold separators to SPACE, reject any code point prohibited in 3.2\n * before the host NFKC can reinterpret it, and freeze the CJK compatibility\n * ideographs whose NFKC decomposition Unicode 4.0 later corrected. Returns\n * `undefined` when a prohibited code point is present.\n */\nfunction mapAndProhibitSource(value: string): string | undefined {\n\tlet mapped = '';\n\tfor (const ch of value) {\n\t\tconst codePoint = ch.codePointAt(0);\n\t\tif (codePoint === undefined || inRanges(codePoint, MAP_TO_NOTHING)) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (inRanges(codePoint, MAP_TO_SPACE)) {\n\t\t\tmapped += ' ';\n\t\t\tcontinue;\n\t\t}\n\t\tif (isProhibited(codePoint)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tmapped += NFKC_3_2_CORRECTIONS.get(ch) ?? ch;\n\t}\n\treturn mapped;\n}\n\n/** RFC 3454 Appendix B.2 case fold, applied per code point with identity fallback. */\nfunction caseFold(value: string): string {\n\tlet out = '';\n\tfor (const ch of value) {\n\t\tout += B2_CASE_FOLD.get(ch) ?? ch;\n\t}\n\treturn out;\n}\n\n/**\n * RFC 4518 §2.6.1: collapses insignificant SPACE runs. A U+0020 followed by a\n * combining mark is significant (the base of a combining sequence) and stays.\n */\nfunction collapseInsignificantSpaces(value: string): string {\n\tlet collapsed = '';\n\tfor (let index = 0; index < value.length; ) {\n\t\tconst codePoint = value.codePointAt(index);\n\t\tif (codePoint === undefined) {\n\t\t\tbreak;\n\t\t}\n\t\tif (codePoint !== 0x20) {\n\t\t\tcollapsed += String.fromCodePoint(codePoint);\n\t\t\tindex += codePoint > 0xffff ? 2 : 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet nextIndex = index + 1;\n\t\twhile (value.codePointAt(nextIndex) === 0x20) {\n\t\t\tnextIndex += 1;\n\t\t}\n\t\tconst nextCodePoint = value.codePointAt(nextIndex);\n\t\tconst followedByCombiningMark =\n\t\t\tnextCodePoint !== undefined && inRanges(nextCodePoint, COMBINING_MARK_RANGES);\n\t\tif (followedByCombiningMark) {\n\t\t\t// Only the final SPACE in the run is the combining sequence's base.\n\t\t\t// Collapse any preceding, inner insignificant run separately.\n\t\t\tif (nextIndex - index > 1 && collapsed.length > 0) {\n\t\t\t\tcollapsed += ' ';\n\t\t\t}\n\t\t\tcollapsed += ' ';\n\t\t} else if (collapsed.length > 0 && nextCodePoint !== undefined) {\n\t\t\tcollapsed += ' ';\n\t\t}\n\t\tindex = nextIndex;\n\t}\n\treturn collapsed;\n}\n\n/**\n * Prepares a DirectoryString value for RFC 5280 §7.1 comparison through the RFC\n * 4518 Map, Normalize, Prohibit, and Insignificant Space steps against the\n * Unicode 3.2 repertoire. B.2 case folds first, the host NFKC runs once, and\n * the Prohibit set is rechecked on the output. Returns `undefined` when a\n * prohibited code point is present.\n */\nexport function prepareNameCompareString(value: string): string | undefined {\n\tconst mapped = mapAndProhibitSource(value);\n\tif (mapped === undefined) {\n\t\treturn undefined;\n\t}\n\tconst normalized = caseFold(mapped).normalize('NFKC');\n\tfor (const ch of normalized) {\n\t\tconst codePoint = ch.codePointAt(0);\n\t\tif (codePoint !== undefined && isProhibited(codePoint)) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\treturn collapseInsignificantSpaces(normalized);\n}\n\n/** Canonical string for a single RDN: attributes sorted, values prepared. */\nfunction canonicalRdnKey(rdn: ParsedRelativeDistinguishedName): string {\n\treturn rdn.attributes\n\t\t.map((attr) => {\n\t\t\tconst val = canonicalAttributeValue(attr);\n\t\t\treturn `${attr.oid}=${escapeCanonicalDnValue(val)}`;\n\t\t})\n\t\t.sort()\n\t\t.join('+');\n}\n\n/** Tag-independent canonical value for one attribute, matching {@linkcode compareNameAttributeValue}. */\nfunction canonicalAttributeValue(attr: ParsedNameAttribute): string {\n\tif (attr.oid === OIDS.domainComponent && attr.valueTag === 0x16 && isAscii(attr.value)) {\n\t\treturn `[dc]${prepareNameCompareString(attr.value) ?? attr.value.toLowerCase()}`;\n\t}\n\tif (attr.oid === OIDS.emailAddress && attr.valueTag === 0x16 && isAscii(attr.value)) {\n\t\treturn `[email]${attr.value.toLowerCase()}`;\n\t}\n\tif (isDirectoryStringTag(attr.valueTag)) {\n\t\treturn prepareNameCompareString(attr.value) ?? `[raw:${attr.valueTag}]${attr.value}`;\n\t}\n\treturn `[${String(attr.valueTag)}]${attr.value}`;\n}\n\nfunction escapeCanonicalDnValue(value: string): string {\n\treturn value\n\t\t.replaceAll('\\\\', '\\\\\\\\')\n\t\t.replaceAll(',', '\\\\,')\n\t\t.replaceAll('+', '\\\\+')\n\t\t.replaceAll('=', '\\\\=');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA+BA,SAAgB,0BAA0B,GAAkB,GAA4B;CACvF,IAAIA,EAAK,KAAK,WAAWC,EAAM,KAAK,QACnC,OAAO;CAER,KAAK,IAAIC,IAAQ,GAAGA,IAAQF,EAAK,KAAK,QAAQ,KAAS,GAAG;EACzD,IAAMG,IAAUH,EAAK,KAAKE,IACpBE,IAAWH,EAAM,KAAKC;EAI5B,IAHIC,MAAY,KAAA,KAAaC,MAAa,KAAA,KAGtC,CAAC,kCAAkCD,GAASC,CAAQ,GACvD,OAAO;CAET;CACA,OAAO;AACR;;;;;;;AAQA,SAAgB,eAAe,GAA0B;CACxD,OAAOC,EAAK,KAAK,IAAI,eAAe,CAAC,CAAC,KAAK,GAAG;AAC/C;;AAGA,SAAgB,6BAA6B,GAAqB,GAAiC;CAClG,OAAO,0BAA0BC,GAASC,CAAU,MAAM;AAC3D;;AASA,SAAgB,0BAA0B,GAAqB,GAAmC;CACjG,IAAIA,EAAW,KAAK,SAASD,EAAQ,KAAK,QACzC,OAAO;CAER,IAAIE,IAAe;CACnB,KAAK,IAAIN,IAAQ,GAAGA,IAAQK,EAAW,KAAK,QAAQ,KAAS,GAAG;EAC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UAAU,MAAM;CACpD,KAAK,IAAMF,KAAMU,GAAY;EAC5B,IAAMX,IAAYC,EAAG,YAAY,CAAC;EAClC,IAAID,MAAc,KAAA,KAAa,aAAaA,CAAS,GACpD;CAEF;CACA,OAAO,4BAA4BW,CAAU;AAC9C;;AAGA,SAAS,gBAAgB,GAA8C;CACtE,OAAOC,EAAI,WACT,KAAK,MAAS;EACd,IAAMC,IAAM,wBAAwBC,CAAI;EACxC,OAAO,GAAGA,EAAK,IAAI,GAAG,uBAAuBD,CAAG;CACjD,CAAC,CAAC,CACD,KAAK,CAAC,CACN,KAAK,GAAG;AACX;;AAGA,SAAS,wBAAwB,GAAmC;CAUnE,OATIC,EAAK,QAAQvB,EAAK,mBAAmBuB,EAAK,aAAa,MAAQ,QAAQA,EAAK,KAAK,IAC7E,OAAO,yBAAyBA,EAAK,KAAK,KAAKA,EAAK,MAAM,YAAY,MAE1EA,EAAK,QAAQvB,EAAK,gBAAgBuB,EAAK,aAAa,MAAQ,QAAQA,EAAK,KAAK,IAC1E,UAAUA,EAAK,MAAM,YAAY,MAErC,qBAAqBA,EAAK,QAAQ,IAC9B,yBAAyBA,EAAK,KAAK,KAAK,QAAQA,EAAK,SAAS,GAAGA,EAAK,UAEvE,IAAI,OAAOA,EAAK,QAAQ,EAAE,GAAGA,EAAK;AAC1C;AAEA,SAAS,uBAAuB,GAAuB;CACtD,OAAOrB,EACL,WAAW,MAAM,MAAM,CAAC,CACxB,WAAW,KAAK,KAAK,CAAC,CACtB,WAAW,KAAK,KAAK,CAAC,CACtB,WAAW,KAAK,KAAK;AACxB"}
|
|
1
|
+
{"version":3,"file":"dn.js","names":["OIDS","A1_UNASSIGNED_RANGES","B2_CASE_FOLD","NFKC_3_2_CORRECTIONS","COMBINING_MARK_RANGES","left","right","index","leftRdn","rightRdn","name","subject","constraint","undetermined","subjectRdn","constraintRdn","match","leftClasses","rightClasses","comparisonClass","leftClass","rightClass","attributes","classes","attribute","comparison","from","to","unpaired","key","count","INCOMPARABLE","value","prepared","tag","MAP_TO_NOTHING","MAP_TO_SPACE","codePoint","ranges","first","last","ch","mapped","out","collapsed","nextIndex","nextCodePoint","normalized","rdn","attr","val"],"sources":["../../../src/internal/shared/dn.ts"],"sourcesContent":["/**\n * Distinguished name comparison utilities implementing RFC 5280 §7.1, which\n * defers string preparation to the RFC 4518 LDAP profile.\n *\n * {@linkcode prepareNameCompareString} runs the RFC 4518 Map, Normalize,\n * Prohibit, and Insignificant Space steps with RFC 3454 Appendix B.2 case\n * folding. The Prohibit step rejects code points unassigned in the running\n * Unicode version; RFC 3454 Table A.1 pins that set to Unicode 3.2.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc4518 | RFC 4518}\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#section-7.1 | RFC 5280 §7.1}\n * @module\n */\n\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport type { CodePointRange } from '#micro509/internal/shared/rfc3454-tables';\nimport {\n\tA1_UNASSIGNED_RANGES,\n\tB2_CASE_FOLD,\n\tNFKC_3_2_CORRECTIONS,\n} from '#micro509/internal/shared/rfc3454-tables';\nimport { COMBINING_MARK_RANGES } from '#micro509/internal/shared/rfc4518-tables';\nimport type {\n\tParsedName,\n\tParsedNameAttribute,\n\tParsedRelativeDistinguishedName,\n} from '#micro509/x509/parse';\n\n// Public API\n\n/** RFC 5280 [§7.1](https://datatracker.ietf.org/doc/html/rfc5280#section-7.1) semantic equality: same RDN count, each pair matches attribute-by-attribute. */\nexport function compareDistinguishedNames(left: ParsedName, right: ParsedName): boolean {\n\tif (left.rdns.length !== right.rdns.length) {\n\t\treturn false;\n\t}\n\tfor (let index = 0; index < left.rdns.length; index += 1) {\n\t\tconst leftRdn = left.rdns[index];\n\t\tconst rightRdn = right.rdns[index];\n\t\tif (leftRdn === undefined || rightRdn === undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!compareRelativeDistinguishedNames(leftRdn, rightRdn)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/**\n * Produces a deterministic string key for a parsed DN, suitable as a Map key.\n * Semantically equal DNs (per RFC 5280 [§7.1](https://datatracker.ietf.org/doc/html/rfc5280#section-7.1)) produce identical keys.\n *\n * Format: RDNs joined by `,`, attributes within each RDN sorted by OID then by prepared value, joined by `+`.\n */\nexport function canonicalDnKey(name: ParsedName): string {\n\treturn name.rdns.map(canonicalRdnKey).join(',');\n}\n\n/** True when `subject` equals or is subordinate to `constraint` (RDN prefix match). */\nexport function isWithinDirectoryNameSubtree(subject: ParsedName, constraint: ParsedName): boolean {\n\treturn directoryNameSubtreeMatch(subject, constraint) === 'match';\n}\n\n/**\n * Outcome of an RFC 5280 §7.1 name comparison. `undetermined` is the RFC 4518\n * Undefined result: a DirectoryString value that string preparation refuses.\n */\nexport type NameMatch = 'match' | 'mismatch' | 'undetermined';\n\n/** {@linkcode isWithinDirectoryNameSubtree}, keeping an undetermined comparison apart from a mismatch. */\nexport function directoryNameSubtreeMatch(subject: ParsedName, constraint: ParsedName): NameMatch {\n\tif (constraint.rdns.length > subject.rdns.length) {\n\t\treturn 'mismatch';\n\t}\n\tlet undetermined = false;\n\tfor (let index = 0; index < constraint.rdns.length; index += 1) {\n\t\tconst subjectRdn = subject.rdns[index];\n\t\tconst constraintRdn = constraint.rdns[index];\n\t\tif (subjectRdn === undefined || constraintRdn === undefined) {\n\t\t\treturn 'mismatch';\n\t\t}\n\t\tconst match = relativeDistinguishedNameMatch(subjectRdn, constraintRdn);\n\t\tif (match === 'mismatch') {\n\t\t\treturn 'mismatch';\n\t\t}\n\t\tundetermined ||= match === 'undetermined';\n\t}\n\treturn undetermined ? 'undetermined' : 'match';\n}\n\n// RDN / attribute comparison\n\n/** Order-independent RDN equality: same attribute count, each pair matched exactly once. */\nexport function compareRelativeDistinguishedNames(\n\tleft: ParsedRelativeDistinguishedName,\n\tright: ParsedRelativeDistinguishedName,\n): boolean {\n\treturn relativeDistinguishedNameMatch(left, right) === 'match';\n}\n\n/**\n * `match` when the two RDNs' attributes pair one to one with every pair\n * matching, else `undetermined` when they pair with Undefined pairs allowed.\n */\nfunction relativeDistinguishedNameMatch(\n\tleft: ParsedRelativeDistinguishedName,\n\tright: ParsedRelativeDistinguishedName,\n): NameMatch {\n\tif (left.attributes.length !== right.attributes.length) {\n\t\treturn 'mismatch';\n\t}\n\tconst leftClasses = comparisonClasses(left.attributes);\n\tconst rightClasses = comparisonClasses(right.attributes);\n\tif (leftClasses === undefined || rightClasses === undefined) {\n\t\treturn 'mismatch';\n\t}\n\tlet undetermined = false;\n\tfor (const [comparisonClass, leftClass] of leftClasses) {\n\t\tconst rightClass = rightClasses.get(comparisonClass);\n\t\tif (rightClass === undefined || rightClass.size !== leftClass.size) {\n\t\t\treturn 'mismatch';\n\t\t}\n\t\tif (\n\t\t\tunpairedKeys(leftClass, rightClass) > rightClass.unprepared ||\n\t\t\tunpairedKeys(rightClass, leftClass) > leftClass.unprepared\n\t\t) {\n\t\t\treturn 'mismatch';\n\t\t}\n\t\tundetermined ||= leftClass.unprepared > 0 || rightClass.unprepared > 0;\n\t}\n\treturn undetermined ? 'undetermined' : 'match';\n}\n\n/** The attributes of one comparison class in an RDN. */\ninterface ComparisonClass {\n\treadonly keys: Map<string, number>;\n\tunprepared: number;\n\tsize: number;\n}\n\n/** An RDN's attributes by comparison class, or `undefined` when one of them is incomparable. */\nfunction comparisonClasses(\n\tattributes: readonly ParsedNameAttribute[],\n): Map<string, ComparisonClass> | undefined {\n\tconst classes = new Map<string, ComparisonClass>();\n\tfor (const attribute of attributes) {\n\t\tconst comparison = attributeComparison(attribute);\n\t\tif (comparison.type === 'incomparable') {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst comparisonClass = classes.get(comparison.comparisonClass) ?? {\n\t\t\tkeys: new Map<string, number>(),\n\t\t\tunprepared: 0,\n\t\t\tsize: 0,\n\t\t};\n\t\tcomparisonClass.size += 1;\n\t\tif (comparison.type === 'unprepared') {\n\t\t\tcomparisonClass.unprepared += 1;\n\t\t} else {\n\t\t\tcomparisonClass.keys.set(comparison.key, (comparisonClass.keys.get(comparison.key) ?? 0) + 1);\n\t\t}\n\t\tclasses.set(comparison.comparisonClass, comparisonClass);\n\t}\n\treturn classes;\n}\n\n/** How many keyed attributes of `from` find no equal key left in `to`. */\nfunction unpairedKeys(from: ComparisonClass, to: ComparisonClass): number {\n\tlet unpaired = 0;\n\tfor (const [key, count] of from.keys) {\n\t\tunpaired += Math.max(0, count - (to.keys.get(key) ?? 0));\n\t}\n\treturn unpaired;\n}\n\n/** Compares two AttributeTypeAndValue pairs using RFC 5280 [§7.1](https://datatracker.ietf.org/doc/html/rfc5280#section-7.1) string-prep for DirectoryString tags. */\nexport function compareNameAttributeValue(\n\tleft: ParsedNameAttribute,\n\tright: ParsedNameAttribute,\n): boolean {\n\treturn nameAttributeValueMatch(left, right) === 'match';\n}\n\nfunction nameAttributeValueMatch(left: ParsedNameAttribute, right: ParsedNameAttribute): NameMatch {\n\tconst leftComparison = attributeComparison(left);\n\tconst rightComparison = attributeComparison(right);\n\tif (\n\t\tleftComparison.type === 'incomparable' ||\n\t\trightComparison.type === 'incomparable' ||\n\t\tleftComparison.comparisonClass !== rightComparison.comparisonClass\n\t) {\n\t\treturn 'mismatch';\n\t}\n\tif (leftComparison.type === 'keyed' && rightComparison.type === 'keyed') {\n\t\treturn leftComparison.key === rightComparison.key ? 'match' : 'mismatch';\n\t}\n\treturn 'undetermined';\n}\n\n/**\n * How an attribute value takes part in matching. Two attributes match when\n * they share a comparison class and a key, a value string preparation refuses\n * is Undefined against every value of its class, and an incomparable value\n * matches nothing.\n */\ntype AttributeComparison =\n\t| { readonly type: 'keyed'; readonly comparisonClass: string; readonly key: string }\n\t| { readonly type: 'unprepared'; readonly comparisonClass: string }\n\t| { readonly type: 'incomparable' };\n\nconst INCOMPARABLE: AttributeComparison = { type: 'incomparable' };\n\nfunction attributeComparison(attribute: ParsedNameAttribute): AttributeComparison {\n\tif (attribute.oid === OIDS.domainComponent) {\n\t\t// RFC 5280 §7.3 / RFC 4519 caseIgnoreIA5Match: domainComponent is\n\t\t// IA5String, prepared and compared case-insensitively with insignificant\n\t\t// spaces collapsed.\n\t\treturn attribute.valueTag === 0x16 && isAscii(attribute.value)\n\t\t\t? preparedComparison(`${attribute.oid} ia5`, attribute.value)\n\t\t\t: INCOMPARABLE;\n\t}\n\t// RFC 5280 §4.1.2.6 and RFC 2985 §6.1 pkcs9CaseIgnoreMatch: emailAddress is\n\t// IA5String, matched character by character without regard to case and\n\t// without the RFC 4518 space collapsing a DirectoryString attribute gets.\n\t// Under any other tag the value falls through to the general comparison.\n\tif (\n\t\tattribute.oid === OIDS.emailAddress &&\n\t\tattribute.valueTag === 0x16 &&\n\t\tisAscii(attribute.value)\n\t) {\n\t\treturn {\n\t\t\ttype: 'keyed',\n\t\t\tcomparisonClass: `${attribute.oid} exact`,\n\t\t\tkey: `ia5 ${attribute.value.toLowerCase()}`,\n\t\t};\n\t}\n\tif (isDirectoryStringTag(attribute.valueTag)) {\n\t\treturn preparedComparison(`${attribute.oid} directory`, attribute.value);\n\t}\n\treturn {\n\t\ttype: 'keyed',\n\t\tcomparisonClass: `${attribute.oid} exact`,\n\t\tkey: `${attribute.valueTag} ${attribute.value}`,\n\t};\n}\n\nfunction preparedComparison(comparisonClass: string, value: string): AttributeComparison {\n\tconst prepared = prepareNameCompareString(value);\n\treturn prepared === undefined\n\t\t? { type: 'unprepared', comparisonClass }\n\t\t: { type: 'keyed', comparisonClass, key: prepared };\n}\n\n// Helpers\n\n/**\n * True for the DirectoryString alternatives compared after RFC 4518\n * preparation: UTF8String (0x0C), PrintableString (0x13), TeletexString (0x14,\n * transcoded by RFC 4518 §2.1's local mapping at decode time), UniversalString\n * (0x1C), and BMPString (0x1E).\n */\nexport function isDirectoryStringTag(tag: number): boolean {\n\treturn tag === 0x0c || tag === 0x13 || tag === 0x14 || tag === 0x1c || tag === 0x1e;\n}\n\n/** RFC 4518 §2.2: code points deleted (Cc/Cf controls, joiners, ignorables). */\nconst MAP_TO_NOTHING: readonly CodePointRange[] = [\n\t[0x0000, 0x0008], // C0 controls NUL..BS\n\t[0x000e, 0x001f], // C0 controls SO..US\n\t[0x007f, 0x0084], // DEL, C1 controls\n\t[0x0086, 0x009f], // C1 controls\n\t[0x00ad, 0x00ad], // SOFT HYPHEN\n\t[0x034f, 0x034f], // COMBINING GRAPHEME JOINER\n\t[0x06dd, 0x06dd], // ARABIC END OF AYAH\n\t[0x070f, 0x070f], // SYRIAC ABBREVIATION MARK\n\t[0x1806, 0x1806], // MONGOLIAN TODO SOFT HYPHEN\n\t[0x180b, 0x180e], // variation selectors, MONGOLIAN VOWEL SEPARATOR\n\t[0x200b, 0x200f], // ZWSP, ZWNJ, ZWJ, LRM, RLM\n\t[0x202a, 0x202e], // bidi embedding/override controls\n\t[0x2060, 0x2063], // WORD JOINER, invisible operators\n\t[0x206a, 0x206f], // deprecated format controls\n\t[0xfe00, 0xfe0f], // variation selectors\n\t[0xfeff, 0xfeff], // ZERO WIDTH NO-BREAK SPACE (BOM)\n\t[0xfff9, 0xfffc], // interlinear annotations, OBJECT REPLACEMENT CHARACTER\n\t[0x1d173, 0x1d17a], // musical symbol format controls\n\t[0xe0001, 0xe0001], // LANGUAGE TAG\n\t[0xe0020, 0xe007f], // tag characters\n];\n\n/** RFC 4518 §2.2: code points mapped to SPACE (control whitespace and Zs/Zl/Zp). */\nconst MAP_TO_SPACE: readonly CodePointRange[] = [\n\t[0x0009, 0x000d], // TAB, LF, VT, FF, CR\n\t[0x0085, 0x0085], // NEL\n\t[0x00a0, 0x00a0], // NO-BREAK SPACE\n\t[0x1680, 0x1680], // OGHAM SPACE MARK\n\t[0x2000, 0x200a], // EN QUAD .. HAIR SPACE\n\t[0x2028, 0x2029], // LINE SEPARATOR, PARAGRAPH SEPARATOR\n\t[0x202f, 0x202f], // NARROW NO-BREAK SPACE\n\t[0x205f, 0x205f], // MEDIUM MATHEMATICAL SPACE\n\t[0x3000, 0x3000], // IDEOGRAPHIC SPACE\n];\n\n/** True when `codePoint` falls in one of the inclusive `ranges`. */\nfunction inRanges(codePoint: number, ranges: readonly CodePointRange[]): boolean {\n\treturn ranges.some(([first, last]) => codePoint >= first && codePoint <= last);\n}\n\n/** True when every code point in `value` is ASCII. */\nfunction isAscii(value: string): boolean {\n\tfor (const ch of value) {\n\t\tconst codePoint = ch.codePointAt(0);\n\t\tif (codePoint === undefined || codePoint > 0x7f) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/**\n * RFC 4518 §2.4 Prohibit against the frozen Unicode 3.2 repertoire: code points\n * unassigned in 3.2 (RFC 3454 Table A.1), private use, surrogate, non-character,\n * and the replacement character. `\\p{Cn}` is avoided because it tracks the\n * running Unicode version rather than 3.2.\n */\nfunction isProhibited(codePoint: number): boolean {\n\treturn (\n\t\tinRanges(codePoint, A1_UNASSIGNED_RANGES) ||\n\t\t(codePoint >= 0xe000 && codePoint <= 0xf8ff) ||\n\t\t(codePoint >= 0xf0000 && codePoint <= 0xffffd) ||\n\t\t(codePoint >= 0x100000 && codePoint <= 0x10fffd) ||\n\t\t(codePoint >= 0xd800 && codePoint <= 0xdfff) ||\n\t\t(codePoint >= 0xfdd0 && codePoint <= 0xfdef) ||\n\t\t(codePoint & 0xffff) >= 0xfffe ||\n\t\tcodePoint === 0xfffd\n\t);\n}\n\n/**\n * RFC 4518 §2.2 Map against the Unicode 3.2 repertoire: delete ignorable code\n * points, fold separators to SPACE, reject any code point prohibited in 3.2\n * before the host NFKC can reinterpret it, and freeze the CJK compatibility\n * ideographs whose NFKC decomposition Unicode 4.0 later corrected. Returns\n * `undefined` when a prohibited code point is present.\n */\nfunction mapAndProhibitSource(value: string): string | undefined {\n\tlet mapped = '';\n\tfor (const ch of value) {\n\t\tconst codePoint = ch.codePointAt(0);\n\t\tif (codePoint === undefined || inRanges(codePoint, MAP_TO_NOTHING)) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (inRanges(codePoint, MAP_TO_SPACE)) {\n\t\t\tmapped += ' ';\n\t\t\tcontinue;\n\t\t}\n\t\tif (isProhibited(codePoint)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tmapped += NFKC_3_2_CORRECTIONS.get(ch) ?? ch;\n\t}\n\treturn mapped;\n}\n\n/** RFC 3454 Appendix B.2 case fold, applied per code point with identity fallback. */\nfunction caseFold(value: string): string {\n\tlet out = '';\n\tfor (const ch of value) {\n\t\tout += B2_CASE_FOLD.get(ch) ?? ch;\n\t}\n\treturn out;\n}\n\n/**\n * RFC 4518 §2.6.1: collapses insignificant SPACE runs. A U+0020 followed by a\n * combining mark is significant (the base of a combining sequence) and stays.\n */\nfunction collapseInsignificantSpaces(value: string): string {\n\tlet collapsed = '';\n\tfor (let index = 0; index < value.length; ) {\n\t\tconst codePoint = value.codePointAt(index);\n\t\tif (codePoint === undefined) {\n\t\t\tbreak;\n\t\t}\n\t\tif (codePoint !== 0x20) {\n\t\t\tcollapsed += String.fromCodePoint(codePoint);\n\t\t\tindex += codePoint > 0xffff ? 2 : 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet nextIndex = index + 1;\n\t\twhile (value.codePointAt(nextIndex) === 0x20) {\n\t\t\tnextIndex += 1;\n\t\t}\n\t\tconst nextCodePoint = value.codePointAt(nextIndex);\n\t\tconst followedByCombiningMark =\n\t\t\tnextCodePoint !== undefined && inRanges(nextCodePoint, COMBINING_MARK_RANGES);\n\t\tif (followedByCombiningMark) {\n\t\t\t// Only the final SPACE in the run is the combining sequence's base.\n\t\t\t// Collapse any preceding, inner insignificant run separately.\n\t\t\tif (nextIndex - index > 1 && collapsed.length > 0) {\n\t\t\t\tcollapsed += ' ';\n\t\t\t}\n\t\t\tcollapsed += ' ';\n\t\t} else if (collapsed.length > 0 && nextCodePoint !== undefined) {\n\t\t\tcollapsed += ' ';\n\t\t}\n\t\tindex = nextIndex;\n\t}\n\treturn collapsed;\n}\n\n/**\n * Prepares a DirectoryString value for RFC 5280 §7.1 comparison through the RFC\n * 4518 Map, Normalize, Prohibit, and Insignificant Space steps against the\n * Unicode 3.2 repertoire. B.2 case folds first, the host NFKC runs once, and\n * the Prohibit set is rechecked on the output. Returns `undefined` when a\n * prohibited code point is present.\n */\nexport function prepareNameCompareString(value: string): string | undefined {\n\tconst mapped = mapAndProhibitSource(value);\n\tif (mapped === undefined) {\n\t\treturn undefined;\n\t}\n\tconst normalized = caseFold(mapped).normalize('NFKC');\n\tfor (const ch of normalized) {\n\t\tconst codePoint = ch.codePointAt(0);\n\t\tif (codePoint !== undefined && isProhibited(codePoint)) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\treturn collapseInsignificantSpaces(normalized);\n}\n\n/** Canonical string for a single RDN: attributes sorted, values prepared. */\nfunction canonicalRdnKey(rdn: ParsedRelativeDistinguishedName): string {\n\treturn rdn.attributes\n\t\t.map((attr) => {\n\t\t\tconst val = canonicalAttributeValue(attr);\n\t\t\treturn `${attr.oid}=${escapeCanonicalDnValue(val)}`;\n\t\t})\n\t\t.sort()\n\t\t.join('+');\n}\n\n/** Tag-independent canonical value for one attribute, matching {@linkcode compareNameAttributeValue}. */\nfunction canonicalAttributeValue(attr: ParsedNameAttribute): string {\n\tif (attr.oid === OIDS.domainComponent && attr.valueTag === 0x16 && isAscii(attr.value)) {\n\t\treturn `[dc]${prepareNameCompareString(attr.value) ?? attr.value.toLowerCase()}`;\n\t}\n\tif (attr.oid === OIDS.emailAddress && attr.valueTag === 0x16 && isAscii(attr.value)) {\n\t\treturn `[email]${attr.value.toLowerCase()}`;\n\t}\n\tif (isDirectoryStringTag(attr.valueTag)) {\n\t\treturn prepareNameCompareString(attr.value) ?? `[raw:${attr.valueTag}]${attr.value}`;\n\t}\n\treturn `[${String(attr.valueTag)}]${attr.value}`;\n}\n\nfunction escapeCanonicalDnValue(value: string): string {\n\treturn value\n\t\t.replaceAll('\\\\', '\\\\\\\\')\n\t\t.replaceAll(',', '\\\\,')\n\t\t.replaceAll('+', '\\\\+')\n\t\t.replaceAll('=', '\\\\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