Author | Jamozed <[email protected]> |
Date | 2021-02-19 09:46:54 |
Commit | 3f2ab85592d348aa136c54bc7e497a73ce06e614 |
Parent | 3e0d5cbec77132353e36774017fb7f993208a31e |
base32: Add base32 decoding tests
Diffstat
M | src/test/test_base32.c | | | 58 | +++++++++++++++++++++++++++++++++++++++++++--------------- |
1 files changed, 43 insertions, 15 deletions
diff --git a/src/test/test_base32.c b/src/test/test_base32.c index b49fd00..c7464b6 100644 --- a/src/test/test_base32.c +++ b/src/test/test_base32.c @@ -121,35 +121,63 @@ int main(void) { } { - uint8_t i[16] = "ZIWBBG2U2E======"; uint8_t o[10] = { 0 }; + uint8_t i[16] = "GEZDGNBVGY3TQOJQ"; uint8_t o[10] = { 0 }; + + b32decode(o, i, 8); + ASSERT("T021 DECODE STRING LENGTH 8", + !memcmp(o, "12345", 5)); + + b32decode(o, i, 16); + ASSERT("T022 DECODE STRING LENGTH 16", + !memcmp(o, "1234567890", 10)); + } + + { + uint8_t i[16] = "GEZDGNBVGY======"; uint8_t o[10] = { 0 }; b32decode(o, i, 10); - ASSERT("T021 DECODE STRING LENGTH 10", + ASSERT("T023 DECODE STRING LENGTH 10", !memcmp(o, "123456", 6)); - b32decode(o, i, 11); - ASSERT("T022 DECODE STRING LENGTH 10, 1 PADDING", + b32decode(o, i, 16); + ASSERT("T024 DECODE STRING LENGTH 10 PADDED", !memcmp(o, "123456", 6)); + } + + { + uint8_t i[16] = "GEZDGNBVGY3Q===="; uint8_t o[10] = { 0 }; b32decode(o, i, 12); - ASSERT("T023 DECODE STRING LENGTH 10, 2 PADDING", - !memcmp(o, "123456", 6)); + ASSERT("T025 DECODE STRING LENGTH 12", + !memcmp(o, "1234567", 7)); + + b32decode(o, i, 16); + ASSERT("T026 DECODE STRING LENGTH 12 PADDED", + !memcmp(o, "1234567", 7)); + } + + { + uint8_t i[16] = "GEZDGNBVGY3TQ==="; uint8_t o[10] = { 0 }; b32decode(o, i, 13); - ASSERT("T024 DECODE STRING LENGTH 10, 3 PADDING", - !memcmp(o, "123456", 6)); + ASSERT("T027 DECODE STRING LENGTH 13", + !memcmp(o, "12345678", 8)); - b32decode(o, i, 14); - ASSERT("T025 DECODE STRING LENGTH 10, 4 PADDING", - !memcmp(o, "123456", 6)); + b32decode(o, i, 16); + ASSERT("T028 DECODE STRING LENGTH 13 PADDED", + !memcmp(o, "12345678", 8)); + } + + { + uint8_t i[16] = "GEZDGNBVGY3TQOI="; uint8_t o[10] = { 0 }; b32decode(o, i, 15); - ASSERT("T026 DECODE STRING LENGTH 10, 5 PADDING", - !memcmp(o, "123456", 6)); + ASSERT("T029 DECODE STRING LENGTH 13", + !memcmp(o, "123456789", 9)); b32decode(o, i, 16); - ASSERT("T027 DECODE STRING LENGTH 10, 6 PADDING", - !memcmp(o, "123456", 6)); + ASSERT("T030 DECODE STRING LENGTH 13 PADDED", + !memcmp(o, "123456789", 9)); } printf("%d of %d tests passed\n", testspassed, testsrun);