Annotation of embedaddon/sudo/plugins/sudoers/regress/parser/check_base64.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (c) 2013 Todd C. Miller <Todd.Miller@courtesan.com>
! 3: *
! 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.
! 7: *
! 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.
! 15: */
! 16:
! 17: #include <config.h>
! 18:
! 19: #include <stdio.h>
! 20: #ifdef STDC_HEADERS
! 21: # include <stdlib.h>
! 22: # include <stddef.h>
! 23: #else
! 24: # ifdef HAVE_STDLIB_H
! 25: # include <stdlib.h>
! 26: # endif
! 27: #endif /* STDC_HEADERS */
! 28: #ifdef HAVE_STRING_H
! 29: # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
! 30: # include <memory.h>
! 31: # endif
! 32: # include <string.h>
! 33: #endif /* HAVE_STRING_H */
! 34: #ifdef HAVE_STRINGS_H
! 35: # include <strings.h>
! 36: #endif /* HAVE_STRINGS_H */
! 37: #if defined(HAVE_STDINT_H)
! 38: # include <stdint.h>
! 39: #elif defined(HAVE_INTTYPES_H)
! 40: # include <inttypes.h>
! 41: #endif
! 42:
! 43: #define SUDO_ERROR_WRAP 0
! 44:
! 45: #include "missing.h"
! 46:
! 47: extern size_t base64_decode(const char *str, unsigned char *dst, size_t dsize);
! 48:
! 49: __dso_public int main(int argc, char *argv[]);
! 50:
! 51: struct base64_test {
! 52: const char *ascii;
! 53: const char *encoded;
! 54: } test_strings[] = {
! 55: {
! 56: "any carnal pleasure.",
! 57: "YW55IGNhcm5hbCBwbGVhc3VyZS4="
! 58: },
! 59: {
! 60: "any carnal pleasure",
! 61: "YW55IGNhcm5hbCBwbGVhc3VyZQ=="
! 62: },
! 63: {
! 64: "any carnal pleasur",
! 65: "YW55IGNhcm5hbCBwbGVhc3Vy"
! 66: },
! 67: {
! 68: "any carnal pleasu",
! 69: "YW55IGNhcm5hbCBwbGVhc3U="
! 70: },
! 71: {
! 72: "any carnal pleas",
! 73: "YW55IGNhcm5hbCBwbGVhcw=="
! 74: }
! 75: };
! 76:
! 77: int
! 78: main(int argc, char *argv[])
! 79: {
! 80: const int ntests = (sizeof(test_strings) / sizeof(test_strings[0]));
! 81: int i, errors = 0;
! 82: char buf[32];
! 83: size_t len;
! 84:
! 85: for (i = 0; i < ntests; i++) {
! 86: len = base64_decode(test_strings[i].encoded, buf, sizeof(buf));
! 87: buf[len] = '\0';
! 88: if (strcmp(test_strings[i].ascii, buf) != 0) {
! 89: fprintf(stderr, "check_base64: expected %s, got %s",
! 90: test_strings[i].ascii, buf);
! 91: errors++;
! 92: }
! 93: }
! 94: printf("check_base64: %d tests run, %d errors, %d%% success rate\n",
! 95: ntests, errors, (ntests - errors) * 100 / ntests);
! 96: exit(errors);
! 97: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>