Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto: cleanup webcrypto jwk code
Browse files Browse the repository at this point in the history
PR-URL: #42562
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Akhil Marsonya <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
panva authored and juanarbol committed Apr 4, 2022
1 parent 44ac5e8 commit c036258
Showing 2 changed files with 0 additions and 56 deletions.
51 changes: 0 additions & 51 deletions lib/internal/crypto/dsa.js
Original file line number Diff line number Diff line change
@@ -7,11 +7,9 @@ const {

const {
DSAKeyExportJob,
KeyObjectHandle,
SignJob,
kCryptoJobAsync,
kSigEncDER,
kKeyTypePrivate,
kSignJobModeSign,
kSignJobModeVerify,
} = internalBinding('crypto');
@@ -29,8 +27,6 @@ const {

const {
InternalCryptoKey,
PrivateKeyObject,
PublicKeyObject,
createPrivateKey,
createPublicKey,
isKeyObject,
@@ -45,7 +41,6 @@ const {
hasAnyNotIn,
jobPromise,
normalizeHashName,
validateKeyOps,
kKeyObject,
kHandle,
} = require('internal/crypto/util');
@@ -178,52 +173,6 @@ async function dsaImportKey(
});
break;
}
case 'jwk': {
if (keyData == null || typeof keyData !== 'object')
throw lazyDOMException('Invalid JWK keyData', 'DataError');

verifyAcceptableDsaKeyUse(
algorithm.name,
keyData.x !== undefined ? 'private' : 'public',
usagesSet);

if (keyData.kty !== 'DSA')
throw lazyDOMException('Invalid key type', 'DataError');

if (usagesSet.size > 0 &&
keyData.use !== undefined &&
keyData.use !== 'sig') {
throw lazyDOMException('Invalid use type', 'DataError');
}

validateKeyOps(keyData.key_ops, usagesSet);

if (keyData.ext !== undefined &&
keyData.ext === false &&
extractable === true) {
throw lazyDOMException('JWK is not extractable', 'DataError');
}

if (keyData.alg !== undefined) {
if (typeof keyData.alg !== 'string')
throw lazyDOMException('Invalid alg', 'DataError');
const hash =
normalizeHashName(keyData.alg, normalizeHashName.kContextWebCrypto);
if (hash !== algorithm.hash.name)
throw lazyDOMException('Hash mismatch', 'DataError');
}

const handle = new KeyObjectHandle();
const type = handle.initJwk(keyData);
if (type === undefined)
throw lazyDOMException('Invalid JWK keyData', 'DataError');

keyObject = type === kKeyTypePrivate ?
new PrivateKeyObject(handle) :
new PublicKeyObject(handle);

break;
}
default:
throw lazyDOMException(
`Unable to import DSA key with format ${format}`,
5 changes: 0 additions & 5 deletions lib/internal/crypto/webcrypto.js
Original file line number Diff line number Diff line change
@@ -403,11 +403,6 @@ async function exportKeyJWK(key) {
key.algorithm.hash.name,
normalizeHashName.kContextJwkHmac);
return jwk;
case 'NODE-DSA':
jwk.alg = normalizeHashName(
key.algorithm.hash.name,
normalizeHashName.kContextJwkDsa);
return jwk;
case 'NODE-ED25519':
// Fall through
case 'NODE-ED448':

0 comments on commit c036258

Please sign in to comment.