diff --git a/lib/internal/crypto/cfrg.js b/lib/internal/crypto/cfrg.js index 5dd4e44bdd06cc..6910aa84134a57 100644 --- a/lib/internal/crypto/cfrg.js +++ b/lib/internal/crypto/cfrg.js @@ -72,13 +72,6 @@ function verifyAcceptableCfrgKeyUse(name, type, usages) { } } -function createECPublicKeyRaw(name, keyData) { - const handle = new KeyObjectHandle(); - keyData = getArrayBufferOrView(keyData, 'keyData'); - if (handle.initECRaw(name.toLowerCase(), keyData)) - return new PublicKeyObject(handle); -} - function createCFRGRawKey(name, keyData, isPublic) { const handle = new KeyObjectHandle(); keyData = getArrayBufferOrView(keyData, 'keyData'); @@ -297,7 +290,7 @@ async function cfrgImportKey( } case 'raw': { verifyAcceptableCfrgKeyUse(name, 'public', usagesSet); - keyObject = createECPublicKeyRaw(name, keyData); + keyObject = createCFRGRawKey(name, keyData, true); if (keyObject === undefined) throw lazyDOMException('Unable to import CFRG key', 'OperationError'); break; diff --git a/test/parallel/test-webcrypto-export-import-cfrg.js b/test/parallel/test-webcrypto-export-import-cfrg.js index 531cb51c1b8b8c..6d162ac61c2e30 100644 --- a/test/parallel/test-webcrypto-export-import-cfrg.js +++ b/test/parallel/test-webcrypto-export-import-cfrg.js @@ -281,6 +281,20 @@ async function testImportJwk({ name, publicUsages, privateUsages }, extractable) } } +async function testImportRaw({ name, publicUsages }) { + const jwk = keyData[name].jwk; + + const publicKey = await subtle.importKey( + 'raw', + Buffer.from(jwk.x, 'base64url'), + { name }, + true, publicUsages); + + assert.strictEqual(publicKey.type, 'public'); + assert.deepStrictEqual(publicKey.usages, publicUsages); + assert.strictEqual(publicKey.algorithm.name, name); +} + (async function() { const tests = []; testVectors.forEach((vector) => { @@ -289,6 +303,7 @@ async function testImportJwk({ name, publicUsages, privateUsages }, extractable) tests.push(testImportPkcs8(vector, extractable)); tests.push(testImportJwk(vector, extractable)); }); + tests.push(testImportRaw(vector)); }); await Promise.all(tests);