[api] Add zero-copy support for noise encryption key requests (#12405)

This commit is contained in:
J. Nick Koston authored and GitHub committed 2025-12-20 06:47:30 -10:00
1 parent 64269334ce
commit 40eb898814
7 files changed
+21 -12

No files matched your search

+8 -4
View File
@@ -479,10 +479,14 @@ std::string base64_encode(const uint8_t *buf, size_t buf_len) {
}
size_t base64_decode(const std::string &encoded_string, uint8_t *buf, size_t buf_len) {
int in_len = encoded_string.size();
return base64_decode(reinterpret_cast<const uint8_t *>(encoded_string.data()), encoded_string.size(), buf, buf_len);
}
size_t base64_decode(const uint8_t *encoded_data, size_t encoded_len, uint8_t *buf, size_t buf_len) {
size_t in_len = encoded_len;
int i = 0;
int j = 0;
int in = 0;
size_t in = 0;
size_t out = 0;
uint8_t char_array_4[4], char_array_3[3];
bool truncated = false;
@@ -490,8 +494,8 @@ size_t base64_decode(const std::string &encoded_string, uint8_t *buf, size_t buf
// SAFETY: The loop condition checks is_base64() before processing each character.
// This ensures base64_find_char() is only called on valid base64 characters,
// preventing the edge case where invalid chars would return 0 (same as 'A').
while (in_len-- && (encoded_string[in] != '=') && is_base64(encoded_string[in])) {
char_array_4[i++] = encoded_string[in];
while (in_len-- && (encoded_data[in] != '=') && is_base64(encoded_data[in])) {
char_array_4[i++] = encoded_data[in];
in++;
if (i == 4) {
for (i = 0; i < 4; i++)