From 923f76d5231256e69985e1bd897fd490ea0cbe9c Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Wed, 14 Oct 2020 12:36:56 +0200 Subject: [PATCH] src: remove ERR prefix in WebCryptoKeyExportStatus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit suggests removing the ERR prefix in the WebCryptoKeyExportStatus enum. The motivation for this is that I think it improves the readability of the code. For example, the following line had me look twice to see what was going on: case WebCryptoKeyExportStatus::ERR_OK: // Success! PR-URL: https://github.com/nodejs/node/pull/35639 Reviewed-By: James M Snell Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Tobias Nießen --- src/crypto/crypto_dh.cc | 4 ++-- src/crypto/crypto_dsa.cc | 6 +++--- src/crypto/crypto_ecdh.cc | 12 ++++++------ src/crypto/crypto_keys.cc | 8 ++++---- src/crypto/crypto_keys.h | 12 ++++++------ src/crypto/crypto_rsa.cc | 8 ++++---- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/crypto/crypto_dh.cc b/src/crypto/crypto_dh.cc index 8a968200687dfb..a2720301cab356 100644 --- a/src/crypto/crypto_dh.cc +++ b/src/crypto/crypto_dh.cc @@ -524,11 +524,11 @@ WebCryptoKeyExportStatus DHKeyExportTraits::DoExport( switch (format) { case kWebCryptoKeyFormatPKCS8: if (key_data->GetKeyType() != kKeyTypePrivate) - return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE; + return WebCryptoKeyExportStatus::INVALID_KEY_TYPE; return PKEY_PKCS8_Export(key_data.get(), out); case kWebCryptoKeyFormatSPKI: if (key_data->GetKeyType() != kKeyTypePublic) - return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE; + return WebCryptoKeyExportStatus::INVALID_KEY_TYPE; return PKEY_SPKI_Export(key_data.get(), out); default: UNREACHABLE(); diff --git a/src/crypto/crypto_dsa.cc b/src/crypto/crypto_dsa.cc index 1dc0a86fb4b10c..ad921ac92012e6 100644 --- a/src/crypto/crypto_dsa.cc +++ b/src/crypto/crypto_dsa.cc @@ -113,14 +113,14 @@ WebCryptoKeyExportStatus DSAKeyExportTraits::DoExport( switch (format) { case kWebCryptoKeyFormatRaw: // Not supported for RSA keys of either type - return WebCryptoKeyExportStatus::ERR_FAILED; + return WebCryptoKeyExportStatus::FAILED; case kWebCryptoKeyFormatPKCS8: if (key_data->GetKeyType() != kKeyTypePrivate) - return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE; + return WebCryptoKeyExportStatus::INVALID_KEY_TYPE; return PKEY_PKCS8_Export(key_data.get(), out); case kWebCryptoKeyFormatSPKI: if (key_data->GetKeyType() != kKeyTypePublic) - return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE; + return WebCryptoKeyExportStatus::INVALID_KEY_TYPE; return PKEY_SPKI_Export(key_data.get(), out); default: UNREACHABLE(); diff --git a/src/crypto/crypto_ecdh.cc b/src/crypto/crypto_ecdh.cc index 9da31b0b5778c0..e2fdc3234b0ae8 100644 --- a/src/crypto/crypto_ecdh.cc +++ b/src/crypto/crypto_ecdh.cc @@ -549,18 +549,18 @@ WebCryptoKeyExportStatus EC_Raw_Export( // Get the allocated data size... size_t len = EC_POINT_point2oct(group, point, form, nullptr, 0, nullptr); if (len == 0) - return WebCryptoKeyExportStatus::ERR_FAILED; + return WebCryptoKeyExportStatus::FAILED; unsigned char* data = MallocOpenSSL(len); size_t check_len = EC_POINT_point2oct(group, point, form, data, len, nullptr); if (check_len == 0) - return WebCryptoKeyExportStatus::ERR_FAILED; + return WebCryptoKeyExportStatus::FAILED; CHECK_EQ(len, check_len); *out = ByteSource::Allocated(reinterpret_cast(data), len); - return WebCryptoKeyExportStatus::ERR_OK; + return WebCryptoKeyExportStatus::OK; } } // namespace @@ -581,15 +581,15 @@ WebCryptoKeyExportStatus ECKeyExportTraits::DoExport( switch (format) { case kWebCryptoKeyFormatRaw: if (key_data->GetKeyType() != kKeyTypePublic) - return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE; + return WebCryptoKeyExportStatus::INVALID_KEY_TYPE; return EC_Raw_Export(key_data.get(), params, out); case kWebCryptoKeyFormatPKCS8: if (key_data->GetKeyType() != kKeyTypePrivate) - return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE; + return WebCryptoKeyExportStatus::INVALID_KEY_TYPE; return PKEY_PKCS8_Export(key_data.get(), out); case kWebCryptoKeyFormatSPKI: if (key_data->GetKeyType() != kKeyTypePublic) - return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE; + return WebCryptoKeyExportStatus::INVALID_KEY_TYPE; return PKEY_SPKI_Export(key_data.get(), out); default: UNREACHABLE(); diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index f5538e54d7e11b..de785a17e05dfc 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -1261,10 +1261,10 @@ WebCryptoKeyExportStatus PKEY_SPKI_Export( CHECK_EQ(key_data->GetKeyType(), kKeyTypePublic); BIOPointer bio(BIO_new(BIO_s_mem())); if (!i2d_PUBKEY_bio(bio.get(), key_data->GetAsymmetricKey().get())) - return WebCryptoKeyExportStatus::ERR_FAILED; + return WebCryptoKeyExportStatus::FAILED; *out = ByteSource::FromBIO(bio); - return WebCryptoKeyExportStatus::ERR_OK; + return WebCryptoKeyExportStatus::OK; } WebCryptoKeyExportStatus PKEY_PKCS8_Export( @@ -1274,10 +1274,10 @@ WebCryptoKeyExportStatus PKEY_PKCS8_Export( BIOPointer bio(BIO_new(BIO_s_mem())); PKCS8Pointer p8inf(EVP_PKEY2PKCS8(key_data->GetAsymmetricKey().get())); if (!i2d_PKCS8_PRIV_KEY_INFO_bio(bio.get(), p8inf.get())) - return WebCryptoKeyExportStatus::ERR_FAILED; + return WebCryptoKeyExportStatus::FAILED; *out = ByteSource::FromBIO(bio); - return WebCryptoKeyExportStatus::ERR_OK; + return WebCryptoKeyExportStatus::OK; } namespace Keys { diff --git a/src/crypto/crypto_keys.h b/src/crypto/crypto_keys.h index 1799ec01ed793e..19bab4749e0803 100644 --- a/src/crypto/crypto_keys.h +++ b/src/crypto/crypto_keys.h @@ -262,9 +262,9 @@ enum WebCryptoKeyFormat { }; enum class WebCryptoKeyExportStatus { - ERR_OK, - ERR_INVALID_KEY_TYPE, - ERR_FAILED + OK, + INVALID_KEY_TYPE, + FAILED }; template @@ -336,13 +336,13 @@ class KeyExportJob final : public CryptoJob { format_, *CryptoJob::params(), &out_)) { - case WebCryptoKeyExportStatus::ERR_OK: + case WebCryptoKeyExportStatus::OK: // Success! break; - case WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE: + case WebCryptoKeyExportStatus::INVALID_KEY_TYPE: // Fall through // TODO(@jasnell): Separate error for this - case WebCryptoKeyExportStatus::ERR_FAILED: { + case WebCryptoKeyExportStatus::FAILED: { CryptoErrorVector* errors = CryptoJob::errors(); errors->Capture(); if (errors->empty()) diff --git a/src/crypto/crypto_rsa.cc b/src/crypto/crypto_rsa.cc index 3576e6084c4a76..70022b3bce3bf5 100644 --- a/src/crypto/crypto_rsa.cc +++ b/src/crypto/crypto_rsa.cc @@ -179,7 +179,7 @@ WebCryptoKeyExportStatus RSA_JWK_Export( KeyObjectData* key_data, const RSAKeyExportConfig& params, ByteSource* out) { - return WebCryptoKeyExportStatus::ERR_FAILED; + return WebCryptoKeyExportStatus::FAILED; } template GetKeyType() != kKeyTypePrivate) - return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE; + return WebCryptoKeyExportStatus::INVALID_KEY_TYPE; return PKEY_PKCS8_Export(key_data.get(), out); case kWebCryptoKeyFormatSPKI: if (key_data->GetKeyType() != kKeyTypePublic) - return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE; + return WebCryptoKeyExportStatus::INVALID_KEY_TYPE; return PKEY_SPKI_Export(key_data.get(), out); default: UNREACHABLE();