Skip to content

Commit

Permalink
define Insert in crypto_util.h itself
Browse files Browse the repository at this point in the history
  • Loading branch information
RaisinTen committed Mar 10, 2021
1 parent b995a71 commit 4ff9e88
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
27 changes: 0 additions & 27 deletions src/crypto/crypto_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,33 +201,6 @@ bool CryptoErrorStore::Empty() const {
return errors_.empty();
}

template<typename... Args>
void CryptoErrorStore::Insert(const NodeCryptoError error, Args&&... args) {
const char* error_string;
switch (error) {
case NodeCryptoError::CIPHER_JOB_FAILED:
error_string = "Cipher job failed";
break;
case NodeCryptoError::DERIVING_BITS_FAILED:
error_string = "Deriving bits failed";
break;
case NodeCryptoError::ENGINE_NOT_FOUND:
error_string = "Engine \"%s\" was not found";
break;
case NodeCryptoError::INVALID_KEY_TYPE:
error_string = "Invalid key type";
break;
case NodeCryptoError::KEY_GENERATION_JOB_FAILED:
error_string = "Key generation failed";
break;
case NodeCryptoError::NO_ERROR:
error_string = "No error";
break;
}
errors.emplace_back(SPrintF(error_string,
std::forward<Args>(args)...));
}

MaybeLocal<Value> CryptoErrorStore::ToException(
Environment* env,
Local<String> exception_string) const {
Expand Down
27 changes: 27 additions & 0 deletions src/crypto/crypto_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,33 @@ struct CryptoErrorStore {
std::vector<std::string> errors_;
};

template <typename... Args>
void CryptoErrorStore::Insert(const NodeCryptoError error, Args&&... args) {
const char* error_string;
switch (error) {
case NodeCryptoError::CIPHER_JOB_FAILED:
error_string = "Cipher job failed";
break;
case NodeCryptoError::DERIVING_BITS_FAILED:
error_string = "Deriving bits failed";
break;
case NodeCryptoError::ENGINE_NOT_FOUND:
error_string = "Engine \"%s\" was not found";
break;
case NodeCryptoError::INVALID_KEY_TYPE:
error_string = "Invalid key type";
break;
case NodeCryptoError::KEY_GENERATION_JOB_FAILED:
error_string = "Key generation failed";
break;
case NodeCryptoError::NO_ERROR:
error_string = "No error";
break;
}
errors_.emplace_back(SPrintF(error_string,
std::forward<Args>(args)...));
}

template <typename T>
T* MallocOpenSSL(size_t count) {
void* mem = OPENSSL_malloc(MultiplyWithOverflowCheck(count, sizeof(T)));
Expand Down

0 comments on commit 4ff9e88

Please sign in to comment.