aboutsummaryrefslogtreecommitdiffstats
path: root/src/base64.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-03-16 16:21:20 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 16:27:02 -0500
commit84bab08585dec858807a6130bd2d71f304b889f0 (patch)
treeea78338414095c2c871944a0135028e1399b12fe /src/base64.c
parentcaa74939cba8b1cd357e553efca9bec5074b1c53 (diff)
downloadserd-84bab08585dec858807a6130bd2d71f304b889f0.tar.gz
serd-84bab08585dec858807a6130bd2d71f304b889f0.tar.bz2
serd-84bab08585dec858807a6130bd2d71f304b889f0.zip
Use char* for strings in public API
The constant casting just makes user code a mess, for no benefit.
Diffstat (limited to 'src/base64.c')
-rw-r--r--src/base64.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/base64.c b/src/base64.c
index ce8fe74d..13f08ab0 100644
--- a/src/base64.c
+++ b/src/base64.c
@@ -60,7 +60,6 @@ serd_base64_encode(uint8_t* const str,
const bool wrap_lines)
{
bool has_newline = false;
-
for (size_t i = 0, j = 0; i < size; i += 3, j += 4) {
uint8_t in[4] = {0, 0, 0, 0};
size_t n_in = MIN(3, size - i);
@@ -94,28 +93,23 @@ decode_chunk(const uint8_t in[4], uint8_t out[3])
}
void*
-serd_base64_decode(const uint8_t* const str,
- const size_t len,
- size_t* const size)
+serd_base64_decode(const char* const str, const size_t len, size_t* const size)
{
- void* buf = malloc((len * 3) / 4 + 2);
+ const uint8_t* const ustr = (const uint8_t*)str;
- *size = 0;
+ void* buf = malloc((len * 3) / 4 + 2);
+ *size = 0;
for (size_t i = 0, j = 0; i < len; j += 3) {
uint8_t in[] = "====";
size_t n_in = 0;
for (; i < len && n_in < 4; ++n_in) {
- for (; i < len && !is_base64(str[i]); ++i) {
- // Skip junk
- }
-
- in[n_in] = str[i++];
+ for (; i < len && !is_base64(ustr[i]); ++i) {
+ } // Skip junk
+ in[n_in] = ustr[i++];
}
-
if (n_in > 1) {
*size += decode_chunk(in, (uint8_t*)buf + j);
}
}
-
return buf;
}