From 84bab08585dec858807a6130bd2d71f304b889f0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 16 Mar 2016 16:21:20 -0400 Subject: Use char* for strings in public API The constant casting just makes user code a mess, for no benefit. --- src/base64.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'src/base64.c') 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; } -- cgit v1.2.1