Skip to content

Commit 1b277d9

Browse files
danbevdanielleadams
authored andcommitted
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 923f76d ("src: remove ERR prefix in WebCryptoKeyExportStatus"). PR-URL: #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>
1 parent 6968b0f commit 1b277d9

File tree

5 files changed

+47
-47
lines changed

5 files changed

+47
-47
lines changed

src/crypto/crypto_aes.cc

+22-22
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace {
3131
// Implements general AES encryption and decryption for CBC
3232
// The key_data must be a secret key.
3333
// On success, this function sets out to a new AllocatedBuffer
34-
// instance containing the results and returns WebCryptoCipherStatus::ERR_OK.
34+
// instance containing the results and returns WebCryptoCipherStatus::OK.
3535
WebCryptoCipherStatus AES_Cipher(
3636
Environment* env,
3737
KeyObjectData* key_data,
@@ -59,15 +59,15 @@ WebCryptoCipherStatus AES_Cipher(
5959
nullptr,
6060
encrypt)) {
6161
// Cipher init failed
62-
return WebCryptoCipherStatus::ERR_FAILED;
62+
return WebCryptoCipherStatus::FAILED;
6363
}
6464

6565
if (mode == EVP_CIPH_GCM_MODE && !EVP_CIPHER_CTX_ctrl(
6666
ctx.get(),
6767
EVP_CTRL_AEAD_SET_IVLEN,
6868
params.iv.size(),
6969
nullptr)) {
70-
return WebCryptoCipherStatus::ERR_FAILED;
70+
return WebCryptoCipherStatus::FAILED;
7171
}
7272

7373
if (!EVP_CIPHER_CTX_set_key_length(
@@ -80,7 +80,7 @@ WebCryptoCipherStatus AES_Cipher(
8080
reinterpret_cast<const unsigned char*>(key_data->GetSymmetricKey()),
8181
params.iv.data<unsigned char>(),
8282
encrypt)) {
83-
return WebCryptoCipherStatus::ERR_FAILED;
83+
return WebCryptoCipherStatus::FAILED;
8484
}
8585

8686
size_t tag_len = 0;
@@ -95,7 +95,7 @@ WebCryptoCipherStatus AES_Cipher(
9595
EVP_CTRL_AEAD_SET_TAG,
9696
params.tag.size(),
9797
const_cast<char*>(params.tag.get()))) {
98-
return WebCryptoCipherStatus::ERR_FAILED;
98+
return WebCryptoCipherStatus::FAILED;
9999
}
100100
break;
101101
case kWebCryptoCipherEncrypt:
@@ -123,7 +123,7 @@ WebCryptoCipherStatus AES_Cipher(
123123
&out_len,
124124
params.additional_data.data<unsigned char>(),
125125
params.additional_data.size())) {
126-
return WebCryptoCipherStatus::ERR_FAILED;
126+
return WebCryptoCipherStatus::FAILED;
127127
}
128128

129129
char* data = MallocOpenSSL<char>(buf_len);
@@ -136,15 +136,15 @@ WebCryptoCipherStatus AES_Cipher(
136136
&out_len,
137137
in.data<unsigned char>(),
138138
in.size())) {
139-
return WebCryptoCipherStatus::ERR_FAILED;
139+
return WebCryptoCipherStatus::FAILED;
140140
}
141141

142142
total += out_len;
143143
CHECK_LE(out_len, buf_len);
144144
ptr += out_len;
145145
out_len = EVP_CIPHER_CTX_block_size(ctx.get());
146146
if (!EVP_CipherFinal_ex(ctx.get(), ptr, &out_len)) {
147-
return WebCryptoCipherStatus::ERR_FAILED;
147+
return WebCryptoCipherStatus::FAILED;
148148
}
149149
total += out_len;
150150

@@ -153,15 +153,15 @@ WebCryptoCipherStatus AES_Cipher(
153153
if (cipher_mode == kWebCryptoCipherEncrypt && mode == EVP_CIPH_GCM_MODE) {
154154
data += out_len;
155155
if (!EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_AEAD_GET_TAG, tag_len, ptr))
156-
return WebCryptoCipherStatus::ERR_FAILED;
156+
return WebCryptoCipherStatus::FAILED;
157157
total += tag_len;
158158
}
159159

160160
// It's possible that we haven't used the full allocated space. Size down.
161161
buf.Resize(total);
162162
*out = std::move(buf);
163163

164-
return WebCryptoCipherStatus::ERR_OK;
164+
return WebCryptoCipherStatus::OK;
165165
}
166166

167167
// The AES_CTR implementation here takes it's inspiration from the chromium
@@ -232,7 +232,7 @@ WebCryptoCipherStatus AES_CTR_Cipher2(
232232
counter,
233233
encrypt)) {
234234
// Cipher init failed
235-
return WebCryptoCipherStatus::ERR_FAILED;
235+
return WebCryptoCipherStatus::FAILED;
236236
}
237237

238238
int out_len = 0;
@@ -243,17 +243,17 @@ WebCryptoCipherStatus AES_CTR_Cipher2(
243243
&out_len,
244244
in.data<unsigned char>(),
245245
in.size())) {
246-
return WebCryptoCipherStatus::ERR_FAILED;
246+
return WebCryptoCipherStatus::FAILED;
247247
}
248248

249249
if (!EVP_CipherFinal_ex(ctx.get(), out + out_len, &final_len))
250-
return WebCryptoCipherStatus::ERR_FAILED;
250+
return WebCryptoCipherStatus::FAILED;
251251

252252
out_len += final_len;
253253
if (static_cast<unsigned>(out_len) != in.size())
254-
return WebCryptoCipherStatus::ERR_FAILED;
254+
return WebCryptoCipherStatus::FAILED;
255255

256-
return WebCryptoCipherStatus::ERR_OK;
256+
return WebCryptoCipherStatus::OK;
257257
}
258258

259259
WebCryptoCipherStatus AES_CTR_Cipher(
@@ -265,25 +265,25 @@ WebCryptoCipherStatus AES_CTR_Cipher(
265265
ByteSource* out) {
266266
BignumPointer num_counters(BN_new());
267267
if (!BN_lshift(num_counters.get(), BN_value_one(), params.length))
268-
return WebCryptoCipherStatus::ERR_FAILED;
268+
return WebCryptoCipherStatus::FAILED;
269269

270270
BignumPointer current_counter = GetCounter(params);
271271

272272
BignumPointer num_output(BN_new());
273273

274274
if (!BN_set_word(num_output.get(), CeilDiv(in.size(), kAesBlockSize)))
275-
return WebCryptoCipherStatus::ERR_FAILED;
275+
return WebCryptoCipherStatus::FAILED;
276276

277277
// Just like in chromium's implementation, if the counter will
278278
// be incremented more than there are counter values, we fail.
279279
if (BN_cmp(num_output.get(), num_counters.get()) > 0)
280-
return WebCryptoCipherStatus::ERR_FAILED;
280+
return WebCryptoCipherStatus::FAILED;
281281

282282
BignumPointer remaining_until_reset(BN_new());
283283
if (!BN_sub(remaining_until_reset.get(),
284284
num_counters.get(),
285285
current_counter.get())) {
286-
return WebCryptoCipherStatus::ERR_FAILED;
286+
return WebCryptoCipherStatus::FAILED;
287287
}
288288

289289
// Output size is identical to the input size
@@ -302,7 +302,7 @@ WebCryptoCipherStatus AES_CTR_Cipher(
302302
in,
303303
params.iv.data<unsigned char>(),
304304
ptr);
305-
if (status == WebCryptoCipherStatus::ERR_OK)
305+
if (status == WebCryptoCipherStatus::OK)
306306
*out = std::move(buf);
307307
return status;
308308
}
@@ -319,7 +319,7 @@ WebCryptoCipherStatus AES_CTR_Cipher(
319319
params.iv.data<unsigned char>(),
320320
ptr);
321321

322-
if (status != WebCryptoCipherStatus::ERR_OK)
322+
if (status != WebCryptoCipherStatus::OK)
323323
return status;
324324

325325
// Wrap the counter around to zero
@@ -336,7 +336,7 @@ WebCryptoCipherStatus AES_CTR_Cipher(
336336
new_counter_block.data(),
337337
ptr + input_size_part1);
338338

339-
if (status == WebCryptoCipherStatus::ERR_OK)
339+
if (status == WebCryptoCipherStatus::OK)
340340
*out = std::move(buf);
341341

342342
return status;

src/crypto/crypto_cipher.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ enum WebCryptoCipherMode {
128128
};
129129

130130
enum class WebCryptoCipherStatus {
131-
ERR_OK,
132-
ERR_INVALID_KEY_TYPE,
133-
ERR_FAILED
131+
OK,
132+
INVALID_KEY_TYPE,
133+
FAILED
134134
};
135135

136136
// CipherJob is a base implementation class for implementations of
@@ -222,13 +222,13 @@ class CipherJob final : public CryptoJob<CipherTraits> {
222222
*CryptoJob<CipherTraits>::params(),
223223
in_,
224224
&out_)) {
225-
case WebCryptoCipherStatus::ERR_OK:
225+
case WebCryptoCipherStatus::OK:
226226
// Success!
227227
break;
228-
case WebCryptoCipherStatus::ERR_INVALID_KEY_TYPE:
228+
case WebCryptoCipherStatus::INVALID_KEY_TYPE:
229229
// Fall through
230230
// TODO(@jasnell): Separate error for this
231-
case WebCryptoCipherStatus::ERR_FAILED: {
231+
case WebCryptoCipherStatus::FAILED: {
232232
CryptoErrorVector* errors = CryptoJob<CipherTraits>::errors();
233233
errors->Capture();
234234
if (errors->empty())

src/crypto/crypto_keygen.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ KeyGenJobStatus SecretKeyGenTraits::DoKeyGen(
8484
CHECK_LE(params->length, INT_MAX);
8585
params->out = MallocOpenSSL<char>(params->length);
8686
EntropySource(reinterpret_cast<unsigned char*>(params->out), params->length);
87-
return KeyGenJobStatus::ERR_OK;
87+
return KeyGenJobStatus::OK;
8888
}
8989

9090
Maybe<bool> SecretKeyGenTraits::EncodeKey(

src/crypto/crypto_keygen.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ void Initialize(Environment* env, v8::Local<v8::Object> target);
1919
} // namespace Keygen
2020

2121
enum class KeyGenJobStatus {
22-
ERR_OK,
23-
ERR_FAILED
22+
OK,
23+
FAILED
2424
};
2525

2626
// A Base CryptoJob for generating secret keys or key pairs.
@@ -77,11 +77,11 @@ class KeyGenJob final : public CryptoJob<KeyGenTraits> {
7777
AdditionalParams* params = CryptoJob<KeyGenTraits>::params();
7878

7979
switch (KeyGenTraits::DoKeyGen(AsyncWrap::env(), params)) {
80-
case KeyGenJobStatus::ERR_OK:
81-
status_ = KeyGenJobStatus::ERR_OK;
80+
case KeyGenJobStatus::OK:
81+
status_ = KeyGenJobStatus::OK;
8282
// Success!
8383
break;
84-
case KeyGenJobStatus::ERR_FAILED: {
84+
case KeyGenJobStatus::FAILED: {
8585
CryptoErrorVector* errors = CryptoJob<KeyGenTraits>::errors();
8686
errors->Capture();
8787
if (errors->empty())
@@ -96,7 +96,7 @@ class KeyGenJob final : public CryptoJob<KeyGenTraits> {
9696
Environment* env = AsyncWrap::env();
9797
CryptoErrorVector* errors = CryptoJob<KeyGenTraits>::errors();
9898
AdditionalParams* params = CryptoJob<KeyGenTraits>::params();
99-
if (status_ == KeyGenJobStatus::ERR_OK &&
99+
if (status_ == KeyGenJobStatus::OK &&
100100
LIKELY(!KeyGenTraits::EncodeKey(env, params, result).IsNothing())) {
101101
*err = Undefined(env->isolate());
102102
return v8::Just(true);
@@ -112,7 +112,7 @@ class KeyGenJob final : public CryptoJob<KeyGenTraits> {
112112
SET_SELF_SIZE(KeyGenJob);
113113

114114
private:
115-
KeyGenJobStatus status_ = KeyGenJobStatus::ERR_FAILED;
115+
KeyGenJobStatus status_ = KeyGenJobStatus::FAILED;
116116
};
117117

118118
// A Base KeyGenTraits for Key Pair generation algorithms.
@@ -162,15 +162,15 @@ struct KeyPairGenTraits final {
162162
AdditionalParameters* params) {
163163
EVPKeyCtxPointer ctx = KeyPairAlgorithmTraits::Setup(params);
164164
if (!ctx || EVP_PKEY_keygen_init(ctx.get()) <= 0)
165-
return KeyGenJobStatus::ERR_FAILED;
165+
return KeyGenJobStatus::FAILED;
166166

167167
// Generate the key
168168
EVP_PKEY* pkey = nullptr;
169169
if (!EVP_PKEY_keygen(ctx.get(), &pkey))
170-
return KeyGenJobStatus::ERR_FAILED;
170+
return KeyGenJobStatus::FAILED;
171171

172172
params->key = ManagedEVPPKey(EVPKeyPointer(pkey));
173-
return KeyGenJobStatus::ERR_OK;
173+
return KeyGenJobStatus::OK;
174174
}
175175

176176
static v8::Maybe<bool> EncodeKey(

src/crypto/crypto_rsa.cc

+8-8
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,16 @@ WebCryptoCipherStatus RSA_Cipher(
196196
EVP_PKEY_CTX_new(key_data->GetAsymmetricKey().get(), nullptr));
197197

198198
if (!ctx || init(ctx.get()) <= 0)
199-
return WebCryptoCipherStatus::ERR_FAILED;
199+
return WebCryptoCipherStatus::FAILED;
200200

201201
if (EVP_PKEY_CTX_set_rsa_padding(ctx.get(), params.padding) <= 0) {
202-
return WebCryptoCipherStatus::ERR_FAILED;
202+
return WebCryptoCipherStatus::FAILED;
203203
}
204204

205205
if (params.digest != nullptr &&
206206
(EVP_PKEY_CTX_set_rsa_oaep_md(ctx.get(), params.digest) <= 0 ||
207207
EVP_PKEY_CTX_set_rsa_mgf1_md(ctx.get(), params.digest) <= 0)) {
208-
return WebCryptoCipherStatus::ERR_FAILED;
208+
return WebCryptoCipherStatus::FAILED;
209209
}
210210

211211
size_t label_len = params.label.size();
@@ -214,7 +214,7 @@ WebCryptoCipherStatus RSA_Cipher(
214214
CHECK_NOT_NULL(label);
215215
if (EVP_PKEY_CTX_set0_rsa_oaep_label(ctx.get(), label, label_len) <= 0) {
216216
OPENSSL_free(label);
217-
return WebCryptoCipherStatus::ERR_FAILED;
217+
return WebCryptoCipherStatus::FAILED;
218218
}
219219
}
220220

@@ -225,7 +225,7 @@ WebCryptoCipherStatus RSA_Cipher(
225225
&out_len,
226226
in.data<unsigned char>(),
227227
in.size()) <= 0) {
228-
return WebCryptoCipherStatus::ERR_FAILED;
228+
return WebCryptoCipherStatus::FAILED;
229229
}
230230

231231
char* data = MallocOpenSSL<char>(out_len);
@@ -238,13 +238,13 @@ WebCryptoCipherStatus RSA_Cipher(
238238
&out_len,
239239
in.data<unsigned char>(),
240240
in.size()) <= 0) {
241-
return WebCryptoCipherStatus::ERR_FAILED;
241+
return WebCryptoCipherStatus::FAILED;
242242
}
243243

244244
buf.Resize(out_len);
245245

246246
*out = std::move(buf);
247-
return WebCryptoCipherStatus::ERR_OK;
247+
return WebCryptoCipherStatus::OK;
248248
}
249249
} // namespace
250250

@@ -356,7 +356,7 @@ WebCryptoCipherStatus RSACipherTraits::DoCipher(
356356
return RSA_Cipher<EVP_PKEY_decrypt_init, EVP_PKEY_decrypt>(
357357
env, key_data.get(), params, in, out);
358358
}
359-
return WebCryptoCipherStatus::ERR_FAILED;
359+
return WebCryptoCipherStatus::FAILED;
360360
}
361361

362362
Maybe<bool> ExportJWKRsaKey(

0 commit comments

Comments
 (0)