Skip to content

Commit cb66676

Browse files
committed
fixup! crypto: add SubleCrypto.supports feature detection in Web Crypto API
1 parent 2ac7785 commit cb66676

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

lib/internal/crypto/webcrypto.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const {
4141
const {
4242
bigIntArrayToUnsignedInt,
4343
getBlockSize,
44+
getCiphers,
45+
getCurves,
4446
normalizeAlgorithm,
4547
normalizeHashName,
4648
validateBitLength,
@@ -1033,6 +1035,28 @@ function check(op, alg, length) {
10331035
return false;
10341036
}
10351037

1038+
if (
1039+
normalizedAlgorithm.namedCurve &&
1040+
!getCurves().includes(kNamedCurveAliases[normalizedAlgorithm.namedCurve])
1041+
) {
1042+
return false;
1043+
}
1044+
1045+
if (normalizedAlgorithm.name.startsWith('AES') && normalizedAlgorithm.length) {
1046+
const mode = normalizedAlgorithm.name.substring(4).toLowerCase()
1047+
let cipher;
1048+
switch (mode) {
1049+
case 'kw':
1050+
cipher = `aes${length}-wrap`
1051+
break;
1052+
default:
1053+
cipher = `aes-${length}-${mode}`
1054+
}
1055+
if (!getCiphers().includes(cipher)) {
1056+
return false;
1057+
}
1058+
}
1059+
10361060
if (op === 'wrapKey') return true;
10371061
if (op === 'unwrapKey') return true;
10381062
if (op === 'exportKey') return true;
@@ -1046,12 +1070,6 @@ function check(op, alg, length) {
10461070
return false;
10471071
}
10481072

1049-
if (normalizedAlgorithm.namedCurve) {
1050-
if (!ArrayPrototypeIncludes(ObjectKeys(kNamedCurveAliases), normalizedAlgorithm.namedCurve)) {
1051-
return false;
1052-
}
1053-
}
1054-
10551073
return true;
10561074
}
10571075

0 commit comments

Comments
 (0)