From 5d987f2dec8d4d292021945a61c69c09264f031e Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Thu, 10 Sep 2020 18:19:58 +0200 Subject: [PATCH] fuzz: add a target for base32/64 encoding Signed-off-by: Antoine Poinsot --- tests/fuzz/Makefile | 1 + tests/fuzz/fuzz-base32-64.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/fuzz/fuzz-base32-64.c diff --git a/tests/fuzz/Makefile b/tests/fuzz/Makefile index 1cef8eebd..922c1ee54 100644 --- a/tests/fuzz/Makefile +++ b/tests/fuzz/Makefile @@ -11,6 +11,7 @@ FUZZ_COMMON_OBJS := \ common/amount.o \ common/addr.o \ common/base32.o \ + common/base64.o \ common/bech32.o \ common/bigsize.o \ common/json.o \ diff --git a/tests/fuzz/fuzz-base32-64.c b/tests/fuzz/fuzz-base32-64.c new file mode 100644 index 000000000..fe19a781d --- /dev/null +++ b/tests/fuzz/fuzz-base32-64.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +#include +#include + +void init(int *argc, char ***argv) +{ +} + +void run(const uint8_t *data, size_t size) +{ + char *encoded; + uint8_t *decoded; + + encoded = b32_encode(NULL, data, size); + decoded = b32_decode(NULL, encoded, strlen(encoded)); + assert(memcmp(decoded, data, size) == 0); + tal_free(encoded); + tal_free(decoded); + + encoded = b64_encode(NULL, data, size); + tal_free(encoded); +}