Skip to content

Commit c922578

Browse files
danbevtargos
authored andcommitted
src: remove ERR prefix in WebCryptoKeyExportStatus
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: #35639 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 3db4354 commit c922578

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

src/crypto/crypto_dh.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,11 @@ WebCryptoKeyExportStatus DHKeyExportTraits::DoExport(
524524
switch (format) {
525525
case kWebCryptoKeyFormatPKCS8:
526526
if (key_data->GetKeyType() != kKeyTypePrivate)
527-
return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE;
527+
return WebCryptoKeyExportStatus::INVALID_KEY_TYPE;
528528
return PKEY_PKCS8_Export(key_data.get(), out);
529529
case kWebCryptoKeyFormatSPKI:
530530
if (key_data->GetKeyType() != kKeyTypePublic)
531-
return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE;
531+
return WebCryptoKeyExportStatus::INVALID_KEY_TYPE;
532532
return PKEY_SPKI_Export(key_data.get(), out);
533533
default:
534534
UNREACHABLE();

src/crypto/crypto_dsa.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ WebCryptoKeyExportStatus DSAKeyExportTraits::DoExport(
113113
switch (format) {
114114
case kWebCryptoKeyFormatRaw:
115115
// Not supported for RSA keys of either type
116-
return WebCryptoKeyExportStatus::ERR_FAILED;
116+
return WebCryptoKeyExportStatus::FAILED;
117117
case kWebCryptoKeyFormatPKCS8:
118118
if (key_data->GetKeyType() != kKeyTypePrivate)
119-
return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE;
119+
return WebCryptoKeyExportStatus::INVALID_KEY_TYPE;
120120
return PKEY_PKCS8_Export(key_data.get(), out);
121121
case kWebCryptoKeyFormatSPKI:
122122
if (key_data->GetKeyType() != kKeyTypePublic)
123-
return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE;
123+
return WebCryptoKeyExportStatus::INVALID_KEY_TYPE;
124124
return PKEY_SPKI_Export(key_data.get(), out);
125125
default:
126126
UNREACHABLE();

src/crypto/crypto_ecdh.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -549,18 +549,18 @@ WebCryptoKeyExportStatus EC_Raw_Export(
549549
// Get the allocated data size...
550550
size_t len = EC_POINT_point2oct(group, point, form, nullptr, 0, nullptr);
551551
if (len == 0)
552-
return WebCryptoKeyExportStatus::ERR_FAILED;
552+
return WebCryptoKeyExportStatus::FAILED;
553553

554554
unsigned char* data = MallocOpenSSL<unsigned char>(len);
555555
size_t check_len = EC_POINT_point2oct(group, point, form, data, len, nullptr);
556556
if (check_len == 0)
557-
return WebCryptoKeyExportStatus::ERR_FAILED;
557+
return WebCryptoKeyExportStatus::FAILED;
558558

559559
CHECK_EQ(len, check_len);
560560

561561
*out = ByteSource::Allocated(reinterpret_cast<char*>(data), len);
562562

563-
return WebCryptoKeyExportStatus::ERR_OK;
563+
return WebCryptoKeyExportStatus::OK;
564564
}
565565
} // namespace
566566

@@ -581,15 +581,15 @@ WebCryptoKeyExportStatus ECKeyExportTraits::DoExport(
581581
switch (format) {
582582
case kWebCryptoKeyFormatRaw:
583583
if (key_data->GetKeyType() != kKeyTypePublic)
584-
return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE;
584+
return WebCryptoKeyExportStatus::INVALID_KEY_TYPE;
585585
return EC_Raw_Export(key_data.get(), params, out);
586586
case kWebCryptoKeyFormatPKCS8:
587587
if (key_data->GetKeyType() != kKeyTypePrivate)
588-
return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE;
588+
return WebCryptoKeyExportStatus::INVALID_KEY_TYPE;
589589
return PKEY_PKCS8_Export(key_data.get(), out);
590590
case kWebCryptoKeyFormatSPKI:
591591
if (key_data->GetKeyType() != kKeyTypePublic)
592-
return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE;
592+
return WebCryptoKeyExportStatus::INVALID_KEY_TYPE;
593593
return PKEY_SPKI_Export(key_data.get(), out);
594594
default:
595595
UNREACHABLE();

src/crypto/crypto_keys.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1261,10 +1261,10 @@ WebCryptoKeyExportStatus PKEY_SPKI_Export(
12611261
CHECK_EQ(key_data->GetKeyType(), kKeyTypePublic);
12621262
BIOPointer bio(BIO_new(BIO_s_mem()));
12631263
if (!i2d_PUBKEY_bio(bio.get(), key_data->GetAsymmetricKey().get()))
1264-
return WebCryptoKeyExportStatus::ERR_FAILED;
1264+
return WebCryptoKeyExportStatus::FAILED;
12651265

12661266
*out = ByteSource::FromBIO(bio);
1267-
return WebCryptoKeyExportStatus::ERR_OK;
1267+
return WebCryptoKeyExportStatus::OK;
12681268
}
12691269

12701270
WebCryptoKeyExportStatus PKEY_PKCS8_Export(
@@ -1274,10 +1274,10 @@ WebCryptoKeyExportStatus PKEY_PKCS8_Export(
12741274
BIOPointer bio(BIO_new(BIO_s_mem()));
12751275
PKCS8Pointer p8inf(EVP_PKEY2PKCS8(key_data->GetAsymmetricKey().get()));
12761276
if (!i2d_PKCS8_PRIV_KEY_INFO_bio(bio.get(), p8inf.get()))
1277-
return WebCryptoKeyExportStatus::ERR_FAILED;
1277+
return WebCryptoKeyExportStatus::FAILED;
12781278

12791279
*out = ByteSource::FromBIO(bio);
1280-
return WebCryptoKeyExportStatus::ERR_OK;
1280+
return WebCryptoKeyExportStatus::OK;
12811281
}
12821282

12831283
namespace Keys {

src/crypto/crypto_keys.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ enum WebCryptoKeyFormat {
262262
};
263263

264264
enum class WebCryptoKeyExportStatus {
265-
ERR_OK,
266-
ERR_INVALID_KEY_TYPE,
267-
ERR_FAILED
265+
OK,
266+
INVALID_KEY_TYPE,
267+
FAILED
268268
};
269269

270270
template <typename KeyExportTraits>
@@ -336,13 +336,13 @@ class KeyExportJob final : public CryptoJob<KeyExportTraits> {
336336
format_,
337337
*CryptoJob<KeyExportTraits>::params(),
338338
&out_)) {
339-
case WebCryptoKeyExportStatus::ERR_OK:
339+
case WebCryptoKeyExportStatus::OK:
340340
// Success!
341341
break;
342-
case WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE:
342+
case WebCryptoKeyExportStatus::INVALID_KEY_TYPE:
343343
// Fall through
344344
// TODO(@jasnell): Separate error for this
345-
case WebCryptoKeyExportStatus::ERR_FAILED: {
345+
case WebCryptoKeyExportStatus::FAILED: {
346346
CryptoErrorVector* errors = CryptoJob<KeyExportTraits>::errors();
347347
errors->Capture();
348348
if (errors->empty())

src/crypto/crypto_rsa.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ WebCryptoKeyExportStatus RSA_JWK_Export(
179179
KeyObjectData* key_data,
180180
const RSAKeyExportConfig& params,
181181
ByteSource* out) {
182-
return WebCryptoKeyExportStatus::ERR_FAILED;
182+
return WebCryptoKeyExportStatus::FAILED;
183183
}
184184

185185
template <PublicKeyCipher::EVP_PKEY_cipher_init_t init,
@@ -268,16 +268,16 @@ WebCryptoKeyExportStatus RSAKeyExportTraits::DoExport(
268268
switch (format) {
269269
case kWebCryptoKeyFormatRaw:
270270
// Not supported for RSA keys of either type
271-
return WebCryptoKeyExportStatus::ERR_FAILED;
271+
return WebCryptoKeyExportStatus::FAILED;
272272
case kWebCryptoKeyFormatJWK:
273273
return RSA_JWK_Export(key_data.get(), params, out);
274274
case kWebCryptoKeyFormatPKCS8:
275275
if (key_data->GetKeyType() != kKeyTypePrivate)
276-
return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE;
276+
return WebCryptoKeyExportStatus::INVALID_KEY_TYPE;
277277
return PKEY_PKCS8_Export(key_data.get(), out);
278278
case kWebCryptoKeyFormatSPKI:
279279
if (key_data->GetKeyType() != kKeyTypePublic)
280-
return WebCryptoKeyExportStatus::ERR_INVALID_KEY_TYPE;
280+
return WebCryptoKeyExportStatus::INVALID_KEY_TYPE;
281281
return PKEY_SPKI_Export(key_data.get(), out);
282282
default:
283283
UNREACHABLE();

0 commit comments

Comments
 (0)