]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/test-base64.c
EAP-SIM/EAP-AKA peer: Support realms according to 3GPP TS 23.003
[thirdparty/hostap.git] / tests / test-base64.c
1 /*
2 * Base64 encoding/decoding (RFC1341) - test program
3 * Copyright (c) 2005, Jouni Malinen <j@w1.fi>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
11 *
12 * See README and COPYING for more details.
13 */
14
15 #include "utils/includes.h"
16 #include "utils/os.h"
17 #include "utils/base64.h"
18
19 int main(int argc, char *argv[])
20 {
21 FILE *f;
22 size_t len, elen;
23 unsigned char *buf, *e;
24
25 if (argc != 4) {
26 printf("Usage: base64 <encode|decode> <in file> <out file>\n");
27 return -1;
28 }
29
30 buf = (unsigned char *) os_readfile(argv[2], &len);
31 if (buf == NULL)
32 return -1;
33
34 if (strcmp(argv[1], "encode") == 0)
35 e = base64_encode(buf, len, &elen);
36 else
37 e = base64_decode(buf, len, &elen);
38 if (e == NULL)
39 return -2;
40 f = fopen(argv[3], "w");
41 if (f == NULL)
42 return -3;
43 fwrite(e, 1, elen, f);
44 fclose(f);
45 free(e);
46
47 return 0;
48 }