aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test-base64.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2009-12-05 18:43:07 (GMT)
committerJouni Malinen <j@w1.fi>2009-12-05 18:43:07 (GMT)
commit1801bd7faee0339e9cbf33336bd55ec649a54755 (patch)
tree84aca3988e4e8fb60a37c9313654d432b80bc897 /tests/test-base64.c
parenta486c0c72a2856161f421e1d4c98e424508be18e (diff)
downloadhostap-1801bd7faee0339e9cbf33336bd55ec649a54755.zip
hostap-1801bd7faee0339e9cbf33336bd55ec649a54755.tar.gz
hostap-1801bd7faee0339e9cbf33336bd55ec649a54755.tar.bz2
Move base64 test code into a new tests subdirectory
Diffstat (limited to 'tests/test-base64.c')
-rw-r--r--tests/test-base64.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test-base64.c b/tests/test-base64.c
new file mode 100644
index 0000000..747290e
--- /dev/null
+++ b/tests/test-base64.c
@@ -0,0 +1,48 @@
+/*
+ * Base64 encoding/decoding (RFC1341) - test program
+ * Copyright (c) 2005, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+#include "utils/os.h"
+#include "utils/base64.h"
+
+int main(int argc, char *argv[])
+{
+ FILE *f;
+ size_t len, elen;
+ unsigned char *buf, *e;
+
+ if (argc != 4) {
+ printf("Usage: base64 <encode|decode> <in file> <out file>\n");
+ return -1;
+ }
+
+ buf = (unsigned char *) os_readfile(argv[2], &len);
+ if (buf == NULL)
+ return -1;
+
+ if (strcmp(argv[1], "encode") == 0)
+ e = base64_encode(buf, len, &elen);
+ else
+ e = base64_decode(buf, len, &elen);
+ if (e == NULL)
+ return -2;
+ f = fopen(argv[3], "w");
+ if (f == NULL)
+ return -3;
+ fwrite(e, 1, elen, f);
+ fclose(f);
+ free(e);
+
+ return 0;
+}