mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Switched to binary pubkeys from base64 for internal user data (#29)
* String copy optmisations. * User pubkey binary.
This commit is contained in:
11
src/util.cpp
11
src/util.cpp
@@ -17,21 +17,20 @@ int base64_encode(std::string &encoded_string, const unsigned char *bin, size_t
|
||||
{
|
||||
// Get length of encoded result from sodium.
|
||||
const size_t base64_len = sodium_base64_encoded_len(bin_len, sodium_base64_VARIANT_ORIGINAL);
|
||||
char base64chars[base64_len];
|
||||
|
||||
// "base64_len - 1" because sodium include '\0' in the calculated base64 length.
|
||||
// Therefore we need to omit it when initializing the std::string.
|
||||
encoded_string.resize(base64_len - 1);
|
||||
|
||||
// Get encoded string.
|
||||
const char *encoded_str_char = sodium_bin2base64(
|
||||
base64chars, base64_len,
|
||||
encoded_string.data(), base64_len,
|
||||
bin, bin_len,
|
||||
sodium_base64_VARIANT_ORIGINAL);
|
||||
|
||||
if (encoded_str_char == NULL)
|
||||
return -1;
|
||||
|
||||
// Assign the encoded char* onto the provided string reference.
|
||||
// "base64_len - 1" because sodium include '\0' in the calculated base64 length.
|
||||
// Therefore we need to omit it when initializing the std::string.
|
||||
encoded_string = std::string(base64chars, base64_len - 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user