From 1b277d97f342cf7a71de3b60d35c2b3c2478415f Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 29 Oct 2020 17:28:28 +0100 Subject: [PATCH] src: remove ERR prefix in crypto status enums MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit removes the ERR prefix of the remaining status enums in crypto so they are consistent with Commit 923f76d5231256e69985e1bd897fd490ea0cbe9c ("src: remove ERR prefix in WebCryptoKeyExportStatus"). PR-URL: https://github.com/nodejs/node/pull/35867 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen Reviewed-By: David Carlier Reviewed-By: Franziska Hinkelmann --- src/crypto/crypto_aes.cc | 44 ++++++++++++++++++------------------- src/crypto/crypto_cipher.h | 12 +++++----- src/crypto/crypto_keygen.cc | 2 +- src/crypto/crypto_keygen.h | 20 ++++++++--------- src/crypto/crypto_rsa.cc | 16 +++++++------- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/crypto/crypto_aes.cc b/src/crypto/crypto_aes.cc index 889bb487fa04d5..584839e813e570 100644 --- a/src/crypto/crypto_aes.cc +++ b/src/crypto/crypto_aes.cc @@ -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(key_data->GetSymmetricKey()), params.iv.data(), 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(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(), params.additional_data.size())) { - return WebCryptoCipherStatus::ERR_FAILED; + return WebCryptoCipherStatus::FAILED; } char* data = MallocOpenSSL(buf_len); @@ -136,7 +136,7 @@ WebCryptoCipherStatus AES_Cipher( &out_len, in.data(), 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(), 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(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(), 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(), 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; diff --git a/src/crypto/crypto_cipher.h b/src/crypto/crypto_cipher.h index 725807d509525d..bae187a6e139a3 100644 --- a/src/crypto/crypto_cipher.h +++ b/src/crypto/crypto_cipher.h @@ -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 { *CryptoJob::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::errors(); errors->Capture(); if (errors->empty()) diff --git a/src/crypto/crypto_keygen.cc b/src/crypto/crypto_keygen.cc index c6ce46584f4104..ab78b7aabc694b 100644 --- a/src/crypto/crypto_keygen.cc +++ b/src/crypto/crypto_keygen.cc @@ -84,7 +84,7 @@ KeyGenJobStatus SecretKeyGenTraits::DoKeyGen( CHECK_LE(params->length, INT_MAX); params->out = MallocOpenSSL(params->length); EntropySource(reinterpret_cast(params->out), params->length); - return KeyGenJobStatus::ERR_OK; + return KeyGenJobStatus::OK; } Maybe SecretKeyGenTraits::EncodeKey( diff --git a/src/crypto/crypto_keygen.h b/src/crypto/crypto_keygen.h index 28dc1273a9e27c..c4197c6eaed8f9 100644 --- a/src/crypto/crypto_keygen.h +++ b/src/crypto/crypto_keygen.h @@ -19,8 +19,8 @@ void Initialize(Environment* env, v8::Local 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 { AdditionalParams* params = CryptoJob::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::errors(); errors->Capture(); if (errors->empty()) @@ -96,7 +96,7 @@ class KeyGenJob final : public CryptoJob { Environment* env = AsyncWrap::env(); CryptoErrorVector* errors = CryptoJob::errors(); AdditionalParams* params = CryptoJob::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 { 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 EncodeKey( diff --git a/src/crypto/crypto_rsa.cc b/src/crypto/crypto_rsa.cc index 70022b3bce3bf5..ac5dbd5106e678 100644 --- a/src/crypto/crypto_rsa.cc +++ b/src/crypto/crypto_rsa.cc @@ -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(), in.size()) <= 0) { - return WebCryptoCipherStatus::ERR_FAILED; + return WebCryptoCipherStatus::FAILED; } char* data = MallocOpenSSL(out_len); @@ -238,13 +238,13 @@ WebCryptoCipherStatus RSA_Cipher( &out_len, in.data(), 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( env, key_data.get(), params, in, out); } - return WebCryptoCipherStatus::ERR_FAILED; + return WebCryptoCipherStatus::FAILED; } Maybe ExportJWKRsaKey(