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 23, 2021
1 parent c7da13c commit 323cafb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/internal/crypto/ec.js
Expand Up @@ -123,11 +123,15 @@ function createECRawKey(namedCurve, keyData, isPublic) {
}

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

handle.initEDRaw(namedCurve, keyData, kKeyTypePrivate);
if (!handle.initEDRaw(namedCurve, keyData, kKeyTypePrivate)) {
throw lazyDOMException('Failure to generate key object');
}
return new PrivateKeyObject(handle);
}

Expand Down
12 changes: 8 additions & 4 deletions lib/internal/crypto/keys.js
Expand Up @@ -436,15 +436,19 @@ function getKeyObjectHandleFromJwk(key, ctx) {

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

return handle;
Expand Down

0 comments on commit 323cafb

Please sign in to comment.