nl80211: Fix a typo
[hostap-gosc2009.git] / tests / test-base64.c
blob747290e74a7d9a271ba0e89c0b3ad1d513bd15be
1 /*
2 * Base64 encoding/decoding (RFC1341) - test program
3 * Copyright (c) 2005, Jouni Malinen <j@w1.fi>
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.
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
16 #include "utils/os.h"
17 #include "utils/base64.h"
19 int main(int argc, char *argv[])
21 FILE *f;
22 size_t len, elen;
23 unsigned char *buf, *e;
25 if (argc != 4) {
26 printf("Usage: base64 <encode|decode> <in file> <out file>\n");
27 return -1;
30 buf = (unsigned char *) os_readfile(argv[2], &len);
31 if (buf == NULL)
32 return -1;
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);
47 return 0;