Branch data Line data Source code
1 : : /* old-base64.c --- Test the base64 functions, using old callback API.
2 : : * Copyright (C) 2002-2012 Simon Josefsson
3 : : *
4 : : * This file is part of GNU SASL.
5 : : *
6 : : * This program is free software: you can redistribute it and/or modify
7 : : * it under the terms of the GNU General Public License as published by
8 : : * the Free Software Foundation, either version 3 of the License, or
9 : : * (at your option) any later version.
10 : : *
11 : : * This program is distributed in the hope that it will be useful,
12 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : : * GNU General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU General Public License
17 : : * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 : : *
19 : : */
20 : :
21 : : #ifdef HAVE_CONFIG_H
22 : : #include "config.h"
23 : : #endif
24 : :
25 : : #include <stdio.h>
26 : : #include <stdarg.h>
27 : : #include <stdlib.h>
28 : : #include <string.h>
29 : :
30 : : #include <gsasl.h>
31 : :
32 : : int
33 : 1 : main (void)
34 : : {
35 : : char target[50];
36 : 1 : size_t targsize = sizeof (target);
37 : : int len;
38 : :
39 : 1 : len = gsasl_base64_encode ("foobar", 6, target, targsize);
40 : 1 : printf ("base64_encode(foobar, 6) = %d, %.*s\n", len, len, target);
41 [ + - ][ - + ]: 1 : if (len != 8 || memcmp (target, "Zm9vYmFy", len) != 0)
42 : : {
43 : 0 : printf ("base64_encode failure\n");
44 : 0 : return EXIT_FAILURE;
45 : : }
46 : :
47 : 1 : len = gsasl_base64_decode ("Zm9vYmFy", target, targsize);
48 : 1 : printf ("base64_decode(Zm9vYmFy, 8) = %d, %.*s\n", len, len, target);
49 [ + - ][ - + ]: 1 : if (len != 6 || memcmp (target, "foobar", len) != 0)
50 : : {
51 : 0 : printf ("base64_decode failure\n");
52 : 0 : return EXIT_FAILURE;
53 : : }
54 : :
55 : 1 : return EXIT_SUCCESS;
56 : : }
|