]> www.average.org Git - pam_pcsc_cr.git/blobdiff - test_base64.c
include base64 encoder
[pam_pcsc_cr.git] / test_base64.c
diff --git a/test_base64.c b/test_base64.c
new file mode 100644 (file)
index 0000000..83fbf57
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+Copyright (c) 2013 Eugene Crosser
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+    1. The origin of this software must not be misrepresented; you must
+    not claim that you wrote the original software. If you use this
+    software in a product, an acknowledgment in the product documentation
+    would be appreciated but is not required.
+
+    2. Altered source versions must be plainly marked as such, and must
+    not be misrepresented as being the original software.
+
+    3. This notice may not be removed or altered from any source
+    distribution.
+*/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include "base64.h"
+
+static char src[40] = "Quick brown fox jumps over the lazy dog";
+
+int main(int argc, char *argv[])
+{
+       char b64[80];
+       char dst[40];
+       int bsize, dsize;
+
+       printf("src=\"%s\" (%d)\n", src, (int)sizeof(src));
+       bsize = sizeof(b64);
+       if (b64_encode(src, sizeof(src), b64, &bsize)) {
+               fprintf(stderr, "encode error\n");
+               return 1;
+       }
+       printf("b64=\"%s\" (%d)\n", b64, bsize);
+       dsize = sizeof(dst);
+       if (b64_decode(b64, dst, &dsize)) {
+               fprintf(stderr, "decode error\n");
+               return 1;
+       }
+       printf("dst=\"%s\" (%d)\n", dst, dsize);
+       return !(dsize == sizeof(src) && !memcmp(src, dst, dsize));
+}