Skip to content

Commit c37806d

Browse files
RaisinTenruyadorno
authored andcommitted
crypto: use macro map for NodeCryptoError
PR-URL: #37758 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent af7489c commit c37806d

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

src/crypto/crypto_util.h

+15-24
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,18 @@ void Decode(const v8::FunctionCallbackInfo<v8::Value>& args,
159159
}
160160
}
161161

162+
#define NODE_CRYPTO_ERROR_CODES_MAP(V) \
163+
V(CIPHER_JOB_FAILED, "Cipher job failed") \
164+
V(DERIVING_BITS_FAILED, "Deriving bits failed") \
165+
V(ENGINE_NOT_FOUND, "Engine \"%s\" was not found") \
166+
V(INVALID_KEY_TYPE, "Invalid key type") \
167+
V(KEY_GENERATION_JOB_FAILED, "Key generation job failed") \
168+
V(OK, "Ok") \
169+
162170
enum class NodeCryptoError {
163-
CIPHER_JOB_FAILED,
164-
DERIVING_BITS_FAILED,
165-
ENGINE_NOT_FOUND,
166-
INVALID_KEY_TYPE,
167-
KEY_GENERATION_JOB_FAILED,
168-
OK
171+
#define V(CODE, DESCRIPTION) CODE,
172+
NODE_CRYPTO_ERROR_CODES_MAP(V)
173+
#undef V
169174
};
170175

171176
// Utility struct used to harvest error information from openssl's error stack
@@ -194,24 +199,10 @@ template <typename... Args>
194199
void CryptoErrorStore::Insert(const NodeCryptoError error, Args&&... args) {
195200
const char* error_string = nullptr;
196201
switch (error) {
197-
case NodeCryptoError::CIPHER_JOB_FAILED:
198-
error_string = "Cipher job failed";
199-
break;
200-
case NodeCryptoError::DERIVING_BITS_FAILED:
201-
error_string = "Deriving bits failed";
202-
break;
203-
case NodeCryptoError::ENGINE_NOT_FOUND:
204-
error_string = "Engine \"%s\" was not found";
205-
break;
206-
case NodeCryptoError::INVALID_KEY_TYPE:
207-
error_string = "Invalid key type";
208-
break;
209-
case NodeCryptoError::KEY_GENERATION_JOB_FAILED:
210-
error_string = "Key generation failed";
211-
break;
212-
case NodeCryptoError::OK:
213-
error_string = "Ok";
214-
break;
202+
#define V(CODE, DESCRIPTION) \
203+
case NodeCryptoError::CODE: error_string = DESCRIPTION; break;
204+
NODE_CRYPTO_ERROR_CODES_MAP(V)
205+
#undef V
215206
}
216207
errors_.emplace_back(SPrintF(error_string,
217208
std::forward<Args>(args)...));

0 commit comments

Comments
 (0)