diff --git a/lib/internal/crypto/keys.js b/lib/internal/crypto/keys.js index 889c3763b965df..3c976ca349e4fa 100644 --- a/lib/internal/crypto/keys.js +++ b/lib/internal/crypto/keys.js @@ -43,13 +43,6 @@ for (const m of [[kKeyEncodingPKCS1, 'pkcs1'], [kKeyEncodingPKCS8, 'pkcs8'], [kKeyEncodingSPKI, 'spki'], [kKeyEncodingSEC1, 'sec1']]) encodingNames[m[0]] = m[1]; -function checkKeyTypeAndHandle(type, handle) { - if (type !== 'secret' && type !== 'public' && type !== 'private') - throw new ERR_INVALID_ARG_VALUE('type', type); - if (typeof handle !== 'object' || !(handle instanceof KeyObjectHandle)) - throw new ERR_INVALID_ARG_TYPE('handle', 'object', handle); -} - // Creating the KeyObject class is a little complicated due to inheritance // and that fact that KeyObjects should be transferrable between threads, // which requires the KeyObject base class to be implemented in C++. @@ -64,7 +57,12 @@ const [ // Publicly visible KeyObject class. class KeyObject extends NativeKeyObject { constructor(type, handle) { - super(checkKeyTypeAndHandle(type, handle) || handle); + if (type !== 'secret' && type !== 'public' && type !== 'private') + throw new ERR_INVALID_ARG_VALUE('type', type); + if (typeof handle !== 'object' || !(handle instanceof KeyObjectHandle)) + throw new ERR_INVALID_ARG_TYPE('handle', 'object', handle); + + super(handle); this[kKeyType] = type;