Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! src: refactor SubtleCrypto algorithm and length validations
  • Loading branch information
panva committed Mar 3, 2025
commit d3b6dd89f8827d8aed74e77fc9698373d1c664db
20 changes: 7 additions & 13 deletions lib/internal/crypto/ec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

const {
ArrayPrototypeIncludes,
ObjectKeys,
ObjectPrototypeHasOwnProperty,
SafeSet,
} = primordials;

Expand Down Expand Up @@ -77,16 +76,16 @@ function createECPublicKeyRaw(namedCurve, keyData) {
return new PublicKeyObject(handle);
}

function validateEcGenerateKeyAlgorithm(algorithm) {
if (!ArrayPrototypeIncludes(ObjectKeys(kNamedCurveAliases), algorithm.namedCurve)) {
function validateEcKeyAlgorithm(algorithm) {
if (!ObjectPrototypeHasOwnProperty(kNamedCurveAliases, algorithm.namedCurve)) {
throw lazyDOMException(
'Unrecognized namedCurve',
'NotSupportedError');
}
}

async function ecGenerateKey(algorithm, extractable, keyUsages) {
validateEcGenerateKeyAlgorithm(algorithm);
validateEcKeyAlgorithm(algorithm);
const { name, namedCurve } = algorithm;

const usageSet = new SafeSet(keyUsages);
Expand Down Expand Up @@ -157,16 +156,11 @@ function ecImportKey(
keyData,
algorithm,
extractable,
keyUsages) {

keyUsages,
) {
validateEcKeyAlgorithm(algorithm);
const { name, namedCurve } = algorithm;

if (!ArrayPrototypeIncludes(ObjectKeys(kNamedCurveAliases), namedCurve)) {
throw lazyDOMException(
'Unrecognized namedCurve',
'NotSupportedError');
}

let keyObject;
const usagesSet = new SafeSet(keyUsages);
switch (format) {
Expand Down