21 static std::vector<uint8_t>
raw_from_b64(
const std::string_view& b64_string)
23 const auto data =
reinterpret_cast<const uint8_t*
>(b64_string.data());
24 const auto size = b64_string.size();
39 int max_size = EVP_DECODE_LENGTH(size);
40 unsigned char output[max_size];
41 memset(output,
'\0', max_size);
45 int rc = EVP_DecodeUpdate(ctx, output, &chunk_len, data, size);
49 throw std::invalid_argument(fmt::format(
50 "OSSL: Could not decode update from base64 string: {} [{} bytes out "
51 "of {}, chunk_len = {}]",
57 encoded_len = chunk_len;
59 rc = EVP_DecodeFinal(ctx, output + chunk_len, &chunk_len);
63 throw std::logic_error(fmt::format(
64 "OSSL: Could not decode final from base64 string: {} [{} bytes out "
65 "of {}, chunk_len = {}]",
71 encoded_len += chunk_len;
73 std::vector<uint8_t> ret(output, output + encoded_len);
93 int max_size = EVP_ENCODE_LENGTH(size);
94 unsigned char output[max_size];
95 memset(output,
'\0', max_size);
99 int rc = EVP_EncodeUpdate(ctx, output, &chunk_len, data, size);
103 throw std::logic_error(fmt::format(
104 "OSSL: Could not encode update to base64 string: {} [{} bytes out of "
105 "{}, chunk_len = {}]",
113 EVP_EncodeFinal(ctx, output + chunk_len, &chunk_len);
114 auto err = ERR_get_error();
118 throw std::logic_error(fmt::format(
119 "OSSL: Could not encode final to base64 string: {} [{} bytes out of "
120 "{}, chunk_len = {}]",
128 std::string ret = (
const char*)output;
130 ret.erase(std::remove(ret.begin(), ret.end(),
'\n'), ret.end());