mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
src: remove ERR prefix in crypto status enums
This commit removes the ERR prefix of the remaining status enums in
crypto so they are consistent with Commit
923f76d523 ("src: remove ERR prefix in
WebCryptoKeyExportStatus").
PR-URL: https://github.com/nodejs/node/pull/35867
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
This commit is contained in:
1 parent
6968b0fd49
commit
1b277d97f3
5 files changed
+47
-47
No files matched your search
+22
-22
@@ -31,7 +31,7 @@ namespace {
|
||||
// Implements general AES encryption and decryption for CBC
|
||||
// The key_data must be a secret key.
|
||||
// On success, this function sets out to a new AllocatedBuffer
|
||||
// instance containing the results and returns WebCryptoCipherStatus::ERR_OK.
|
||||
// instance containing the results and returns WebCryptoCipherStatus::OK.
|
||||
WebCryptoCipherStatus AES_Cipher(
|
||||
Environment* env,
|
||||
KeyObjectData* key_data,
|
||||
@@ -59,7 +59,7 @@ WebCryptoCipherStatus AES_Cipher(
|
||||
nullptr,
|
||||
encrypt)) {
|
||||
// Cipher init failed
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
|
||||
if (mode == EVP_CIPH_GCM_MODE && !EVP_CIPHER_CTX_ctrl(
|
||||
@@ -67,7 +67,7 @@ WebCryptoCipherStatus AES_Cipher(
|
||||
EVP_CTRL_AEAD_SET_IVLEN,
|
||||
params.iv.size(),
|
||||
nullptr)) {
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
|
||||
if (!EVP_CIPHER_CTX_set_key_length(
|
||||
@@ -80,7 +80,7 @@ WebCryptoCipherStatus AES_Cipher(
|
||||
reinterpret_cast<const unsigned char*>(key_data->GetSymmetricKey()),
|
||||
params.iv.data<unsigned char>(),
|
||||
encrypt)) {
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
|
||||
size_t tag_len = 0;
|
||||
@@ -95,7 +95,7 @@ WebCryptoCipherStatus AES_Cipher(
|
||||
EVP_CTRL_AEAD_SET_TAG,
|
||||
params.tag.size(),
|
||||
const_cast<char*>(params.tag.get()))) {
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
break;
|
||||
case kWebCryptoCipherEncrypt:
|
||||
@@ -123,7 +123,7 @@ WebCryptoCipherStatus AES_Cipher(
|
||||
&out_len,
|
||||
params.additional_data.data<unsigned char>(),
|
||||
params.additional_data.size())) {
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
|
||||
char* data = MallocOpenSSL<char>(buf_len);
|
||||
@@ -136,7 +136,7 @@ WebCryptoCipherStatus AES_Cipher(
|
||||
&out_len,
|
||||
in.data<unsigned char>(),
|
||||
in.size())) {
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
|
||||
total += out_len;
|
||||
@@ -144,7 +144,7 @@ WebCryptoCipherStatus AES_Cipher(
|
||||
ptr += out_len;
|
||||
out_len = EVP_CIPHER_CTX_block_size(ctx.get());
|
||||
if (!EVP_CipherFinal_ex(ctx.get(), ptr, &out_len)) {
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
total += out_len;
|
||||
|
||||
@@ -153,7 +153,7 @@ WebCryptoCipherStatus AES_Cipher(
|
||||
if (cipher_mode == kWebCryptoCipherEncrypt && mode == EVP_CIPH_GCM_MODE) {
|
||||
data += out_len;
|
||||
if (!EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_AEAD_GET_TAG, tag_len, ptr))
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
total += tag_len;
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ WebCryptoCipherStatus AES_Cipher(
|
||||
buf.Resize(total);
|
||||
*out = std::move(buf);
|
||||
|
||||
return WebCryptoCipherStatus::ERR_OK;
|
||||
return WebCryptoCipherStatus::OK;
|
||||
}
|
||||
|
||||
// The AES_CTR implementation here takes it's inspiration from the chromium
|
||||
@@ -232,7 +232,7 @@ WebCryptoCipherStatus AES_CTR_Cipher2(
|
||||
counter,
|
||||
encrypt)) {
|
||||
// Cipher init failed
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
|
||||
int out_len = 0;
|
||||
@@ -243,17 +243,17 @@ WebCryptoCipherStatus AES_CTR_Cipher2(
|
||||
&out_len,
|
||||
in.data<unsigned char>(),
|
||||
in.size())) {
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
|
||||
if (!EVP_CipherFinal_ex(ctx.get(), out + out_len, &final_len))
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
|
||||
out_len += final_len;
|
||||
if (static_cast<unsigned>(out_len) != in.size())
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
|
||||
return WebCryptoCipherStatus::ERR_OK;
|
||||
return WebCryptoCipherStatus::OK;
|
||||
}
|
||||
|
||||
WebCryptoCipherStatus AES_CTR_Cipher(
|
||||
@@ -265,25 +265,25 @@ WebCryptoCipherStatus AES_CTR_Cipher(
|
||||
ByteSource* out) {
|
||||
BignumPointer num_counters(BN_new());
|
||||
if (!BN_lshift(num_counters.get(), BN_value_one(), params.length))
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
|
||||
BignumPointer current_counter = GetCounter(params);
|
||||
|
||||
BignumPointer num_output(BN_new());
|
||||
|
||||
if (!BN_set_word(num_output.get(), CeilDiv(in.size(), kAesBlockSize)))
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
|
||||
// Just like in chromium's implementation, if the counter will
|
||||
// be incremented more than there are counter values, we fail.
|
||||
if (BN_cmp(num_output.get(), num_counters.get()) > 0)
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
|
||||
BignumPointer remaining_until_reset(BN_new());
|
||||
if (!BN_sub(remaining_until_reset.get(),
|
||||
num_counters.get(),
|
||||
current_counter.get())) {
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
|
||||
// Output size is identical to the input size
|
||||
@@ -302,7 +302,7 @@ WebCryptoCipherStatus AES_CTR_Cipher(
|
||||
in,
|
||||
params.iv.data<unsigned char>(),
|
||||
ptr);
|
||||
if (status == WebCryptoCipherStatus::ERR_OK)
|
||||
if (status == WebCryptoCipherStatus::OK)
|
||||
*out = std::move(buf);
|
||||
return status;
|
||||
}
|
||||
@@ -319,7 +319,7 @@ WebCryptoCipherStatus AES_CTR_Cipher(
|
||||
params.iv.data<unsigned char>(),
|
||||
ptr);
|
||||
|
||||
if (status != WebCryptoCipherStatus::ERR_OK)
|
||||
if (status != WebCryptoCipherStatus::OK)
|
||||
return status;
|
||||
|
||||
// Wrap the counter around to zero
|
||||
@@ -336,7 +336,7 @@ WebCryptoCipherStatus AES_CTR_Cipher(
|
||||
new_counter_block.data(),
|
||||
ptr + input_size_part1);
|
||||
|
||||
if (status == WebCryptoCipherStatus::ERR_OK)
|
||||
if (status == WebCryptoCipherStatus::OK)
|
||||
*out = std::move(buf);
|
||||
|
||||
return status;
|
||||
|
||||
@@ -128,9 +128,9 @@ enum WebCryptoCipherMode {
|
||||
};
|
||||
|
||||
enum class WebCryptoCipherStatus {
|
||||
ERR_OK,
|
||||
ERR_INVALID_KEY_TYPE,
|
||||
ERR_FAILED
|
||||
OK,
|
||||
INVALID_KEY_TYPE,
|
||||
FAILED
|
||||
};
|
||||
|
||||
// CipherJob is a base implementation class for implementations of
|
||||
@@ -222,13 +222,13 @@ class CipherJob final : public CryptoJob<CipherTraits> {
|
||||
*CryptoJob<CipherTraits>::params(),
|
||||
in_,
|
||||
&out_)) {
|
||||
case WebCryptoCipherStatus::ERR_OK:
|
||||
case WebCryptoCipherStatus::OK:
|
||||
// Success!
|
||||
break;
|
||||
case WebCryptoCipherStatus::ERR_INVALID_KEY_TYPE:
|
||||
case WebCryptoCipherStatus::INVALID_KEY_TYPE:
|
||||
// Fall through
|
||||
// TODO(@jasnell): Separate error for this
|
||||
case WebCryptoCipherStatus::ERR_FAILED: {
|
||||
case WebCryptoCipherStatus::FAILED: {
|
||||
CryptoErrorVector* errors = CryptoJob<CipherTraits>::errors();
|
||||
errors->Capture();
|
||||
if (errors->empty())
|
||||
|
||||
@@ -84,7 +84,7 @@ KeyGenJobStatus SecretKeyGenTraits::DoKeyGen(
|
||||
CHECK_LE(params->length, INT_MAX);
|
||||
params->out = MallocOpenSSL<char>(params->length);
|
||||
EntropySource(reinterpret_cast<unsigned char*>(params->out), params->length);
|
||||
return KeyGenJobStatus::ERR_OK;
|
||||
return KeyGenJobStatus::OK;
|
||||
}
|
||||
|
||||
Maybe<bool> SecretKeyGenTraits::EncodeKey(
|
||||
|
||||
+10
-10
@@ -19,8 +19,8 @@ void Initialize(Environment* env, v8::Local<v8::Object> target);
|
||||
} // namespace Keygen
|
||||
|
||||
enum class KeyGenJobStatus {
|
||||
ERR_OK,
|
||||
ERR_FAILED
|
||||
OK,
|
||||
FAILED
|
||||
};
|
||||
|
||||
// A Base CryptoJob for generating secret keys or key pairs.
|
||||
@@ -77,11 +77,11 @@ class KeyGenJob final : public CryptoJob<KeyGenTraits> {
|
||||
AdditionalParams* params = CryptoJob<KeyGenTraits>::params();
|
||||
|
||||
switch (KeyGenTraits::DoKeyGen(AsyncWrap::env(), params)) {
|
||||
case KeyGenJobStatus::ERR_OK:
|
||||
status_ = KeyGenJobStatus::ERR_OK;
|
||||
case KeyGenJobStatus::OK:
|
||||
status_ = KeyGenJobStatus::OK;
|
||||
// Success!
|
||||
break;
|
||||
case KeyGenJobStatus::ERR_FAILED: {
|
||||
case KeyGenJobStatus::FAILED: {
|
||||
CryptoErrorVector* errors = CryptoJob<KeyGenTraits>::errors();
|
||||
errors->Capture();
|
||||
if (errors->empty())
|
||||
@@ -96,7 +96,7 @@ class KeyGenJob final : public CryptoJob<KeyGenTraits> {
|
||||
Environment* env = AsyncWrap::env();
|
||||
CryptoErrorVector* errors = CryptoJob<KeyGenTraits>::errors();
|
||||
AdditionalParams* params = CryptoJob<KeyGenTraits>::params();
|
||||
if (status_ == KeyGenJobStatus::ERR_OK &&
|
||||
if (status_ == KeyGenJobStatus::OK &&
|
||||
LIKELY(!KeyGenTraits::EncodeKey(env, params, result).IsNothing())) {
|
||||
*err = Undefined(env->isolate());
|
||||
return v8::Just(true);
|
||||
@@ -112,7 +112,7 @@ class KeyGenJob final : public CryptoJob<KeyGenTraits> {
|
||||
SET_SELF_SIZE(KeyGenJob);
|
||||
|
||||
private:
|
||||
KeyGenJobStatus status_ = KeyGenJobStatus::ERR_FAILED;
|
||||
KeyGenJobStatus status_ = KeyGenJobStatus::FAILED;
|
||||
};
|
||||
|
||||
// A Base KeyGenTraits for Key Pair generation algorithms.
|
||||
@@ -162,15 +162,15 @@ struct KeyPairGenTraits final {
|
||||
AdditionalParameters* params) {
|
||||
EVPKeyCtxPointer ctx = KeyPairAlgorithmTraits::Setup(params);
|
||||
if (!ctx || EVP_PKEY_keygen_init(ctx.get()) <= 0)
|
||||
return KeyGenJobStatus::ERR_FAILED;
|
||||
return KeyGenJobStatus::FAILED;
|
||||
|
||||
// Generate the key
|
||||
EVP_PKEY* pkey = nullptr;
|
||||
if (!EVP_PKEY_keygen(ctx.get(), &pkey))
|
||||
return KeyGenJobStatus::ERR_FAILED;
|
||||
return KeyGenJobStatus::FAILED;
|
||||
|
||||
params->key = ManagedEVPPKey(EVPKeyPointer(pkey));
|
||||
return KeyGenJobStatus::ERR_OK;
|
||||
return KeyGenJobStatus::OK;
|
||||
}
|
||||
|
||||
static v8::Maybe<bool> EncodeKey(
|
||||
|
||||
@@ -196,16 +196,16 @@ WebCryptoCipherStatus RSA_Cipher(
|
||||
EVP_PKEY_CTX_new(key_data->GetAsymmetricKey().get(), nullptr));
|
||||
|
||||
if (!ctx || init(ctx.get()) <= 0)
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
|
||||
if (EVP_PKEY_CTX_set_rsa_padding(ctx.get(), params.padding) <= 0) {
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
|
||||
if (params.digest != nullptr &&
|
||||
(EVP_PKEY_CTX_set_rsa_oaep_md(ctx.get(), params.digest) <= 0 ||
|
||||
EVP_PKEY_CTX_set_rsa_mgf1_md(ctx.get(), params.digest) <= 0)) {
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
|
||||
size_t label_len = params.label.size();
|
||||
@@ -214,7 +214,7 @@ WebCryptoCipherStatus RSA_Cipher(
|
||||
CHECK_NOT_NULL(label);
|
||||
if (EVP_PKEY_CTX_set0_rsa_oaep_label(ctx.get(), label, label_len) <= 0) {
|
||||
OPENSSL_free(label);
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ WebCryptoCipherStatus RSA_Cipher(
|
||||
&out_len,
|
||||
in.data<unsigned char>(),
|
||||
in.size()) <= 0) {
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
|
||||
char* data = MallocOpenSSL<char>(out_len);
|
||||
@@ -238,13 +238,13 @@ WebCryptoCipherStatus RSA_Cipher(
|
||||
&out_len,
|
||||
in.data<unsigned char>(),
|
||||
in.size()) <= 0) {
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
|
||||
buf.Resize(out_len);
|
||||
|
||||
*out = std::move(buf);
|
||||
return WebCryptoCipherStatus::ERR_OK;
|
||||
return WebCryptoCipherStatus::OK;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -356,7 +356,7 @@ WebCryptoCipherStatus RSACipherTraits::DoCipher(
|
||||
return RSA_Cipher<EVP_PKEY_decrypt_init, EVP_PKEY_decrypt>(
|
||||
env, key_data.get(), params, in, out);
|
||||
}
|
||||
return WebCryptoCipherStatus::ERR_FAILED;
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
|
||||
Maybe<bool> ExportJWKRsaKey(
|
||||
|
||||
Reference in new issue
Block a user