micro509 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2064 -0
- package/README.md +111 -183
- package/dist/crypto/crypto.d.ts +104 -0
- package/dist/crypto/crypto.js +105 -0
- package/dist/crypto/crypto.js.map +1 -0
- package/dist/crypto.d.ts +4 -0
- package/dist/crypto.js +1 -0
- package/dist/der/der.d.ts +41 -33
- package/dist/der/der.js +26 -24
- package/dist/der/der.js.map +1 -1
- package/dist/index.d.ts +18 -14
- package/dist/index.js +19 -17
- package/dist/internal/asn1/asn1.d.ts +3 -6
- package/dist/internal/asn1/asn1.js +355 -44
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/ber.js +146 -0
- package/dist/internal/asn1/ber.js.map +1 -0
- package/dist/internal/asn1/decode-refusal.js +29 -0
- package/dist/internal/asn1/decode-refusal.js.map +1 -0
- package/dist/internal/asn1/der.d.ts +42 -43
- package/dist/internal/asn1/der.js +148 -56
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js +90 -54
- package/dist/internal/asn1/oids.js.map +1 -1
- package/dist/internal/asn1/oids2.js +1 -2
- package/dist/internal/asn1/oids2.js.map +1 -1
- package/dist/internal/crypto/algorithm-names.js +5 -2
- package/dist/internal/crypto/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/ecdsa.js +13 -8
- package/dist/internal/crypto/ecdsa.js.map +1 -1
- package/dist/internal/crypto/hash.js +1 -2
- package/dist/internal/crypto/hash.js.map +1 -1
- package/dist/internal/crypto/pbes2.d.ts +51 -0
- package/dist/internal/crypto/pbes2.js +86 -34
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/rsa-pss.js +48 -44
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +28 -0
- package/dist/internal/crypto/sig-verify.js +111 -62
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/crypto/signing.d.ts +1 -4
- package/dist/internal/crypto/signing.js +28 -29
- package/dist/internal/crypto/signing.js.map +1 -1
- package/dist/internal/crypto/webcrypto.js +1 -2
- package/dist/internal/crypto/webcrypto.js.map +1 -1
- package/dist/internal/shared/base64.js +8 -3
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.d.ts +13 -0
- package/dist/internal/shared/dn.js +101 -48
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/idna-tables.js +7217 -0
- package/dist/internal/shared/idna-tables.js.map +1 -0
- package/dist/internal/shared/idna.js +296 -0
- package/dist/internal/shared/idna.js.map +1 -0
- package/dist/internal/shared/ip.d.ts +66 -0
- package/dist/internal/shared/ip.js +19 -3
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/shared/mailbox.js +26 -0
- package/dist/internal/shared/mailbox.js.map +1 -0
- package/dist/internal/shared/punycode.js +101 -0
- package/dist/internal/shared/punycode.js.map +1 -0
- package/dist/internal/shared/rfc3454-tables.js +1 -2
- package/dist/internal/shared/rfc3454-tables.js.map +1 -1
- package/dist/internal/shared/rfc4518-tables.js +119 -0
- package/dist/internal/shared/rfc4518-tables.js.map +1 -0
- package/dist/internal/shared/uri-host.js +102 -0
- package/dist/internal/shared/uri-host.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +246 -131
- package/dist/internal/verify/name-constraints-engine.js.map +1 -1
- package/dist/internal/verify/policy-engine.js +6 -21
- package/dist/internal/verify/policy-engine.js.map +1 -1
- package/dist/internal/verify/verify-path.d.ts +4 -0
- package/dist/internal/verify/verify-path.js +264 -128
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/internal/x509/directory-name.js +23 -0
- package/dist/internal/x509/directory-name.js.map +1 -0
- package/dist/internal/x509/extension-bits.js +15 -13
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.d.ts +3 -0
- package/dist/internal/x509/extension-errors.js +19 -0
- package/dist/internal/x509/extension-errors.js.map +1 -0
- package/dist/internal/x509/extension-registry.js +157 -81
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-profile.js +129 -0
- package/dist/internal/x509/general-name-profile.js.map +1 -0
- package/dist/internal/x509/general-name-tags.js +27 -0
- package/dist/internal/x509/general-name-tags.js.map +1 -0
- package/dist/internal/x509/general-name.js +183 -0
- package/dist/internal/x509/general-name.js.map +1 -0
- package/dist/internal/x509/name-fields.js +21 -12
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/internal/x509/or-address.js +217 -0
- package/dist/internal/x509/or-address.js.map +1 -0
- package/dist/keys/keys.d.ts +124 -95
- package/dist/keys/keys.js +362 -214
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +3 -2
- package/dist/keys.js +3 -2
- package/dist/pem/pem.d.ts +17 -19
- package/dist/pem/pem.js +122 -41
- package/dist/pem/pem.js.map +1 -1
- package/dist/pem.js +1 -2
- package/dist/pkcs/pfx.d.ts +57 -32
- package/dist/pkcs/pfx.js +209 -173
- package/dist/pkcs/pfx.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.d.ts +104 -27
- package/dist/pkcs/pkcs12-mac.js +266 -79
- package/dist/pkcs/pkcs12-mac.js.map +1 -1
- package/dist/pkcs/pkcs7.d.ts +123 -53
- package/dist/pkcs/pkcs7.js +314 -238
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +5 -4
- package/dist/result/result.d.ts +43 -28
- package/dist/result/result.js +27 -14
- package/dist/result/result.js.map +1 -1
- package/dist/result.d.ts +2 -2
- package/dist/result.js +1 -2
- package/dist/revocation/chain.d.ts +101 -23
- package/dist/revocation/chain.js +456 -206
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +140 -65
- package/dist/revocation/crl.js +691 -391
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +145 -69
- package/dist/revocation/ocsp.js +347 -297
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +48 -36
- package/dist/revocation/revocation.js +112 -63
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +5 -5
- package/dist/revocation.js +5 -5
- package/dist/verify/identity.d.ts +18 -20
- package/dist/verify/identity.js +120 -90
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/name-constraints.d.ts +1 -4
- package/dist/verify/policy.d.ts +15 -8
- package/dist/verify/verify.d.ts +86 -46
- package/dist/verify/verify.js +309 -143
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +3 -2
- package/dist/verify.js +4 -3
- package/dist/x509/certificate.d.ts +50 -28
- package/dist/x509/certificate.js +69 -36
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.d.ts +9 -8
- package/dist/x509/csr.js +10 -11
- package/dist/x509/csr.js.map +1 -1
- package/dist/x509/extensions.d.ts +207 -82
- package/dist/x509/extensions.js +561 -128
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.d.ts +4 -7
- package/dist/x509/fingerprint.js +1 -2
- package/dist/x509/fingerprint.js.map +1 -1
- package/dist/x509/name-text.d.ts +7 -9
- package/dist/x509/name-text.js +20 -4
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.d.ts +15 -14
- package/dist/x509/name.js +23 -19
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +165 -64
- package/dist/x509/parse.js +444 -459
- package/dist/x509/parse.js.map +1 -1
- package/dist/x509.d.ts +8 -5
- package/dist/x509.js +10 -8
- package/package.json +90 -65
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/internal/asn1/oids.json
|
|
2
2
|
var e = {
|
|
3
3
|
$schema: "./oids.schema.json",
|
|
4
4
|
ituT: {
|
|
@@ -53,7 +53,8 @@ var e = {
|
|
|
53
53
|
arc: "5",
|
|
54
54
|
oids: {
|
|
55
55
|
pbkdf2: "12",
|
|
56
|
-
pbes2: "13"
|
|
56
|
+
pbes2: "13",
|
|
57
|
+
pbmac1: "14"
|
|
57
58
|
}
|
|
58
59
|
},
|
|
59
60
|
pkcs7: {
|
|
@@ -98,7 +99,9 @@ var e = {
|
|
|
98
99
|
arc: "2",
|
|
99
100
|
oids: {
|
|
100
101
|
hmacWithSHA1: "7",
|
|
101
|
-
hmacWithSHA256: "9"
|
|
102
|
+
hmacWithSHA256: "9",
|
|
103
|
+
hmacWithSHA384: "10",
|
|
104
|
+
hmacWithSHA512: "11"
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
}
|
|
@@ -150,64 +153,96 @@ var e = {
|
|
|
150
153
|
},
|
|
151
154
|
edwardsCurveAlgs: {
|
|
152
155
|
arc: "101",
|
|
153
|
-
oids: {
|
|
156
|
+
oids: {
|
|
157
|
+
x25519: "110",
|
|
158
|
+
x448: "111",
|
|
159
|
+
ed25519: "112",
|
|
160
|
+
ed448: "113"
|
|
161
|
+
}
|
|
154
162
|
},
|
|
155
163
|
dod: {
|
|
156
164
|
arc: "6",
|
|
157
165
|
children: { internet: {
|
|
158
166
|
arc: "1",
|
|
159
|
-
children: {
|
|
160
|
-
|
|
161
|
-
children: { mechanisms: {
|
|
167
|
+
children: {
|
|
168
|
+
security: {
|
|
162
169
|
arc: "5",
|
|
163
|
-
children: {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
arc: "
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
170
|
+
children: {
|
|
171
|
+
mechanisms: {
|
|
172
|
+
arc: "5",
|
|
173
|
+
children: { pkix: {
|
|
174
|
+
arc: "7",
|
|
175
|
+
children: {
|
|
176
|
+
extensions: {
|
|
177
|
+
arc: "1",
|
|
178
|
+
oids: { authorityInfoAccess: "1" }
|
|
179
|
+
},
|
|
180
|
+
policyQualifiers: {
|
|
181
|
+
arc: "2",
|
|
182
|
+
oids: {
|
|
183
|
+
cpsPolicyQualifier: "1",
|
|
184
|
+
userNoticePolicyQualifier: "2"
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
extendedKeyUsage: {
|
|
188
|
+
arc: "3",
|
|
189
|
+
oids: {
|
|
190
|
+
serverAuth: "1",
|
|
191
|
+
clientAuth: "2",
|
|
192
|
+
codeSigning: "3",
|
|
193
|
+
emailProtection: "4",
|
|
194
|
+
timeStamping: "8",
|
|
195
|
+
ocspSigning: "9"
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
otherNameForms: {
|
|
199
|
+
arc: "8",
|
|
200
|
+
oids: {
|
|
201
|
+
idOnDnsSrv: "7",
|
|
202
|
+
idOnSmtpUtf8Mailbox: "9"
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
accessMethods: {
|
|
206
|
+
arc: "48",
|
|
207
|
+
oids: {
|
|
208
|
+
ocspAccessMethod: "1",
|
|
209
|
+
caIssuersAccessMethod: "2"
|
|
210
|
+
},
|
|
211
|
+
children: { ocsp: {
|
|
212
|
+
arc: "1",
|
|
213
|
+
oids: {
|
|
214
|
+
ocspBasicResponse: "1",
|
|
215
|
+
ocspNonce: "2",
|
|
216
|
+
ocspNoCheck: "5"
|
|
217
|
+
}
|
|
218
|
+
} }
|
|
204
219
|
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
220
|
+
}
|
|
221
|
+
} }
|
|
222
|
+
},
|
|
223
|
+
kerberosV5: {
|
|
224
|
+
arc: "2",
|
|
225
|
+
oids: { idPkinitSan: "2" }
|
|
207
226
|
}
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
private: {
|
|
230
|
+
arc: "4",
|
|
231
|
+
children: { enterprise: {
|
|
232
|
+
arc: "1",
|
|
233
|
+
children: { microsoft: {
|
|
234
|
+
arc: "311",
|
|
235
|
+
children: { msEnrollment: {
|
|
236
|
+
arc: "20",
|
|
237
|
+
children: { msPrincipalNameForms: {
|
|
238
|
+
arc: "2",
|
|
239
|
+
oids: { ntPrincipalName: "3" }
|
|
240
|
+
} }
|
|
241
|
+
} }
|
|
242
|
+
} }
|
|
208
243
|
} }
|
|
209
|
-
}
|
|
210
|
-
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
211
246
|
} }
|
|
212
247
|
},
|
|
213
248
|
oiw: {
|
|
@@ -252,6 +287,7 @@ var e = {
|
|
|
252
287
|
subjectKeyIdentifier: "14",
|
|
253
288
|
keyUsage: "15",
|
|
254
289
|
subjectAltName: "17",
|
|
290
|
+
issuerAltName: "18",
|
|
255
291
|
basicConstraints: "19",
|
|
256
292
|
cRLNumber: "20",
|
|
257
293
|
cRLReason: "21",
|
|
@@ -267,7 +303,8 @@ var e = {
|
|
|
267
303
|
policyConstraints: "36",
|
|
268
304
|
extendedKeyUsage: "37",
|
|
269
305
|
freshestCRL: "46",
|
|
270
|
-
inhibitAnyPolicy: "54"
|
|
306
|
+
inhibitAnyPolicy: "54",
|
|
307
|
+
noRevAvail: "56"
|
|
271
308
|
},
|
|
272
309
|
children: { certificatePolicies: {
|
|
273
310
|
arc: "32",
|
|
@@ -315,7 +352,6 @@ var e = {
|
|
|
315
352
|
}
|
|
316
353
|
}
|
|
317
354
|
};
|
|
318
|
-
//#endregion
|
|
319
355
|
export { e as default };
|
|
320
356
|
|
|
321
357
|
//# sourceMappingURL=oids.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oids.js","names":[],"sources":["../../../src/internal/asn1/oids.json"],"sourcesContent":[""],"mappings":""}
|
|
1
|
+
{"version":3,"file":"oids.js","names":["oids_default","\"arc\"","\"children\"","\"data\"","\"pss\"","\"ucl\"","\"pilot\"","\"pilotAttributeType\"","\"oids\"","\"userId\"","\"domainComponent\"","\"memberBody\"","\"us\"","\"rsadsi\"","\"pkcs\"","\"pkcs1\"","\"rsaEncryption\"","\"sha1WithRSAEncryption\"","\"mgf1\"","\"rsassaPss\"","\"sha256WithRSAEncryption\"","\"sha384WithRSAEncryption\"","\"sha512WithRSAEncryption\"","\"pkcs5\"","\"pbkdf2\"","\"pbes2\"","\"pbmac1\"","\"pkcs7\"","\"pkcs7Data\"","\"pkcs7SignedData\"","\"pkcs7EncryptedData\"","\"pkcs9\"","\"emailAddress\"","\"cmsContentType\"","\"cmsMessageDigest\"","\"extensionRequest\"","\"friendlyName\"","\"localKeyId\"","\"certTypes\"","\"x509CertificateBagType\"","\"pkcs12Bags\"","\"bagTypes\"","\"bags\"","\"pkcs12KeyBag\"","\"pkcs12CertBag\"","\"digestAlgorithm\"","\"hmacWithSHA1\"","\"hmacWithSHA256\"","\"hmacWithSHA384\"","\"hmacWithSHA512\"","\"ansiX962\"","\"keyType\"","\"ecPublicKey\"","\"curves\"","\"prime\"","\"prime256v1\"","\"signatures\"","\"ecdsaWithSHA1\"","\"sha2\"","\"ecdsaWithSHA224\"","\"ecdsaWithSHA256\"","\"ecdsaWithSHA384\"","\"ecdsaWithSHA512\"","\"identifiedOrganization\"","\"certicom\"","\"curve\"","\"secp384r1\"","\"secp521r1\"","\"edwardsCurveAlgs\"","\"x25519\"","\"x448\"","\"ed25519\"","\"ed448\"","\"dod\"","\"internet\"","\"security\"","\"mechanisms\"","\"pkix\"","\"extensions\"","\"authorityInfoAccess\"","\"policyQualifiers\"","\"cpsPolicyQualifier\"","\"userNoticePolicyQualifier\"","\"extendedKeyUsage\"","\"serverAuth\"","\"clientAuth\"","\"codeSigning\"","\"emailProtection\"","\"timeStamping\"","\"ocspSigning\"","\"otherNameForms\"","\"idOnDnsSrv\"","\"idOnSmtpUtf8Mailbox\"","\"accessMethods\"","\"ocspAccessMethod\"","\"caIssuersAccessMethod\"","\"ocsp\"","\"ocspBasicResponse\"","\"ocspNonce\"","\"ocspNoCheck\"","\"kerberosV5\"","\"idPkinitSan\"","\"private\"","\"enterprise\"","\"microsoft\"","\"msEnrollment\"","\"msPrincipalNameForms\"","\"ntPrincipalName\"","\"oiw\"","\"secsig\"","\"algorithms\"","\"sha1\"","\"ds\"","\"attributeType\"","\"commonName\"","\"surname\"","\"serialNumber\"","\"countryName\"","\"localityName\"","\"stateOrProvinceName\"","\"streetAddress\"","\"organizationName\"","\"organizationalUnitName\"","\"title\"","\"givenName\"","\"certificateExtension\"","\"subjectKeyIdentifier\"","\"keyUsage\"","\"subjectAltName\"","\"issuerAltName\"","\"basicConstraints\"","\"cRLNumber\"","\"cRLReason\"","\"invalidityDate\"","\"deltaCRLIndicator\"","\"issuingDistributionPoint\"","\"certificateIssuer\"","\"nameConstraints\"","\"cRLDistributionPoints\"","\"certificatePolicies\"","\"policyMappings\"","\"authorityKeyIdentifier\"","\"policyConstraints\"","\"freshestCRL\"","\"inhibitAnyPolicy\"","\"noRevAvail\"","\"anyPolicy\"","\"country\"","\"organization\"","\"gov\"","\"csor\"","\"nistAlgorithms\"","\"aes\"","\"aes128Cbc\"","\"aes192Cbc\"","\"aes256Cbc\"","\"hashes\"","\"sha256\"","\"sha384\"","\"sha512\""],"sources":["../../../src/internal/asn1/oids.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import e from "./oids.js";
|
|
2
|
-
|
|
2
|
+
// src/internal/asn1/oids.ts
|
|
3
3
|
/**
|
|
4
4
|
* Centralized ASN.1 object identifier registry referenced by create, parse,
|
|
5
5
|
* verify, and container modules.
|
|
@@ -70,7 +70,6 @@ function flattenOidTree(e) {
|
|
|
70
70
|
* - hash algorithms.
|
|
71
71
|
*/
|
|
72
72
|
const t = flattenOidTree(e);
|
|
73
|
-
//#endregion
|
|
74
73
|
export { t as OIDS, e as OID_GROUP_SPECS };
|
|
75
74
|
|
|
76
75
|
//# sourceMappingURL=oids2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oids2.js","names":["OID_GROUP_SPECS"],"sources":["../../../src/internal/asn1/oids.ts"],"sourcesContent":["/**\n * Centralized ASN.1 object identifier registry referenced by create, parse,\n * verify, and container modules.\n *\n * All OIDs are dotted-decimal string constants keyed by their common short name.\n *\n * @module\n */\n\nimport OID_GROUP_SPECS from './oids.json' with { type: 'json' };\n\ntype OidLeaves = { readonly [name: string]: string };\ntype OidNode = {\n\treadonly arc: string;\n\treadonly oids?: OidLeaves;\n\treadonly children?: OidTree;\n};\ntype OidTree = { readonly [name: string]: OidNode };\ntype OidMap = { readonly [name: string]: string };\ntype MutableOidMap = { [name: string]: string };\ndeclare const oidNameBrand: unique symbol;\ntype OidValue<Name extends string, Value extends string> = Value & {\n\treadonly [oidNameBrand]?: Name;\n};\ntype JoinOidPrefix<Base extends string, Arc extends string> = Base extends ''\n\t? Arc\n\t: `${Base}.${Arc}`;\ntype OidsFromLeaves<Prefix extends string, Leaves extends OidLeaves> = {\n\treadonly [Name in keyof Leaves]: OidValue<Name & string, `${Prefix}.${Leaves[Name]}`>;\n};\ntype UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends (\n\tvalue: infer Intersection,\n) => void\n\t? Intersection\n\t: never;\ntype OidsFromNode<Node extends OidNode, Base extends string = ''> = Node extends {\n\treadonly arc: infer Arc extends string;\n}\n\t? (Node extends { readonly oids: infer Leaves extends OidLeaves }\n\t\t\t? OidsFromLeaves<JoinOidPrefix<Base, Arc>, Leaves>\n\t\t\t: unknown) &\n\t\t\t(Node extends { readonly children: infer Children extends OidTree }\n\t\t\t\t? OidsFromTree<Children, JoinOidPrefix<Base, Arc>>\n\t\t\t\t: unknown)\n\t: never;\ntype OidsFromTree<Tree extends OidTree, Base extends string = ''> = UnionToIntersection<\n\tOidsFromNode<Tree[keyof Tree], Base>\n>;\ntype OidDocumentRoots<Document> = Omit<Document, '$schema'>;\ntype OidRegistry = OidsFromTree<OidDocumentRoots<typeof OID_GROUP_SPECS>>;\n\nfunction joinOidPrefix(basePrefix: string, arc: string): string {\n\tif (basePrefix === '') {\n\t\treturn arc;\n\t}\n\n\treturn `${basePrefix}.${arc}`;\n}\n\nfunction isOidNode(value: unknown): value is OidNode {\n\treturn typeof value === 'object' && value !== null && 'arc' in value;\n}\n\nfunction hasOidName(oids: OidMap, name: string): boolean {\n\treturn Object.hasOwn(oids, name);\n}\n\nfunction addOidNode(oids: MutableOidMap, node: OidNode, basePrefix: string): void {\n\tconst prefix = joinOidPrefix(basePrefix, node.arc);\n\n\tif (node.oids !== undefined) {\n\t\tfor (const [name, arc] of Object.entries(node.oids)) {\n\t\t\tconst path = joinOidPrefix(prefix, arc);\n\t\t\tif (hasOidName(oids, name)) {\n\t\t\t\tconst existingPath = oids[name];\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Duplicate OID name \"${name}\" at ${path}; already assigned to ${existingPath}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\toids[name] = path;\n\t\t}\n\t}\n\n\tif (node.children !== undefined) {\n\t\taddOidTree(oids, node.children, prefix);\n\t}\n}\n\nfunction addOidTree(oids: MutableOidMap, tree: OidTree, basePrefix: string): void {\n\tfor (const node of Object.values(tree)) {\n\t\taddOidNode(oids, node, basePrefix);\n\t}\n}\n\nfunction addOidDocument(oids: MutableOidMap, document: typeof OID_GROUP_SPECS): void {\n\tfor (const value of Object.values(document)) {\n\t\tif (isOidNode(value)) {\n\t\t\taddOidNode(oids, value, '');\n\t\t}\n\t}\n}\n\nfunction collectOidNamesFromNode(names: Set<string>, node: OidNode): void {\n\tif (node.oids !== undefined) {\n\t\tfor (const name of Object.keys(node.oids)) {\n\t\t\tnames.add(name);\n\t\t}\n\t}\n\n\tif (node.children !== undefined) {\n\t\tfor (const child of Object.values(node.children)) {\n\t\t\tcollectOidNamesFromNode(names, child);\n\t\t}\n\t}\n}\n\nfunction collectOidNamesFromDocument(document: typeof OID_GROUP_SPECS): readonly string[] {\n\tconst names = new Set<string>();\n\tfor (const value of Object.values(document)) {\n\t\tif (isOidNode(value)) {\n\t\t\tcollectOidNamesFromNode(names, value);\n\t\t}\n\t}\n\treturn [...names];\n}\n\nfunction isOidRegistry(oids: OidMap, names: readonly string[]): oids is OidRegistry {\n\tfor (const name of names) {\n\t\tif (!hasOidName(oids, name)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction flattenOidTree(tree: typeof OID_GROUP_SPECS): OidRegistry {\n\tconst oids: MutableOidMap = Object.create(null);\n\taddOidDocument(oids, tree);\n\tconst names = collectOidNamesFromDocument(tree);\n\tif (!isOidRegistry(oids, names)) {\n\t\tconst missingNames = names.filter((name) => !hasOidName(oids, name));\n\t\tthrow new TypeError(`Incomplete OID registry; missing ${missingNames.join(', ')}`);\n\t}\n\treturn oids;\n}\n\n/**\n * Dotted-decimal OID constants.\n *\n * Includes:\n * - EKU purposes,\n * - PKCS algorithms,\n * - PKIX access methods,\n * - X.500 attributes,\n * - X.509v3 extensions, and\n * - hash algorithms.\n */\nconst OIDS: OidRegistry = flattenOidTree(OID_GROUP_SPECS);\n\nexport { OID_GROUP_SPECS, OIDS };\n"],"mappings":";;;;;;;;;;AAmDA,SAAS,cAAc,GAAoB,GAAqB;CAK/D,
|
|
1
|
+
{"version":3,"file":"oids2.js","names":["OID_GROUP_SPECS","oids_default","basePrefix","arc","value","oids","name","prefix","node","path","existingPath","tree","document","child","names","missingNames","OIDS"],"sources":["../../../src/internal/asn1/oids.ts"],"sourcesContent":["/**\n * Centralized ASN.1 object identifier registry referenced by create, parse,\n * verify, and container modules.\n *\n * All OIDs are dotted-decimal string constants keyed by their common short name.\n *\n * @module\n */\n\nimport OID_GROUP_SPECS from './oids.json' with { type: 'json' };\n\ntype OidLeaves = { readonly [name: string]: string };\ntype OidNode = {\n\treadonly arc: string;\n\treadonly oids?: OidLeaves;\n\treadonly children?: OidTree;\n};\ntype OidTree = { readonly [name: string]: OidNode };\ntype OidMap = { readonly [name: string]: string };\ntype MutableOidMap = { [name: string]: string };\ndeclare const oidNameBrand: unique symbol;\ntype OidValue<Name extends string, Value extends string> = Value & {\n\treadonly [oidNameBrand]?: Name;\n};\ntype JoinOidPrefix<Base extends string, Arc extends string> = Base extends ''\n\t? Arc\n\t: `${Base}.${Arc}`;\ntype OidsFromLeaves<Prefix extends string, Leaves extends OidLeaves> = {\n\treadonly [Name in keyof Leaves]: OidValue<Name & string, `${Prefix}.${Leaves[Name]}`>;\n};\ntype UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends (\n\tvalue: infer Intersection,\n) => void\n\t? Intersection\n\t: never;\ntype OidsFromNode<Node extends OidNode, Base extends string = ''> = Node extends {\n\treadonly arc: infer Arc extends string;\n}\n\t? (Node extends { readonly oids: infer Leaves extends OidLeaves }\n\t\t\t? OidsFromLeaves<JoinOidPrefix<Base, Arc>, Leaves>\n\t\t\t: unknown) &\n\t\t\t(Node extends { readonly children: infer Children extends OidTree }\n\t\t\t\t? OidsFromTree<Children, JoinOidPrefix<Base, Arc>>\n\t\t\t\t: unknown)\n\t: never;\ntype OidsFromTree<Tree extends OidTree, Base extends string = ''> = UnionToIntersection<\n\tOidsFromNode<Tree[keyof Tree], Base>\n>;\ntype OidDocumentRoots<Document> = Omit<Document, '$schema'>;\ntype OidRegistry = OidsFromTree<OidDocumentRoots<typeof OID_GROUP_SPECS>>;\n\nfunction joinOidPrefix(basePrefix: string, arc: string): string {\n\tif (basePrefix === '') {\n\t\treturn arc;\n\t}\n\n\treturn `${basePrefix}.${arc}`;\n}\n\nfunction isOidNode(value: unknown): value is OidNode {\n\treturn typeof value === 'object' && value !== null && 'arc' in value;\n}\n\nfunction hasOidName(oids: OidMap, name: string): boolean {\n\treturn Object.hasOwn(oids, name);\n}\n\nfunction addOidNode(oids: MutableOidMap, node: OidNode, basePrefix: string): void {\n\tconst prefix = joinOidPrefix(basePrefix, node.arc);\n\n\tif (node.oids !== undefined) {\n\t\tfor (const [name, arc] of Object.entries(node.oids)) {\n\t\t\tconst path = joinOidPrefix(prefix, arc);\n\t\t\tif (hasOidName(oids, name)) {\n\t\t\t\tconst existingPath = oids[name];\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Duplicate OID name \"${name}\" at ${path}; already assigned to ${existingPath}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\toids[name] = path;\n\t\t}\n\t}\n\n\tif (node.children !== undefined) {\n\t\taddOidTree(oids, node.children, prefix);\n\t}\n}\n\nfunction addOidTree(oids: MutableOidMap, tree: OidTree, basePrefix: string): void {\n\tfor (const node of Object.values(tree)) {\n\t\taddOidNode(oids, node, basePrefix);\n\t}\n}\n\nfunction addOidDocument(oids: MutableOidMap, document: typeof OID_GROUP_SPECS): void {\n\tfor (const value of Object.values(document)) {\n\t\tif (isOidNode(value)) {\n\t\t\taddOidNode(oids, value, '');\n\t\t}\n\t}\n}\n\nfunction collectOidNamesFromNode(names: Set<string>, node: OidNode): void {\n\tif (node.oids !== undefined) {\n\t\tfor (const name of Object.keys(node.oids)) {\n\t\t\tnames.add(name);\n\t\t}\n\t}\n\n\tif (node.children !== undefined) {\n\t\tfor (const child of Object.values(node.children)) {\n\t\t\tcollectOidNamesFromNode(names, child);\n\t\t}\n\t}\n}\n\nfunction collectOidNamesFromDocument(document: typeof OID_GROUP_SPECS): readonly string[] {\n\tconst names = new Set<string>();\n\tfor (const value of Object.values(document)) {\n\t\tif (isOidNode(value)) {\n\t\t\tcollectOidNamesFromNode(names, value);\n\t\t}\n\t}\n\treturn [...names];\n}\n\nfunction isOidRegistry(oids: OidMap, names: readonly string[]): oids is OidRegistry {\n\tfor (const name of names) {\n\t\tif (!hasOidName(oids, name)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction flattenOidTree(tree: typeof OID_GROUP_SPECS): OidRegistry {\n\tconst oids: MutableOidMap = Object.create(null);\n\taddOidDocument(oids, tree);\n\tconst names = collectOidNamesFromDocument(tree);\n\tif (!isOidRegistry(oids, names)) {\n\t\tconst missingNames = names.filter((name) => !hasOidName(oids, name));\n\t\tthrow new TypeError(`Incomplete OID registry; missing ${missingNames.join(', ')}`);\n\t}\n\treturn oids;\n}\n\n/**\n * Dotted-decimal OID constants.\n *\n * Includes:\n * - EKU purposes,\n * - PKCS algorithms,\n * - PKIX access methods,\n * - X.500 attributes,\n * - X.509v3 extensions, and\n * - hash algorithms.\n */\nconst OIDS: OidRegistry = flattenOidTree(OID_GROUP_SPECS);\n\nexport { OID_GROUP_SPECS, OIDS };\n"],"mappings":";;;;;;;;;;AAmDA,SAAS,cAAc,GAAoB,GAAqB;CAK/D,OAJIE,MAAe,KACXC,IAGD,GAAGD,EAAW,GAAGC;AACzB;AAEA,SAAS,UAAU,GAAkC;CACpD,OAAO,OAAOC,KAAU,cAAYA,KAAkB,SAASA;AAChE;AAEA,SAAS,WAAW,GAAc,GAAuB;CACxD,OAAO,OAAO,OAAOC,GAAMC,CAAI;AAChC;AAEA,SAAS,WAAW,GAAqB,GAAe,GAA0B;CACjF,IAAMC,IAAS,cAAcL,GAAYM,EAAK,GAAG;CAEjD,IAAIA,EAAK,SAAS,KAAA,GACjB,KAAK,IAAM,CAACF,GAAMH,MAAQ,OAAO,QAAQK,EAAK,IAAI,GAAG;EACpD,IAAMC,IAAO,cAAcF,GAAQJ,CAAG;EACtC,IAAI,WAAWE,GAAMC,CAAI,GAAG;GAC3B,IAAMI,IAAeL,EAAKC;GAC1B,MAAU,UACT,uBAAuBA,EAAK,OAAOG,EAAK,wBAAwBC,GACjE;EACD;EACA,EAAKJ,KAAQG;CACd;CAGD,AAAID,EAAK,aAAa,KAAA,KACrB,WAAWH,GAAMG,EAAK,UAAUD,CAAM;AA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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OIDS as e } from "../asn1/oids2.js";
|
|
2
2
|
import { parseRsaPssParameters as t } from "./rsa-pss.js";
|
|
3
|
-
|
|
3
|
+
// src/internal/crypto/algorithm-names.ts
|
|
4
4
|
/**
|
|
5
5
|
* Human-readable algorithm labels for parsed OIDs.
|
|
6
6
|
*
|
|
@@ -36,6 +36,7 @@ function describeSignatureAlgorithm(n, r) {
|
|
|
36
36
|
case e.ecdsaWithSHA384: return "ECDSA with SHA-384";
|
|
37
37
|
case e.ecdsaWithSHA512: return "ECDSA with SHA-512";
|
|
38
38
|
case e.ed25519: return "Ed25519";
|
|
39
|
+
case e.ed448: return "Ed448";
|
|
39
40
|
default: return `Unknown (${n})`;
|
|
40
41
|
}
|
|
41
42
|
}
|
|
@@ -50,11 +51,13 @@ function describePublicKeyAlgorithm(t, n) {
|
|
|
50
51
|
case e.secp521r1: return "EC P-521";
|
|
51
52
|
default: return "EC";
|
|
52
53
|
}
|
|
54
|
+
case e.x25519: return "X25519";
|
|
55
|
+
case e.x448: return "X448";
|
|
53
56
|
case e.ed25519: return "Ed25519";
|
|
57
|
+
case e.ed448: return "Ed448";
|
|
54
58
|
default: return `Unknown (${t})`;
|
|
55
59
|
}
|
|
56
60
|
}
|
|
57
|
-
//#endregion
|
|
58
61
|
export { describeHashAlgorithm, describePublicKeyAlgorithm, describeSignatureAlgorithm };
|
|
59
62
|
|
|
60
63
|
//# sourceMappingURL=algorithm-names.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"algorithm-names.js","names":[],"sources":["../../../src/internal/crypto/algorithm-names.ts"],"sourcesContent":["/**\n * Human-readable algorithm labels for parsed OIDs.\n *\n * Shared by certificate, revocation, and PKCS parse surfaces so callers can\n * display meaningful algorithm names without memorizing dotted-decimal OIDs.\n *\n * @module\n */\n\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport { parseRsaPssParameters } from '#micro509/internal/crypto/rsa-pss';\n\n/** Convert a hash or message-digest OID into a human-readable name. */\nexport function describeHashAlgorithm(oid: string): string {\n\tswitch (oid) {\n\t\tcase OIDS.sha1:\n\t\t\treturn 'SHA-1';\n\t\tcase OIDS.sha256:\n\t\t\treturn 'SHA-256';\n\t\tcase OIDS.sha384:\n\t\t\treturn 'SHA-384';\n\t\tcase OIDS.sha512:\n\t\t\treturn 'SHA-512';\n\t\tdefault:\n\t\t\treturn `Unknown (${oid})`;\n\t}\n}\n\n/** Convert a signature AlgorithmIdentifier into a human-readable name. */\nexport function describeSignatureAlgorithm(\n\toid: string,\n\tparametersDer: Uint8Array | undefined,\n): string {\n\tswitch (oid) {\n\t\tcase OIDS.sha1WithRSAEncryption:\n\t\t\treturn 'RSA PKCS#1 v1.5 with SHA-1';\n\t\tcase OIDS.sha256WithRSAEncryption:\n\t\t\treturn 'RSA PKCS#1 v1.5 with SHA-256';\n\t\tcase OIDS.sha384WithRSAEncryption:\n\t\t\treturn 'RSA PKCS#1 v1.5 with SHA-384';\n\t\tcase OIDS.sha512WithRSAEncryption:\n\t\t\treturn 'RSA PKCS#1 v1.5 with SHA-512';\n\t\tcase OIDS.rsassaPss: {\n\t\t\tconst parsed = parseRsaPssParameters(parametersDer);\n\t\t\treturn parsed.ok ? `RSA-PSS with ${parsed.value.hash}` : 'RSA-PSS';\n\t\t}\n\t\tcase OIDS.ecdsaWithSHA1:\n\t\t\treturn 'ECDSA with SHA-1';\n\t\tcase OIDS.ecdsaWithSHA224:\n\t\t\treturn 'ECDSA with SHA-224';\n\t\tcase OIDS.ecdsaWithSHA256:\n\t\t\treturn 'ECDSA with SHA-256';\n\t\tcase OIDS.ecdsaWithSHA384:\n\t\t\treturn 'ECDSA with SHA-384';\n\t\tcase OIDS.ecdsaWithSHA512:\n\t\t\treturn 'ECDSA with SHA-512';\n\t\tcase OIDS.ed25519:\n\t\t\treturn 'Ed25519';\n\t\tdefault:\n\t\t\treturn `Unknown (${oid})`;\n\t}\n}\n\n/** Convert a SubjectPublicKeyInfo algorithm identifier into a human-readable name. */\nexport function describePublicKeyAlgorithm(oid: string, parametersOid: string | undefined): string {\n\tswitch (oid) {\n\t\tcase OIDS.rsaEncryption:\n\t\t\treturn 'RSA';\n\t\tcase OIDS.rsassaPss:\n\t\t\treturn 'RSA-PSS';\n\t\tcase OIDS.ecPublicKey:\n\t\t\tswitch (parametersOid) {\n\t\t\t\tcase OIDS.prime256v1:\n\t\t\t\t\treturn 'EC P-256';\n\t\t\t\tcase OIDS.secp384r1:\n\t\t\t\t\treturn 'EC P-384';\n\t\t\t\tcase OIDS.secp521r1:\n\t\t\t\t\treturn 'EC P-521';\n\t\t\t\tdefault:\n\t\t\t\t\treturn 'EC';\n\t\t\t}\n\t\tcase OIDS.ed25519:\n\t\t\treturn 'Ed25519';\n\t\tdefault:\n\t\t\treturn `Unknown (${oid})`;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,sBAAsB,GAAqB;CAC1D,
|
|
1
|
+
{"version":3,"file":"algorithm-names.js","names":["oid","OIDS","parsed","parseRsaPssParameters","parametersDer","parametersOid"],"sources":["../../../src/internal/crypto/algorithm-names.ts"],"sourcesContent":["/**\n * Human-readable algorithm labels for parsed OIDs.\n *\n * Shared by certificate, revocation, and PKCS parse surfaces so callers can\n * display meaningful algorithm names without memorizing dotted-decimal OIDs.\n *\n * @module\n */\n\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport { parseRsaPssParameters } from '#micro509/internal/crypto/rsa-pss';\n\n/** Convert a hash or message-digest OID into a human-readable name. */\nexport function describeHashAlgorithm(oid: string): string {\n\tswitch (oid) {\n\t\tcase OIDS.sha1:\n\t\t\treturn 'SHA-1';\n\t\tcase OIDS.sha256:\n\t\t\treturn 'SHA-256';\n\t\tcase OIDS.sha384:\n\t\t\treturn 'SHA-384';\n\t\tcase OIDS.sha512:\n\t\t\treturn 'SHA-512';\n\t\tdefault:\n\t\t\treturn `Unknown (${oid})`;\n\t}\n}\n\n/** Convert a signature AlgorithmIdentifier into a human-readable name. */\nexport function describeSignatureAlgorithm(\n\toid: string,\n\tparametersDer: Uint8Array | undefined,\n): string {\n\tswitch (oid) {\n\t\tcase OIDS.sha1WithRSAEncryption:\n\t\t\treturn 'RSA PKCS#1 v1.5 with SHA-1';\n\t\tcase OIDS.sha256WithRSAEncryption:\n\t\t\treturn 'RSA PKCS#1 v1.5 with SHA-256';\n\t\tcase OIDS.sha384WithRSAEncryption:\n\t\t\treturn 'RSA PKCS#1 v1.5 with SHA-384';\n\t\tcase OIDS.sha512WithRSAEncryption:\n\t\t\treturn 'RSA PKCS#1 v1.5 with SHA-512';\n\t\tcase OIDS.rsassaPss: {\n\t\t\tconst parsed = parseRsaPssParameters(parametersDer);\n\t\t\treturn parsed.ok ? `RSA-PSS with ${parsed.value.hash}` : 'RSA-PSS';\n\t\t}\n\t\tcase OIDS.ecdsaWithSHA1:\n\t\t\treturn 'ECDSA with SHA-1';\n\t\tcase OIDS.ecdsaWithSHA224:\n\t\t\treturn 'ECDSA with SHA-224';\n\t\tcase OIDS.ecdsaWithSHA256:\n\t\t\treturn 'ECDSA with SHA-256';\n\t\tcase OIDS.ecdsaWithSHA384:\n\t\t\treturn 'ECDSA with SHA-384';\n\t\tcase OIDS.ecdsaWithSHA512:\n\t\t\treturn 'ECDSA with SHA-512';\n\t\tcase OIDS.ed25519:\n\t\t\treturn 'Ed25519';\n\t\tcase OIDS.ed448:\n\t\t\treturn 'Ed448';\n\t\tdefault:\n\t\t\treturn `Unknown (${oid})`;\n\t}\n}\n\n/** Convert a SubjectPublicKeyInfo algorithm identifier into a human-readable name. */\nexport function describePublicKeyAlgorithm(oid: string, parametersOid: string | undefined): string {\n\tswitch (oid) {\n\t\tcase OIDS.rsaEncryption:\n\t\t\treturn 'RSA';\n\t\tcase OIDS.rsassaPss:\n\t\t\treturn 'RSA-PSS';\n\t\tcase OIDS.ecPublicKey:\n\t\t\tswitch (parametersOid) {\n\t\t\t\tcase OIDS.prime256v1:\n\t\t\t\t\treturn 'EC P-256';\n\t\t\t\tcase OIDS.secp384r1:\n\t\t\t\t\treturn 'EC P-384';\n\t\t\t\tcase OIDS.secp521r1:\n\t\t\t\t\treturn 'EC P-521';\n\t\t\t\tdefault:\n\t\t\t\t\treturn 'EC';\n\t\t\t}\n\t\tcase OIDS.x25519:\n\t\t\treturn 'X25519';\n\t\tcase OIDS.x448:\n\t\t\treturn 'X448';\n\t\tcase OIDS.ed25519:\n\t\t\treturn 'Ed25519';\n\t\tcase OIDS.ed448:\n\t\t\treturn 'Ed448';\n\t\tdefault:\n\t\t\treturn `Unknown (${oid})`;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,sBAAsB,GAAqB;CAC1D,QAAQA,GAAR;EACC,KAAKC,EAAK,MACT,OAAO;EACR,KAAKA,EAAK,QACT,OAAO;EACR,KAAKA,EAAK,QACT,OAAO;EACR,KAAKA,EAAK,QACT,OAAO;EACR,SACC,OAAO,YAAYD,EAAI;CACzB;AACD;;AAGA,SAAgB,2BACf,GACA,GACS;CACT,QAAQA,GAAR;EACC,KAAKC,EAAK,uBACT,OAAO;EACR,KAAKA,EAAK,yBACT,OAAO;EACR,KAAKA,EAAK,yBACT,OAAO;EACR,KAAKA,EAAK,yBACT,OAAO;EACR,KAAKA,EAAK,WAAW;GACpB,IAAMC,IAASC,EAAsBC,CAAa;GAClD,OAAOF,EAAO,KAAK,gBAAgBA,EAAO,MAAM,SAAS;EAC1D;EACA,KAAKD,EAAK,eACT,OAAO;EACR,KAAKA,EAAK,iBACT,OAAO;EACR,KAAKA,EAAK,iBACT,OAAO;EACR,KAAKA,EAAK,iBACT,OAAO;EACR,KAAKA,EAAK,iBACT,OAAO;EACR,KAAKA,EAAK,SACT,OAAO;EACR,KAAKA,EAAK,OACT,OAAO;EACR,SACC,OAAO,YAAYD,EAAI;CACzB;AACD;;AAGA,SAAgB,2BAA2B,GAAa,GAA2C;CAClG,QAAQA,GAAR;EACC,KAAKC,EAAK,eACT,OAAO;EACR,KAAKA,EAAK,WACT,OAAO;EACR,KAAKA,EAAK,aACT,QAAQI,GAAR;GACC,KAAKJ,EAAK,YACT,OAAO;GACR,KAAKA,EAAK,WACT,OAAO;GACR,KAAKA,EAAK,WACT,OAAO;GACR,SACC,OAAO;EACT;EACD,KAAKA,EAAK,QACT,OAAO;EACR,KAAKA,EAAK,MACT,OAAO;EACR,KAAKA,EAAK,SACT,OAAO;EACR,KAAKA,EAAK,OACT,OAAO;EACR,SACC,OAAO,YAAYD,EAAI;CACzB;AACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { integer as e, readSequenceChildren as t, sequence as n } from "../asn1/der.js";
|
|
2
|
-
|
|
2
|
+
// src/internal/crypto/ecdsa.ts
|
|
3
3
|
/**
|
|
4
4
|
* ECDSA signature encoding conversion between ASN.1 DER (r, s INTEGER) and the
|
|
5
5
|
* fixed-width raw format used by WebCrypto.
|
|
@@ -11,7 +11,7 @@ function derEcdsaSignatureToRaw(e, n) {
|
|
|
11
11
|
let r = t(e), i = r[0], a = r[1];
|
|
12
12
|
if (i === void 0 || a === void 0 || r.length !== 2) throw Error("Malformed ECDSA DER signature");
|
|
13
13
|
if (i.tag !== 2 || a.tag !== 2) throw Error("ECDSA DER signature must contain two INTEGERs");
|
|
14
|
-
return concatFixedWidth(
|
|
14
|
+
return concatFixedWidth(derIntegerMagnitude(i.value), derIntegerMagnitude(a.value), n);
|
|
15
15
|
}
|
|
16
16
|
/** Convert a fixed-width raw `r || s` ECDSA signature to DER-encoded SEQUENCE of two INTEGERs. */
|
|
17
17
|
function rawEcdsaSignatureToDer(t, r) {
|
|
@@ -53,13 +53,18 @@ function concatFixedWidth(e, t, n) {
|
|
|
53
53
|
let r = new Uint8Array(n * 2);
|
|
54
54
|
return r.set(e, n - e.length), r.set(t, r.length - t.length), r;
|
|
55
55
|
}
|
|
56
|
-
/**
|
|
57
|
-
function
|
|
58
|
-
let t = 0;
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
/** Validate a non-negative DER INTEGER and return its unsigned magnitude. */
|
|
57
|
+
function derIntegerMagnitude(e) {
|
|
58
|
+
let t = e[0];
|
|
59
|
+
if (t === void 0) throw Error("ECDSA DER signature INTEGER must not be empty");
|
|
60
|
+
if (t & 128) throw Error("ECDSA DER signature INTEGER must be non-negative");
|
|
61
|
+
if (t === 0 && e.length > 1) {
|
|
62
|
+
let t = e[1];
|
|
63
|
+
if (t === void 0 || !(t & 128)) throw Error("ECDSA DER signature INTEGER must use minimal encoding");
|
|
64
|
+
return e.slice(1);
|
|
65
|
+
}
|
|
66
|
+
return e;
|
|
61
67
|
}
|
|
62
|
-
//#endregion
|
|
63
68
|
export { alternateEcdsaSignatureEncoding, concatFixedWidth, derEcdsaSignatureToRaw, ecdsaSignatureToDer, rawEcdsaSignatureToDer };
|
|
64
69
|
|
|
65
70
|
//# sourceMappingURL=ecdsa.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecdsa.js","names":[],"sources":["../../../src/internal/crypto/ecdsa.ts"],"sourcesContent":["/**\n * ECDSA signature encoding conversion between ASN.1 DER (r, s INTEGER) and the\n * fixed-width raw format used by WebCrypto.\n *\n * @module\n */\n\nimport { integer, readSequenceChildren, sequence } from '#micro509/internal/asn1/der';\n\n/** Convert a DER-encoded ECDSA signature (SEQUENCE of two INTEGERs) to fixed-width raw `r || s`. */\nexport function derEcdsaSignatureToRaw(signature: Uint8Array, partLength: number): Uint8Array {\n\tconst parts = readSequenceChildren(signature);\n\tconst r = parts[0];\n\tconst s = parts[1];\n\tif (r === undefined || s === undefined || parts.length !== 2) {\n\t\tthrow new Error('Malformed ECDSA DER signature');\n\t}\n\tif (r.tag !== 0x02 || s.tag !== 0x02) {\n\t\tthrow new Error('ECDSA DER signature must contain two INTEGERs');\n\t}\n\treturn concatFixedWidth(
|
|
1
|
+
{"version":3,"file":"ecdsa.js","names":["parts","readSequenceChildren","signature","r","s","partLength","sequence","integer","rawSignatureBytes","left","right","out","first","bytes","second"],"sources":["../../../src/internal/crypto/ecdsa.ts"],"sourcesContent":["/**\n * ECDSA signature encoding conversion between ASN.1 DER (r, s INTEGER) and the\n * fixed-width raw format used by WebCrypto.\n *\n * @module\n */\n\nimport { integer, readSequenceChildren, sequence } from '#micro509/internal/asn1/der';\n\n/** Convert a DER-encoded ECDSA signature (SEQUENCE of two INTEGERs) to fixed-width raw `r || s`. */\nexport function derEcdsaSignatureToRaw(signature: Uint8Array, partLength: number): Uint8Array {\n\tconst parts = readSequenceChildren(signature);\n\tconst r = parts[0];\n\tconst s = parts[1];\n\tif (r === undefined || s === undefined || parts.length !== 2) {\n\t\tthrow new Error('Malformed ECDSA DER signature');\n\t}\n\tif (r.tag !== 0x02 || s.tag !== 0x02) {\n\t\tthrow new Error('ECDSA DER signature must contain two INTEGERs');\n\t}\n\treturn concatFixedWidth(derIntegerMagnitude(r.value), derIntegerMagnitude(s.value), partLength);\n}\n\n/** Convert a fixed-width raw `r || s` ECDSA signature to DER-encoded SEQUENCE of two INTEGERs. */\nexport function rawEcdsaSignatureToDer(signature: Uint8Array, partLength: number): Uint8Array {\n\tif (signature.length !== partLength * 2) {\n\t\tthrow new Error('Unexpected ECDSA raw signature length');\n\t}\n\treturn sequence([integer(signature.slice(0, partLength)), integer(signature.slice(partLength))]);\n}\n\n/**\n * Normalize a WebCrypto ECDSA signature to DER.\n *\n * Spec-compliant WebCrypto always returns fixed-width raw `r || s`\n * (exactly `rawSignatureBytes` long), which needs conversion. Detection is\n * by length, never by sniffing the first byte: a raw signature whose `r`\n * happens to start with `0x30` (1-in-256 per signature) is\n * indistinguishable from DER by tag, and embedding it unconverted produces\n * a certificate/CRL that OpenSSL rejects with a signature failure.\n */\nexport function ecdsaSignatureToDer(signature: Uint8Array, rawSignatureBytes: number): Uint8Array {\n\tif (signature.length === rawSignatureBytes) {\n\t\treturn rawEcdsaSignatureToDer(signature, rawSignatureBytes / 2);\n\t}\n\treturn signature;\n}\n\n/**\n * Try the opposite ECDSA encoding: DER→raw or raw→DER.\n *\n * Returns `undefined` if conversion fails, letting callers retry verification\n * with the alternate encoding.\n */\nexport function alternateEcdsaSignatureEncoding(\n\tsignature: Uint8Array,\n\tpartLength: number,\n): Uint8Array | undefined {\n\t// Try DER→raw first if it looks like DER (starts with SEQUENCE tag)\n\tif (signature[0] === 0x30) {\n\t\ttry {\n\t\t\treturn derEcdsaSignatureToRaw(signature, partLength);\n\t\t} catch {\n\t\t\t// Fall through to try raw→DER\n\t\t}\n\t}\n\t// Try raw→DER\n\ttry {\n\t\treturn rawEcdsaSignatureToDer(signature, partLength);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** Left-pad and concatenate `r` and `s` into a fixed-width `partLength * 2` byte buffer. */\nexport function concatFixedWidth(\n\tleft: Uint8Array,\n\tright: Uint8Array,\n\tpartLength: number,\n): Uint8Array {\n\tif (left.length > partLength || right.length > partLength) {\n\t\tthrow new Error('ECDSA signature integer too large');\n\t}\n\tconst out = new Uint8Array(partLength * 2);\n\tout.set(left, partLength - left.length);\n\tout.set(right, out.length - right.length);\n\treturn out;\n}\n\n/** Validate a non-negative DER INTEGER and return its unsigned magnitude. */\nfunction derIntegerMagnitude(bytes: Uint8Array): Uint8Array {\n\tconst first = bytes[0];\n\tif (first === undefined) {\n\t\tthrow new Error('ECDSA DER signature INTEGER must not be empty');\n\t}\n\tif ((first & 0x80) !== 0) {\n\t\tthrow new Error('ECDSA DER signature INTEGER must be non-negative');\n\t}\n\tif (first === 0 && bytes.length > 1) {\n\t\tconst second = bytes[1];\n\t\tif (second === undefined || (second & 0x80) === 0) {\n\t\t\tthrow new Error('ECDSA DER signature INTEGER must use minimal encoding');\n\t\t}\n\t\treturn bytes.slice(1);\n\t}\n\treturn bytes;\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,uBAAuB,GAAuB,GAAgC;CAC7F,IAAMA,IAAQC,EAAqBC,CAAS,GACtCC,IAAIH,EAAM,IACVI,IAAIJ,EAAM;CAChB,IAAIG,MAAM,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KC,EAAM,SAAS,GAAG;EACpC,IAAMC,IAASD,EAAM;EACrB,IAAIC,MAAW,KAAA,KAAA,EAAcA,IAAS,MACrC,MAAU,MAAM,uDAAuD;EAExE,OAAOD,EAAM,MAAM,CAAC;CACrB;CACA,OAAOA;AACR"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/internal/crypto/hash.ts
|
|
2
2
|
/**
|
|
3
3
|
* Synchronous digest implementations for MD5 and SHA-1, used where WebCrypto's
|
|
4
4
|
* async API is impractical (e.g. `EVP_BytesToKey` key derivation, PKCS#12 MAC).
|
|
@@ -219,7 +219,6 @@ function sha1(e) {
|
|
|
219
219
|
let l = /* @__PURE__ */ new Uint8Array(20), u = new DataView(l.buffer, l.byteOffset, l.byteLength);
|
|
220
220
|
return u.setUint32(0, n, !1), u.setUint32(4, r, !1), u.setUint32(8, i, !1), u.setUint32(12, a, !1), u.setUint32(16, o, !1), l;
|
|
221
221
|
}
|
|
222
|
-
//#endregion
|
|
223
222
|
export { md5, sha1 };
|
|
224
223
|
|
|
225
224
|
//# sourceMappingURL=hash.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","names":[],"sources":["../../../src/internal/crypto/hash.ts"],"sourcesContent":["/**\n * Synchronous digest implementations for MD5 and SHA-1, used where WebCrypto's\n * async API is impractical (e.g. `EVP_BytesToKey` key derivation, PKCS#12 MAC).\n *\n * @module\n */\n\n// Shared Merkle–Damgård primitives\n\n/** Unsigned 32-bit left-rotate. */\nfunction rotl(x: number, n: number): number {\n\treturn ((x << n) | (x >>> (32 - n))) >>> 0;\n}\n\n/**\n * Merkle–Damgård padding: append 0x80, zero-pad to 56 mod 64,\n * append original bit-length as 64-bit integer.\n */\nfunction mdPad(data: Uint8Array, littleEndian: boolean): Uint8Array {\n\tconst bitLen = BigInt(data.length) * 8n;\n\tconst padded = new Uint8Array(Math.ceil((data.length + 1 + 8) / 64) * 64);\n\tpadded.set(data);\n\tpadded[data.length] = 0x80;\n\tconst view = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);\n\tview.setBigUint64(padded.length - 8, bitLen, littleEndian);\n\treturn padded;\n}\n\n/** Bounds-checked read from a readonly number table. */\nfunction tbl(arr: readonly number[], i: number): number {\n\tconst v = arr[i];\n\tif (v === undefined) throw new RangeError(`table index ${i}`);\n\treturn v;\n}\n\n/** Bounds-checked read from a Uint32Array. */\nfunction w32(arr: Uint32Array, i: number): number {\n\tconst v = arr[i];\n\tif (v === undefined) throw new RangeError(`word index ${i}`);\n\treturn v;\n}\n\n// MD5 (RFC 1321)\n\n/** Per-round left-rotate amounts for MD5 (RFC 1321 §3.4). */\nconst MD5_S = /* dprint-ignore */ [\n\t7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14,\n\t20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6,\n\t10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21,\n] as const satisfies readonly number[];\n\n/** Pre-computed sine-derived constants for MD5 (RFC 1321 §3.4). */\nconst MD5_K = /* dprint-ignore */ [\n\t0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,\n\t0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,\n\t0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,\n\t0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,\n\t0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,\n\t0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,\n\t0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,\n\t0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,\n] as const satisfies readonly number[];\n\n/** Compute a 16-byte MD5 digest (RFC 1321). Used by `EVP_BytesToKey` key derivation. */\nexport function md5(data: Uint8Array): Uint8Array<ArrayBuffer> {\n\tconst padded = mdPad(data, true);\n\n\tlet [a0, b0, c0, d0] = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476];\n\n\tconst M = new Uint32Array(16);\n\n\tfor (let offset = 0; offset < padded.length; offset += 64) {\n\t\tconst view = new DataView(padded.buffer, padded.byteOffset + offset, 64);\n\t\tfor (let j = 0; j < 16; j++) {\n\t\t\tM[j] = view.getUint32(j * 4, true);\n\t\t}\n\n\t\tlet [A, B, C, D] = [a0, b0, c0, d0];\n\n\t\tfor (let i = 0; i < 64; i++) {\n\t\t\tlet F: number;\n\t\t\tlet g: number;\n\n\t\t\tif (i < 16) {\n\t\t\t\tF = ((B & C) | (~B & D)) >>> 0;\n\t\t\t\tg = i;\n\t\t\t} else if (i < 32) {\n\t\t\t\tF = ((D & B) | (~D & C)) >>> 0;\n\t\t\t\tg = (5 * i + 1) & 15;\n\t\t\t} else if (i < 48) {\n\t\t\t\tF = (B ^ C ^ D) >>> 0;\n\t\t\t\tg = (3 * i + 5) & 15;\n\t\t\t} else {\n\t\t\t\tF = (C ^ (B | ~D)) >>> 0;\n\t\t\t\tg = (7 * i) & 15;\n\t\t\t}\n\n\t\t\tF = (F + A + tbl(MD5_K, i) + w32(M, g)) >>> 0;\n\t\t\tconst oldD = D;\n\t\t\tD = C;\n\t\t\tC = B;\n\t\t\tB = (B + rotl(F, tbl(MD5_S, i))) >>> 0;\n\t\t\tA = oldD;\n\t\t}\n\n\t\ta0 = (a0 + A) >>> 0;\n\t\tb0 = (b0 + B) >>> 0;\n\t\tc0 = (c0 + C) >>> 0;\n\t\td0 = (d0 + D) >>> 0;\n\t}\n\n\tconst out = new Uint8Array(16);\n\tconst dv = new DataView(out.buffer, out.byteOffset, out.byteLength);\n\tdv.setUint32(0, a0, true);\n\tdv.setUint32(4, b0, true);\n\tdv.setUint32(8, c0, true);\n\tdv.setUint32(12, d0, true);\n\treturn out;\n}\n\n// SHA-1 (RFC 3174)\n\n/** Compute a 20-byte SHA-1 digest (RFC 3174). Used by PKCS#12 MAC verification. */\nexport function sha1(data: Uint8Array): Uint8Array<ArrayBuffer> {\n\tconst padded = mdPad(data, false);\n\n\tlet [h0, h1, h2, h3, h4] = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];\n\n\tconst W = new Uint32Array(80);\n\tconst pv = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);\n\n\tfor (let off = 0; off < padded.length; off += 64) {\n\t\tfor (let i = 0; i < 16; i++) {\n\t\t\tW[i] = pv.getUint32(off + i * 4, false);\n\t\t}\n\t\tfor (let i = 16; i < 80; i++) {\n\t\t\tW[i] = rotl(w32(W, i - 3) ^ w32(W, i - 8) ^ w32(W, i - 14) ^ w32(W, i - 16), 1);\n\t\t}\n\n\t\tlet [a, b, c, d, e] = [h0, h1, h2, h3, h4];\n\n\t\tfor (let i = 0; i < 80; i++) {\n\t\t\tlet f: number;\n\t\t\tlet k: number;\n\n\t\t\tif (i <= 19) {\n\t\t\t\tf = ((b & c) | (~b & d)) >>> 0;\n\t\t\t\tk = 0x5a827999;\n\t\t\t} else if (i <= 39) {\n\t\t\t\tf = (b ^ c ^ d) >>> 0;\n\t\t\t\tk = 0x6ed9eba1;\n\t\t\t} else if (i <= 59) {\n\t\t\t\tf = ((b & c) | (b & d) | (c & d)) >>> 0;\n\t\t\t\tk = 0x8f1bbcdc;\n\t\t\t} else {\n\t\t\t\tf = (b ^ c ^ d) >>> 0;\n\t\t\t\tk = 0xca62c1d6;\n\t\t\t}\n\n\t\t\tconst temp = (rotl(a, 5) + f + e + k + w32(W, i)) >>> 0;\n\t\t\te = d;\n\t\t\td = c;\n\t\t\tc = rotl(b, 30);\n\t\t\tb = a;\n\t\t\ta = temp;\n\t\t}\n\n\t\th0 = (h0 + a) >>> 0;\n\t\th1 = (h1 + b) >>> 0;\n\t\th2 = (h2 + c) >>> 0;\n\t\th3 = (h3 + d) >>> 0;\n\t\th4 = (h4 + e) >>> 0;\n\t}\n\n\tconst out = new Uint8Array(20);\n\tconst dv = new DataView(out.buffer, out.byteOffset, out.byteLength);\n\tdv.setUint32(0, h0, false);\n\tdv.setUint32(4, h1, false);\n\tdv.setUint32(8, h2, false);\n\tdv.setUint32(12, h3, false);\n\tdv.setUint32(16, h4, false);\n\treturn out;\n}\n"],"mappings":";;;;;;;;AAUA,SAAS,KAAK,GAAW,GAAmB;CAC3C,QAAS,KAAK,IAAM,MAAO,KAAK,OAAS;AAC1C;;;;;AAMA,SAAS,MAAM,GAAkB,GAAmC;CACnE,IAAM,IAAS,OAAO,EAAK,MAAM,IAAI,IAC/B,IAAS,IAAI,WAAW,KAAK,MAAM,EAAK,SAAS,IAAI,KAAK,EAAE,IAAI,EAAE;CAKxE,OAJA,EAAO,IAAI,CAAI,GACf,EAAO,EAAK,UAAU,KAEtB,IADiB,SAAS,EAAO,QAAQ,EAAO,YAAY,EAAO,UAChE,CAAC,CAAC,aAAa,EAAO,SAAS,GAAG,GAAQ,CAAY,GAClD;AACR;;AAGA,SAAS,IAAI,GAAwB,GAAmB;CACvD,IAAM,IAAI,EAAI;CACd,IAAI,MAAM,KAAA,GAAW,MAAU,WAAW,eAAe,GAAG;CAC5D,OAAO;AACR;;AAGA,SAAS,IAAI,GAAkB,GAAmB;CACjD,IAAM,IAAI,EAAI;CACd,IAAI,MAAM,KAAA,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UAAU,GAAG,GAAI,EAAK,GACzB,EAAG,UAAU,GAAG,GAAI,EAAK,GACzB,EAAG,UAAU,IAAI,GAAI,EAAK,GAC1B,EAAG,UAAU,IAAI,GAAI,EAAK,GACnB;AACR"}
|
|
1
|
+
{"version":3,"file":"hash.js","names":["x","n","bitLen","data","padded","littleEndian","v","arr","i","MD5_S","MD5_K","a0","b0","c0","d0","M","offset","view","j","A","B","C","D","F","g","oldD","out","dv","h0","h1","h2","h3","h4","W","pv","off","a","b","c","e","f","k","temp"],"sources":["../../../src/internal/crypto/hash.ts"],"sourcesContent":["/**\n * Synchronous digest implementations for MD5 and SHA-1, used where WebCrypto's\n * async API is impractical (e.g. `EVP_BytesToKey` key derivation, PKCS#12 MAC).\n *\n * @module\n */\n\n// Shared Merkle–Damgård primitives\n\n/** Unsigned 32-bit left-rotate. */\nfunction rotl(x: number, n: number): number {\n\treturn ((x << n) | (x >>> (32 - n))) >>> 0;\n}\n\n/**\n * Merkle–Damgård padding: append 0x80, zero-pad to 56 mod 64,\n * append original bit-length as 64-bit integer.\n */\nfunction mdPad(data: Uint8Array, littleEndian: boolean): Uint8Array {\n\tconst bitLen = BigInt(data.length) * 8n;\n\tconst padded = new Uint8Array(Math.ceil((data.length + 1 + 8) / 64) * 64);\n\tpadded.set(data);\n\tpadded[data.length] = 0x80;\n\tconst view = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);\n\tview.setBigUint64(padded.length - 8, bitLen, littleEndian);\n\treturn padded;\n}\n\n/** Bounds-checked read from a readonly number table. */\nfunction tbl(arr: readonly number[], i: number): number {\n\tconst v = arr[i];\n\tif (v === undefined) throw new RangeError(`table index ${i}`);\n\treturn v;\n}\n\n/** Bounds-checked read from a Uint32Array. */\nfunction w32(arr: Uint32Array, i: number): number {\n\tconst v = arr[i];\n\tif (v === undefined) throw new RangeError(`word index ${i}`);\n\treturn v;\n}\n\n// MD5 (RFC 1321)\n\n/** Per-round left-rotate amounts for MD5 (RFC 1321 §3.4). */\nconst MD5_S = /* dprint-ignore */ [\n\t7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14,\n\t20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6,\n\t10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21,\n] as const satisfies readonly number[];\n\n/** Pre-computed sine-derived constants for MD5 (RFC 1321 §3.4). */\nconst MD5_K = /* dprint-ignore */ [\n\t0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,\n\t0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,\n\t0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,\n\t0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,\n\t0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,\n\t0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,\n\t0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,\n\t0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,\n] as const satisfies readonly number[];\n\n/** Compute a 16-byte MD5 digest (RFC 1321). Used by `EVP_BytesToKey` key derivation. */\nexport function md5(data: Uint8Array): Uint8Array<ArrayBuffer> {\n\tconst padded = mdPad(data, true);\n\n\tlet [a0, b0, c0, d0] = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476];\n\n\tconst M = new Uint32Array(16);\n\n\tfor (let offset = 0; offset < padded.length; offset += 64) {\n\t\tconst view = new DataView(padded.buffer, padded.byteOffset + offset, 64);\n\t\tfor (let j = 0; j < 16; j++) {\n\t\t\tM[j] = view.getUint32(j * 4, true);\n\t\t}\n\n\t\tlet [A, B, C, D] = [a0, b0, c0, d0];\n\n\t\tfor (let i = 0; i < 64; i++) {\n\t\t\tlet F: number;\n\t\t\tlet g: number;\n\n\t\t\tif (i < 16) {\n\t\t\t\tF = ((B & C) | (~B & D)) >>> 0;\n\t\t\t\tg = i;\n\t\t\t} else if (i < 32) {\n\t\t\t\tF = ((D & B) | (~D & C)) >>> 0;\n\t\t\t\tg = (5 * i + 1) & 15;\n\t\t\t} else if (i < 48) {\n\t\t\t\tF = (B ^ C ^ D) >>> 0;\n\t\t\t\tg = (3 * i + 5) & 15;\n\t\t\t} else {\n\t\t\t\tF = (C ^ (B | ~D)) >>> 0;\n\t\t\t\tg = (7 * i) & 15;\n\t\t\t}\n\n\t\t\tF = (F + A + tbl(MD5_K, i) + w32(M, g)) >>> 0;\n\t\t\tconst oldD = D;\n\t\t\tD = C;\n\t\t\tC = B;\n\t\t\tB = (B + rotl(F, tbl(MD5_S, i))) >>> 0;\n\t\t\tA = oldD;\n\t\t}\n\n\t\ta0 = (a0 + A) >>> 0;\n\t\tb0 = (b0 + B) >>> 0;\n\t\tc0 = (c0 + C) >>> 0;\n\t\td0 = (d0 + D) >>> 0;\n\t}\n\n\tconst out = new Uint8Array(16);\n\tconst dv = new DataView(out.buffer, out.byteOffset, out.byteLength);\n\tdv.setUint32(0, a0, true);\n\tdv.setUint32(4, b0, true);\n\tdv.setUint32(8, c0, true);\n\tdv.setUint32(12, d0, true);\n\treturn out;\n}\n\n// SHA-1 (RFC 3174)\n\n/** Compute a 20-byte SHA-1 digest (RFC 3174). Used by PKCS#12 MAC verification. */\nexport function sha1(data: Uint8Array): Uint8Array<ArrayBuffer> {\n\tconst padded = mdPad(data, false);\n\n\tlet [h0, h1, h2, h3, h4] = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];\n\n\tconst W = new Uint32Array(80);\n\tconst pv = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);\n\n\tfor (let off = 0; off < padded.length; off += 64) {\n\t\tfor (let i = 0; i < 16; i++) {\n\t\t\tW[i] = pv.getUint32(off + i * 4, false);\n\t\t}\n\t\tfor (let i = 16; i < 80; i++) {\n\t\t\tW[i] = rotl(w32(W, i - 3) ^ w32(W, i - 8) ^ w32(W, i - 14) ^ w32(W, i - 16), 1);\n\t\t}\n\n\t\tlet [a, b, c, d, e] = [h0, h1, h2, h3, h4];\n\n\t\tfor (let i = 0; i < 80; i++) {\n\t\t\tlet f: number;\n\t\t\tlet k: number;\n\n\t\t\tif (i <= 19) {\n\t\t\t\tf = ((b & c) | (~b & d)) >>> 0;\n\t\t\t\tk = 0x5a827999;\n\t\t\t} else if (i <= 39) {\n\t\t\t\tf = (b ^ c ^ d) >>> 0;\n\t\t\t\tk = 0x6ed9eba1;\n\t\t\t} else if (i <= 59) {\n\t\t\t\tf = ((b & c) | (b & d) | (c & d)) >>> 0;\n\t\t\t\tk = 0x8f1bbcdc;\n\t\t\t} else {\n\t\t\t\tf = (b ^ c ^ d) >>> 0;\n\t\t\t\tk = 0xca62c1d6;\n\t\t\t}\n\n\t\t\tconst temp = (rotl(a, 5) + f + e + k + w32(W, i)) >>> 0;\n\t\t\te = d;\n\t\t\td = c;\n\t\t\tc = rotl(b, 30);\n\t\t\tb = a;\n\t\t\ta = temp;\n\t\t}\n\n\t\th0 = (h0 + a) >>> 0;\n\t\th1 = (h1 + b) >>> 0;\n\t\th2 = (h2 + c) >>> 0;\n\t\th3 = (h3 + d) >>> 0;\n\t\th4 = (h4 + e) >>> 0;\n\t}\n\n\tconst out = new Uint8Array(20);\n\tconst dv = new DataView(out.buffer, out.byteOffset, out.byteLength);\n\tdv.setUint32(0, h0, false);\n\tdv.setUint32(4, h1, false);\n\tdv.setUint32(8, h2, false);\n\tdv.setUint32(12, h3, false);\n\tdv.setUint32(16, h4, false);\n\treturn out;\n}\n"],"mappings":";;;;;;;;AAUA,SAAS,KAAK,GAAW,GAAmB;CAC3C,QAASA,KAAKC,IAAMD,MAAO,KAAKC,OAAS;AAC1C;;;;;AAMA,SAAS,MAAM,GAAkB,GAAmC;CACnE,IAAMC,IAAS,OAAOC,EAAK,MAAM,IAAI,IAC/BC,IAAS,IAAI,WAAW,KAAK,MAAMD,EAAK,SAAS,IAAI,KAAK,EAAE,IAAI,EAAE;CAKxE,OAJAC,EAAO,IAAID,CAAI,GACf,EAAOA,EAAK,UAAU,KAEtB,IADiB,SAASC,EAAO,QAAQA,EAAO,YAAYA,EAAO,UAChE,CAAC,CAAC,aAAaA,EAAO,SAAS,GAAGF,GAAQG,CAAY,GAClDD;AACR;;AAGA,SAAS,IAAI,GAAwB,GAAmB;CACvD,IAAME,IAAIC,EAAIC;CACd,IAAIF,MAAM,KAAA,GAAW,MAAU,WAAW,eAAeE,GAAG;CAC5D,OAAOF;AACR;;AAGA,SAAS,IAAI,GAAkB,GAAmB;CACjD,IAAMA,IAAIC,EAAIC;CACd,IAAIF,MAAM,KAAA,GAAW,MAAU,WAAW,cAAcE,GAAG;CAC3D,OAAOF;AACR;;AAKA,MAAMG,IAA4B;CACjC;CAAG;CAAI;CAAI;CAAI;CAAG;CAAI;CAAI;CAAI;CAAG;CAAI;CAAI;CAAI;CAAG;CAAI;CAAI;CAAI;CAAG;CAAG;CAAI;CAAI;CAAG;CAAG;CAAI;CAAI;CAAG;CAAG;CAC9F;CAAI;CAAG;CAAG;CAAI;CAAI;CAAG;CAAI;CAAI;CAAI;CAAG;CAAI;CAAI;CAAI;CAAG;CAAI;CAAI;CAAI;CAAG;CAAI;CAAI;CAAI;CAAG;CAAI;CAAI;CAAI;CAC7F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,0 +1,51 @@
|
|
|
1
|
+
/** Caller-supplied bound on password-based KDF work. */
|
|
2
|
+
export interface KdfLimitOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Maximum KDF iteration count accepted from the input. Higher counts fail
|
|
5
|
+
* before any derivation runs. Defaults to `2_000_000` for PBKDF2 and
|
|
6
|
+
* `100_000` for the PKCS#12 KDF, which costs more per round. In a PFX the
|
|
7
|
+
* PBES2-encrypted entries share one budget of this size and the MAC has a
|
|
8
|
+
* separate budget of this size.
|
|
9
|
+
*/
|
|
10
|
+
readonly maxKdfIterations?: number;
|
|
11
|
+
}
|
|
12
|
+
/** AES-CBC key sizes supported by this PBES2 implementation. */
|
|
13
|
+
export type Pbes2EncryptionScheme = "AES-128-CBC" | "AES-192-CBC" | "AES-256-CBC";
|
|
14
|
+
/** PBKDF2 pseudo-random function choices. `HMAC-SHA-1` is the RFC default; `HMAC-SHA-256` is preferred. */
|
|
15
|
+
export type Pbes2Prf = "HMAC-SHA-1" | "HMAC-SHA-256";
|
|
16
|
+
/** Input for `encryptPbes2`. */
|
|
17
|
+
export interface Pbes2EncryptionOptions {
|
|
18
|
+
/** Password fed to PBKDF2 for key derivation. */
|
|
19
|
+
readonly password: string;
|
|
20
|
+
/** PBKDF2 iteration count, an integer from 1 to 4294967295. Default: `100_000`. */
|
|
21
|
+
readonly iterations?: number;
|
|
22
|
+
/** PBKDF2 salt. Default: 16 cryptographically random bytes. */
|
|
23
|
+
readonly salt?: Uint8Array;
|
|
24
|
+
/** AES-CBC initialization vector. Default: 16 cryptographically random bytes. */
|
|
25
|
+
readonly iv?: Uint8Array;
|
|
26
|
+
/** AES-CBC cipher. Default: `'AES-256-CBC'`. */
|
|
27
|
+
readonly cipher?: Pbes2EncryptionScheme;
|
|
28
|
+
/** PBKDF2 PRF. Default: `'HMAC-SHA-256'`. */
|
|
29
|
+
readonly prf?: Pbes2Prf;
|
|
30
|
+
}
|
|
31
|
+
/** Resolved PBES2 algorithm parameters, either parsed from DER or built by `encryptPbes2`. */
|
|
32
|
+
export interface Pbes2Parameters {
|
|
33
|
+
/** PBKDF2 iteration count, an integer from 1 to 4294967295. */
|
|
34
|
+
readonly iterations: number;
|
|
35
|
+
/** PBKDF2 salt bytes. */
|
|
36
|
+
readonly salt: Uint8Array;
|
|
37
|
+
/** AES-CBC initialization vector. */
|
|
38
|
+
readonly iv: Uint8Array;
|
|
39
|
+
/** AES-CBC key-size variant. */
|
|
40
|
+
readonly cipher: Pbes2EncryptionScheme;
|
|
41
|
+
/** PBKDF2 pseudo-random function. */
|
|
42
|
+
readonly prf: Pbes2Prf;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Decodes a DER-encoded PBES2 AlgorithmIdentifier into structured {@linkcode Pbes2Parameters}.
|
|
46
|
+
*
|
|
47
|
+
* @throws if the encoding is malformed, names an unsupported KDF, PRF or cipher, or carries an
|
|
48
|
+
* iteration count outside 1 to 4294967295.
|
|
49
|
+
*/
|
|
50
|
+
export declare function parsePbes2AlgorithmIdentifier(algorithmIdentifierDer: Uint8Array): Pbes2Parameters;
|
|
51
|
+
//# sourceMappingURL=pbes2.d.ts.map
|