mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
crypto: handle initEDRaw pkey failure
PR-URL: https://github.com/nodejs/node/pull/40188 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
committed by
James M Snell
parent
5ba7fbb731
commit
17bb7b2936
@@ -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) : new PrivateKeyObject(handle);
|
||||
}
|
||||
|
||||
async function ecGenerateKey(algorithm, extractable, keyUsages) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user