crypto: use CryptoKey internal slots in Web Cryptography · nodejs/node@207ffbe
@@ -50,6 +50,8 @@ const {
5050 PublicKeyObject,
5151 createPublicKey,
5252 createPrivateKey,
53+ kAlgorithm,
54+ kKeyType,
5355} = require('internal/crypto/keys');
54565557const {
@@ -95,7 +97,7 @@ function rsaOaepCipher(mode, key, data, algorithm) {
9597validateRsaOaepAlgorithm(algorithm);
96989799const type = mode === kWebCryptoCipherEncrypt ? 'public' : 'private';
98-if (key.type !== type) {
100+if (key[kKeyType] !== type) {
99101throw lazyDOMException(
100102'The requested operation is not valid for the provided key',
101103'InvalidAccessError');
@@ -107,7 +109,7 @@ function rsaOaepCipher(mode, key, data, algorithm) {
107109key[kKeyObject][kHandle],
108110data,
109111kKeyVariantRSA_OAEP,
110-normalizeHashName(key.algorithm.hash.name),
112+normalizeHashName(key[kAlgorithm].hash.name),
111113algorithm.label));
112114}
113115@@ -201,7 +203,7 @@ function rsaExportKey(key, format) {
201203kCryptoJobAsync,
202204format,
203205key[kKeyObject][kHandle],
204-kRsaVariants[key.algorithm.name]));
206+kRsaVariants[key[kAlgorithm].name]));
205207}
206208207209function rsaImportKey(
@@ -329,16 +331,16 @@ function rsaSignVerify(key, data, { saltLength }, signature) {
329331const mode = signature === undefined ? kSignJobModeSign : kSignJobModeVerify;
330332const type = mode === kSignJobModeSign ? 'private' : 'public';
331333332-if (key.type !== type)
334+if (key[kKeyType] !== type)
333335throw lazyDOMException(`Key must be a ${type} key`, 'InvalidAccessError');
334336335337return jobPromise(() => {
336-if (key.algorithm.name === 'RSA-PSS') {
338+if (key[kAlgorithm].name === 'RSA-PSS') {
337339validateInt32(
338340saltLength,
339341'algorithm.saltLength',
3403420,
341-MathCeil((key.algorithm.modulusLength - 1) / 8) - getDigestSizeInBytes(key.algorithm.hash.name) - 2);
343+MathCeil((key[kAlgorithm].modulusLength - 1) / 8) - getDigestSizeInBytes(key[kAlgorithm].hash.name) - 2);
342344}
343345344346return new SignJob(
@@ -349,9 +351,9 @@ function rsaSignVerify(key, data, { saltLength }, signature) {
349351undefined,
350352undefined,
351353data,
352-normalizeHashName(key.algorithm.hash.name),
354+normalizeHashName(key[kAlgorithm].hash.name),
353355saltLength,
354-key.algorithm.name === 'RSA-PSS' ? RSA_PKCS1_PSS_PADDING : undefined,
356+key[kAlgorithm].name === 'RSA-PSS' ? RSA_PKCS1_PSS_PADDING : undefined,
355357undefined,
356358signature);
357359});