Skip to content

Commit b73c0a1

Browse files
committedSep 24, 2021
crypto: handle initEDRaw pkey failure
1 parent c7da13c commit b73c0a1

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed
 

‎lib/internal/crypto/ec.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,11 @@ function createECRawKey(namedCurve, keyData, isPublic) {
122122
break;
123123
}
124124

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

130-
handle.initEDRaw(namedCurve, keyData, kKeyTypePrivate);
131130
return new PrivateKeyObject(handle);
132131
}
133132

‎lib/internal/crypto/keys.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,10 @@ function getKeyObjectHandleFromJwk(key, ctx) {
435435
}
436436

437437
const handle = new KeyObjectHandle();
438-
if (isPublic) {
439-
handle.initEDRaw(
440-
`NODE-${key.crv.toUpperCase()}`,
441-
keyData,
442-
kKeyTypePublic);
443-
} else {
444-
handle.initEDRaw(
445-
`NODE-${key.crv.toUpperCase()}`,
446-
keyData,
447-
kKeyTypePrivate);
438+
439+
const keyType = isPublic ? kKeyTypePublic : kKeyTypePrivate;
440+
if (!handle.initEDRaw(`NODE-${key.crv.toUpperCase()}`, keyData, keyType)) {
441+
throw new ERR_CRYPTO_INVALID_JWK();
448442
}
449443

450444
return handle;

0 commit comments

Comments
 (0)