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>2020-10-27 13:13:58 +0100
commit085e63e53502adfc16c3830ed6b0b941314b8f8a (patch)
tree509a1b7b5ee85e9e6d3a409e25029f9062fe29fb /src/base64.c
parent9e5fa742b6ef66a546c0a77c14f834f2268c5f71 (diff)
downloadserd-085e63e53502adfc16c3830ed6b0b941314b8f8a.tar.gz
serd-085e63e53502adfc16c3830ed6b0b941314b8f8a.tar.bz2
serd-085e63e53502adfc16c3830ed6b0b941314b8f8a.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.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/base64.c b/src/base64.c
index 763c2d2e..884d0a48 100644
--- a/src/base64.c
+++ b/src/base64.c
@@ -71,7 +71,7 @@ serd_base64_encode(uint8_t* const str,
const size_t size,
const bool wrap_lines)
{
- bool has_newline = false;
+ 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);
@@ -105,16 +105,18 @@ decode_chunk(const uint8_t in[4], uint8_t out[3])
}
void*
-serd_base64_decode(const uint8_t* str, size_t len, size_t* size)
+serd_base64_decode(const char* str, size_t len, size_t* size)
{
+ const uint8_t* const ustr = (const uint8_t*)str;
+
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);