1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 12:28:09 +00:00

tests: Add test_base32_rfc4648

This commit is contained in:
Saleem Rashid 2017-05-26 17:35:28 +01:00 committed by Pavol Rusnak
parent 5ae3f57255
commit 1df57c3de2

View File

@ -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);