]>
Commit | Line | Data |
---|---|---|
1801bd7f JM |
1 | /* |
2 | * Base64 encoding/decoding (RFC1341) - test program | |
3 | * Copyright (c) 2005, Jouni Malinen <j@w1.fi> | |
4 | * | |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
1801bd7f JM |
7 | */ |
8 | ||
9 | #include "utils/includes.h" | |
10 | #include "utils/os.h" | |
11 | #include "utils/base64.h" | |
12 | ||
13 | int main(int argc, char *argv[]) | |
14 | { | |
15 | FILE *f; | |
16 | size_t len, elen; | |
17 | unsigned char *buf, *e; | |
18 | ||
19 | if (argc != 4) { | |
20 | printf("Usage: base64 <encode|decode> <in file> <out file>\n"); | |
21 | return -1; | |
22 | } | |
23 | ||
24 | buf = (unsigned char *) os_readfile(argv[2], &len); | |
25 | if (buf == NULL) | |
26 | return -1; | |
27 | ||
28 | if (strcmp(argv[1], "encode") == 0) | |
29 | e = base64_encode(buf, len, &elen); | |
30 | else | |
31 | e = base64_decode(buf, len, &elen); | |
32 | if (e == NULL) | |
33 | return -2; | |
34 | f = fopen(argv[3], "w"); | |
35 | if (f == NULL) | |
36 | return -3; | |
37 | fwrite(e, 1, elen, f); | |
38 | fclose(f); | |
39 | free(e); | |
40 | ||
41 | return 0; | |
42 | } |