diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-11-03 21:34:45 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-11-03 21:35:28 +0100 |
commit | fd81692f4b51d1f7f8914acbe79595f6dfa460f5 (patch) | |
tree | d25235420ff5e65aced1a5a3d6fff02e604d2e61 /src/test | |
parent | hexdecoct: implicitly parse URL-safe base64 format, too (diff) | |
download | systemd-fd81692f4b51d1f7f8914acbe79595f6dfa460f5.tar.xz systemd-fd81692f4b51d1f7f8914acbe79595f6dfa460f5.zip |
test: add test for the combined base64/base64url decoder
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-hexdecoct.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/test/test-hexdecoct.c b/src/test/test-hexdecoct.c index 9d71db6ae1..f884008660 100644 --- a/src/test/test-hexdecoct.c +++ b/src/test/test-hexdecoct.c @@ -516,4 +516,33 @@ TEST(hexdump) { hexdump(stdout, data, sizeof(data)); } +TEST(base64withwithouturl) { + static const uint8_t plaintext[] = { + 0xcc, 0xa1, 0x72, 0x22, 0xae, 0xda, 0x66, 0x7e, 0x04, 0xa6, 0xe0, 0x82, + 0x9a, 0x97, 0x05, 0xf6, 0x33, 0xe0, 0x0f, 0xc2, 0x45, 0x13, 0x58, 0x3f, + 0xc5, 0xf4, 0xf4, 0x31, 0xab, 0x3c, 0x5f, 0x83, 0x34, 0x5b, 0x27, 0x32, + 0x8a, 0x04, 0x6c, 0x43, 0x82, 0x07, 0xe3, 0x2c, 0xac, 0xb9, 0xfb, 0xac, + 0xd0, 0x03, 0x91, 0x42, 0xcb, 0xa4, 0xde, 0x87, 0x86, 0x85, 0x10, 0xbb, + 0xb7, 0x5b, 0x4b, 0xc8, 0xa0, 0xf4, 0x22, 0x1d, 0x15, 0x71, 0x87, 0x9d, + 0xbf, 0x9f, 0xa9, 0xf1, 0xee, 0xa2, 0xb6, 0xaa, 0xc8, 0xc3, 0x37, 0x9c, + 0xbb, 0xdf, 0x3e, 0xac, 0xdc, 0x94, 0x54, 0x38, 0x56, 0x07, 0x34, 0xb4, + 0x3c, 0xcc, 0x31, 0x13 + }; + + _cleanup_free_ void *buffer = NULL; + size_t size; + + /* This is regular base64 */ + assert_se(unbase64mem("zKFyIq7aZn4EpuCCmpcF9jPgD8JFE1g/xfT0Mas8X4M0WycyigRsQ4IH4yysufus0AORQsuk3oeGhRC7t1tLyKD0Ih0VcYedv5+p8e6itqrIwzecu98+rNyUVDhWBzS0PMwxEw==", SIZE_MAX, &buffer, &size) >= 0); + assert_se(memcmp_nn(plaintext, sizeof(plaintext), buffer, size) == 0); + buffer = mfree(buffer); + + /* This is the same but in base64url */ + assert_se(unbase64mem("zKFyIq7aZn4EpuCCmpcF9jPgD8JFE1g_xfT0Mas8X4M0WycyigRsQ4IH4yysufus0AORQsuk3oeGhRC7t1tLyKD0Ih0VcYedv5-p8e6itqrIwzecu98-rNyUVDhWBzS0PMwxEw==", SIZE_MAX, &buffer, &size) >= 0); + assert_se(memcmp_nn(plaintext, sizeof(plaintext), buffer, size) == 0); + + /* Hint: use xxd -i to generate the static C array from some data, and basenc --base64 + basenc + * --base64url to generate the correctly encoded base64 strings */ +} + DEFINE_TEST_MAIN(LOG_INFO); |