feat(deps): UA_base64_buf encodes into an existing buffer

This commit is contained in:
Julius Pfrommer 2022-08-14 21:32:13 +02:00 committed by Julius Pfrommer
parent 8716d24f74
commit 88adf5c673
2 changed files with 12 additions and 2 deletions

9
deps/base64.c vendored
View File

@ -28,6 +28,12 @@ UA_base64(const unsigned char *src, size_t len, size_t *out_len) {
if(!out)
return NULL;
*out_len = UA_base64_buf(src, len, out);
return out;
}
size_t
UA_base64_buf(const unsigned char *src, size_t len, unsigned char *out) {
const unsigned char *end = src + len;
const unsigned char *in = src;
unsigned char *pos = out;
@ -51,8 +57,7 @@ UA_base64(const unsigned char *src, size_t len, size_t *out_len) {
*pos++ = '=';
}
*out_len = (size_t)(pos - out);
return out;
return (size_t)(pos - out);
}
static const uint32_t from_b64[256] = {

5
deps/base64.h vendored
View File

@ -17,6 +17,11 @@ _UA_BEGIN_DECLS
unsigned char *
UA_base64(const unsigned char *src, size_t len, size_t *out_len);
/* Requires as input a buffer of length at least 4*((len + 2) / 3).
* Returns the actual size */
size_t
UA_base64_buf(const unsigned char *src, size_t len, unsigned char *out);
/**
* base64_decode - Base64 decode
* @src: Data to be decoded