diff --git a/src/crypto/crypto_keygen.h b/src/crypto/crypto_keygen.h index c286cffdc95c63..03729faf9c23f0 100644 --- a/src/crypto/crypto_keygen.h +++ b/src/crypto/crypto_keygen.h @@ -238,7 +238,9 @@ struct KeyPairGenConfig final : public MemoryRetainer { KeyPairGenConfig() = default; ~KeyPairGenConfig() { - Mutex::ScopedLock priv_lock(key->mutex()); + if (key) { + Mutex::ScopedLock priv_lock(key->mutex()); + } } explicit KeyPairGenConfig(KeyPairGenConfig&& other) noexcept diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index f336d59813fe5e..cd8351a57c64c3 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -763,18 +763,19 @@ std::shared_ptr KeyObjectData::GetParsedKey( ParseKeyResult ret, const char* default_msg) { switch (ret) { - case ParseKeyResult::kParseKeyOk: - CHECK(pkey); - break; - case ParseKeyResult::kParseKeyNeedPassphrase: + case ParseKeyResult::kParseKeyOk: { + return CreateAsymmetric(type, std::move(pkey)); + } + case ParseKeyResult::kParseKeyNeedPassphrase: { THROW_ERR_MISSING_PASSPHRASE(env, "Passphrase required for encrypted key"); - break; - default: + return {}; + } + default: { ThrowCryptoError(env, ERR_get_error(), default_msg); + return {}; + } } - - return CreateAsymmetric(type, std::move(pkey)); } KeyObjectData::KeyObjectData(Private, ByteSource symmetric_key)