Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions common/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ char *b64_encode(const tal_t *ctx, const void *data, size_t len)
str[enclen] = '\0';
return str;
}

u8 *b64_decode(const tal_t *ctx, const char *str, size_t len)
{
size_t dlen = base64_decoded_length(len);
u8 *ret = tal_arr(ctx, u8, dlen);
if (base64_decode((char *)ret, dlen, str, len) < 0)
return tal_free(ret);
return ret;
}
1 change: 1 addition & 0 deletions common/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
#include <ccan/tal/tal.h>

char *b64_encode(const tal_t *ctx, const void *data, size_t len);
u8 *b64_decode(const tal_t *ctx, const char *str, size_t len);

#endif /* LIGHTNING_COMMON_BASE64_H */
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/fuzz/fuzz-base32-64.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ void run(const uint8_t *data, size_t size)
tal_free(decoded);

encoded = b64_encode(NULL, data, size);
decoded = b64_decode(NULL, encoded, strlen(encoded));
assert(memcmp(decoded, data, size) == 0);
tal_free(encoded);
tal_free(decoded);
}