Fix compilation for compilers lacking std::to_array

This commit is contained in:
blankie 2023-12-08 22:52:06 +11:00
parent 9b718459d1
commit 4d874d2a05
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 5 additions and 2 deletions

View File

@ -1,3 +1,4 @@
#include <cstring>
#include <stdexcept> #include <stdexcept>
#include <openssl/hmac.h> #include <openssl/hmac.h>
@ -18,7 +19,7 @@ std::vector<char> secure_random_bytes(int num) {
} }
std::array<char, 32> hmac_sha3_256(const std::vector<char>& key, const std::vector<char>& data) { std::array<char, 32> hmac_sha3_256(const std::vector<char>& key, const std::vector<char>& data) {
char hmac[32]; char hmac[EVP_MAX_MD_SIZE];
unsigned int md_len; unsigned int md_len;
if (HMAC(EVP_sha3_256(), key.data(), static_cast<int>(key.size()), reinterpret_cast<const unsigned char*>(data.data()), data.size(), reinterpret_cast<unsigned char*>(hmac), &md_len)) { if (HMAC(EVP_sha3_256(), key.data(), static_cast<int>(key.size()), reinterpret_cast<const unsigned char*>(data.data()), data.size(), reinterpret_cast<unsigned char*>(hmac), &md_len)) {
@ -26,7 +27,9 @@ std::array<char, 32> hmac_sha3_256(const std::vector<char>& key, const std::vect
throw std::runtime_error("hmac_sha3_256(): HMAC() returned an unexpected size"); throw std::runtime_error("hmac_sha3_256(): HMAC() returned an unexpected size");
} }
return std::to_array(hmac); std::array<char, 32> ret;
memcpy(ret.data(), hmac, 32);
return ret;
} else { } else {
throw OpenSSLException(ERR_get_error()); throw OpenSSLException(ERR_get_error());
} }