From 1df57c3de277ec683015eeea02f26455bfd5dc64 Mon Sep 17 00:00:00 2001 From: Saleem Rashid Date: Fri, 26 May 2017 17:35:28 +0100 Subject: [PATCH] tests: Add test_base32_rfc4648 --- test_check.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test_check.c b/test_check.c index 3cc675c4d..e814da204 100644 --- a/test_check.c +++ b/test_check.c @@ -37,6 +37,7 @@ #include "aes.h" #include "bignum.h" +#include "base32.h" #include "base58.h" #include "bip32.h" #include "bip39.h" @@ -498,6 +499,38 @@ START_TEST(test_bignum_format) { } END_TEST +// https://tools.ietf.org/html/rfc4648#section-10 +START_TEST(test_base32_rfc4648) +{ + static const struct { + const char *input; + const char *output; + } tests[] = { + { "", "" }, + { "f", "MY" }, + { "fo", "MZXQ" }, + { "foo", "MZXW6" }, + { "foob", "MZXW6YQ" }, + { "fooba", "MZXW6YTB" }, + { "foobar", "MZXW6YTBOI" }, + }; + + char buffer[64]; + + for (size_t i = 0; i < (sizeof(tests) / sizeof(*tests)); i++) { + const char *input = tests[i].input; + const char *output = tests[i].output; + + size_t inlen = strlen(input); + size_t outlen = base32_encoded_length(inlen); + ck_assert_int_eq(outlen, strlen(output)); + + base32_encode((uint8_t *) input, inlen, buffer, sizeof(buffer), BASE32_ALPHABET_RFC4648); + ck_assert_str_eq(buffer, output); + } +} +END_TEST + // from https://github.com/bitcoin/bitcoin/blob/master/src/test/data/base58_keys_valid.json START_TEST(test_base58) { @@ -3019,6 +3052,10 @@ Suite *test_suite(void) tcase_add_test(tc, test_bignum_format); suite_add_tcase(s, tc); + tc = tcase_create("base32"); + tcase_add_test(tc, test_base32_rfc4648); + suite_add_tcase(s, tc); + tc = tcase_create("base58"); tcase_add_test(tc, test_base58); suite_add_tcase(s, tc);