Skip to content

Commit

Permalink
crypto: handle initEDRaw pkey failure
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Sep 24, 2021
1 parent c7da13c commit f7f01b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
9 changes: 4 additions & 5 deletions lib/internal/crypto/ec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,12 @@ function createECRawKey(namedCurve, keyData, isPublic) {
break;
}

if (isPublic) {
handle.initEDRaw(namedCurve, keyData, kKeyTypePublic);
return new PublicKeyObject(handle);
const keyType = isPublic ? kKeyTypePublic : kKeyTypePrivate;
if (!handle.initEDRaw(namedCurve, keyData, keyType)) {
throw lazyDOMException('Failure to generate key object');
}

handle.initEDRaw(namedCurve, keyData, kKeyTypePrivate);
return new PrivateKeyObject(handle);
return isPublic ? new PublicKeyObject(handle) : PrivateKeyObject(handle);
}

async function ecGenerateKey(algorithm, extractable, keyUsages) {
Expand Down
14 changes: 4 additions & 10 deletions lib/internal/crypto/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,16 +435,10 @@ function getKeyObjectHandleFromJwk(key, ctx) {
}

const handle = new KeyObjectHandle();
if (isPublic) {
handle.initEDRaw(
`NODE-${key.crv.toUpperCase()}`,
keyData,
kKeyTypePublic);
} else {
handle.initEDRaw(
`NODE-${key.crv.toUpperCase()}`,
keyData,
kKeyTypePrivate);

const keyType = isPublic ? kKeyTypePublic : kKeyTypePrivate;
if (!handle.initEDRaw(`NODE-${key.crv.toUpperCase()}`, keyData, keyType)) {
throw new ERR_CRYPTO_INVALID_JWK();
}

return handle;
Expand Down

0 comments on commit f7f01b6

Please sign in to comment.