diff options
author | Vincent Sanders <vince@kyllikki.org> | 2014-11-18 16:15:56 +0000 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2014-11-18 16:15:56 +0000 |
commit | 257deb32c83dbdd989d2021cdbd5ad7dbb28386f (patch) | |
tree | 2a29e2222196f351e62e1316ddaeefcb405fbb1a /test/base64.c | |
download | libnsutils-257deb32c83dbdd989d2021cdbd5ad7dbb28386f.tar.gz libnsutils-257deb32c83dbdd989d2021cdbd5ad7dbb28386f.tar.bz2 |
Initial nsutils library with base64 implementation an tests
Diffstat (limited to 'test/base64.c')
-rw-r--r-- | test/base64.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/base64.c b/test/base64.c new file mode 100644 index 0000000..f86e65e --- /dev/null +++ b/test/base64.c @@ -0,0 +1,48 @@ +/* + * Copyright 2014 Vincent Sanders <vince@netsurf-browser.org> + * + * This file is part of libnsutils. + * + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + */ + +/** + * \file + * + * Base64 test program. Reads data from stdin and en/de codes it to/from base64 + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> + +#include <nsutils/base64.h> + +int main(int argc, char**argv) +{ + uint8_t *buffer; + size_t buffer_len; + uint8_t *output; + size_t output_len; + + if (scanf("%1024mc%n", &buffer, (int *)&buffer_len) < 1) { + return 1; + } + + if (argc == 1) { + /* encode */ + base64_encode_alloc(buffer, buffer_len, &output, &output_len); + } else { + /* decode */ + base64_decode_alloc(buffer, buffer_len, &output, &output_len); + } + + if (output != NULL) { + printf("%.*s", (int)output_len, output); + free(output); + } + + free(buffer); + +} |