2 * Copyright (c) 2013 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27 #endif /* STDC_HEADERS */
29 # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
33 #endif /* HAVE_STRING_H */
36 #endif /* HAVE_STRINGS_H */
37 #if defined(HAVE_STDINT_H)
39 #elif defined(HAVE_INTTYPES_H)
40 # include <inttypes.h>
43 #define SUDO_ERROR_WRAP 0
47 extern size_t base64_decode(const char *str, unsigned char *dst, size_t dsize);
49 __dso_public int main(int argc, char *argv[]);
56 "any carnal pleasure.",
57 "YW55IGNhcm5hbCBwbGVhc3VyZS4="
60 "any carnal pleasure",
61 "YW55IGNhcm5hbCBwbGVhc3VyZQ=="
65 "YW55IGNhcm5hbCBwbGVhc3Vy"
69 "YW55IGNhcm5hbCBwbGVhc3U="
73 "YW55IGNhcm5hbCBwbGVhcw=="
78 main(int argc, char *argv[])
80 const int ntests = (sizeof(test_strings) / sizeof(test_strings[0]));
85 for (i = 0; i < ntests; i++) {
86 len = base64_decode(test_strings[i].encoded, buf, sizeof(buf));
88 if (strcmp(test_strings[i].ascii, buf) != 0) {
89 fprintf(stderr, "check_base64: expected %s, got %s",
90 test_strings[i].ascii, buf);
94 printf("check_base64: %d tests run, %d errors, %d%% success rate\n",
95 ntests, errors, (ntests - errors) * 100 / ntests);