@@ -86,9 +86,15 @@ MaybeLocal<Value> ToV8Value(
8686 Environment* env,
8787 const BIOPointer& bio,
8888 const EVPKeyPointer::AsymmetricKeyEncodingConfig& config) {
89- if (!bio) return {};
89+ if (!bio) {
90+ THROW_ERR_CRYPTO_OPERATION_FAILED (env, " Invalid BIO pointer" );
91+ return {};
92+ }
9093 BUF_MEM* bptr = bio;
91- if (!bptr) return {};
94+ if (!bptr) {
95+ THROW_ERR_CRYPTO_OPERATION_FAILED (env, " Unable to create BUF_MEM pointer" );
96+ return {};
97+ }
9298 if (config.format == EVPKeyPointer::PKFormatType::PEM) {
9399 // PEM is an ASCII format, so we will return it as a string.
94100 return String::NewFromUtf8 (
@@ -107,12 +113,7 @@ MaybeLocal<Value> WritePrivateKey(
107113 const EVPKeyPointer::PrivateKeyEncodingConfig& config) {
108114 if (!pkey) return {};
109115 auto res = pkey.writePrivateKey (config);
110- if (res) {
111- auto value = ToV8Value (env, std::move (res.value ), config);
112- if (!value.IsEmpty ()) {
113- return value;
114- }
115- }
116+ if (res) return ToV8Value (env, std::move (res.value ), config);
116117
117118 ThrowCryptoError (
118119 env, res.openssl_error .value_or (0 ), " Failed to encode private key" );
@@ -125,12 +126,7 @@ MaybeLocal<Value> WritePublicKey(
125126 const EVPKeyPointer::PublicKeyEncodingConfig& config) {
126127 if (!pkey) return {};
127128 auto res = pkey.writePublicKey (config);
128- if (res) {
129- auto value = ToV8Value (env, res.value , config);
130- if (!value.IsEmpty ()) {
131- return value;
132- }
133- }
129+ if (res) return ToV8Value (env, std::move (res.value ), config);
134130
135131 ThrowCryptoError (
136132 env, res.openssl_error .value_or (0 ), " Failed to encode public key" );
0 commit comments