diff --git a/base32.c b/base32.c index 1da7e63327..42675e5b5d 100644 --- a/base32.c +++ b/base32.c @@ -33,22 +33,22 @@ static inline void base32_8to5_raw(const uint8_t *in, uint8_t length, uint8_t *o static inline int base32_encode_character(uint8_t decoded, const char *alphabet); static inline int base32_decode_character(char encoded, const char *alphabet); -bool base32_encode(const uint8_t *in, size_t inlen, char *out, size_t outlen, const char *alphabet) { +char *base32_encode(const uint8_t *in, size_t inlen, char *out, size_t outlen, const char *alphabet) { size_t length = base32_encoded_length(inlen); if (outlen <= length) { - return false; + return NULL; } base32_encode_unsafe(in, inlen, (uint8_t *) out); for (size_t i = 0; i < length; i++) { if ((out[i] = base32_encode_character(out[i], alphabet)) == -1) { - return false; + return NULL; } } out[length] = '\0'; - return true; + return &out[length]; } uint8_t *base32_decode(const char *in, size_t inlen, uint8_t *out, size_t outlen, const char *alphabet) { diff --git a/base32.h b/base32.h index a4dcbc8da5..2509979673 100644 --- a/base32.h +++ b/base32.h @@ -29,7 +29,7 @@ extern const char *BASE32_ALPHABET_RFC4648; -bool base32_encode(const uint8_t *in, size_t inlen, char *out, size_t outlen, const char *alphabet); +char *base32_encode(const uint8_t *in, size_t inlen, char *out, size_t outlen, const char *alphabet); void base32_encode_unsafe(const uint8_t *in, size_t inlen, uint8_t *out); uint8_t *base32_decode(const char *in, size_t inlen, uint8_t *out, size_t outlen, const char *alphabet); diff --git a/test_check.c b/test_check.c index 4659460fae..78b97cd81c 100644 --- a/test_check.c +++ b/test_check.c @@ -527,11 +527,11 @@ START_TEST(test_base32_rfc4648) ck_assert_int_eq(outlen, base32_encoded_length(inlen)); ck_assert_int_eq(inlen, base32_decoded_length(outlen)); - ck_assert(base32_encode((uint8_t *) in, inlen, buffer, sizeof(buffer), BASE32_ALPHABET_RFC4648)); + ck_assert(base32_encode((uint8_t *) in, inlen, buffer, sizeof(buffer), BASE32_ALPHABET_RFC4648) != NULL); ck_assert_str_eq(buffer, out); char *ret = (char *) base32_decode(out, outlen, (uint8_t *) buffer, sizeof(buffer), BASE32_ALPHABET_RFC4648); - ck_assert(ret); + ck_assert(ret != NULL); *ret = '\0'; ck_assert_str_eq(buffer, in);