]> www.average.org Git - pam_pcsc_cr.git/blob - test_base64.c
replace README_CR with svg pic
[pam_pcsc_cr.git] / test_base64.c
1 /*
2 Copyright (c) 2013 Eugene Crosser
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12     1. The origin of this software must not be misrepresented; you must
13     not claim that you wrote the original software. If you use this
14     software in a product, an acknowledgment in the product documentation
15     would be appreciated but is not required.
16
17     2. Altered source versions must be plainly marked as such, and must
18     not be misrepresented as being the original software.
19
20     3. This notice may not be removed or altered from any source
21     distribution.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include "base64.h"
32
33 static unsigned char src[40] = "Quick brown fox jumps over the lazy dog";
34
35 int main(int argc, char *argv[])
36 {
37         char b64[80];
38         unsigned char dst[44];
39         int bsize, dsize;
40
41         printf("src=\"%s\" (%d)\n", src, (int)sizeof(src));
42         bsize = sizeof(b64);
43         if (b64_encode(src, sizeof(src), b64, &bsize)) {
44                 fprintf(stderr, "encode error\n");
45                 return 1;
46         }
47         printf("b64=\"%s\" (%d)\n", b64, bsize);
48         dsize = sizeof(dst);
49         if (b64_decode(b64, dst, &dsize)) {
50                 fprintf(stderr, "decode error\n");
51                 return 1;
52         }
53         printf("dst=\"%s\" (%d)\n", dst, dsize);
54         return !(dsize == sizeof(src) && !memcmp(src, dst, dsize));
55 }