Branch data Line data Source code
1 : : /* keytab.c --- Self test MIT keytab file readers.
2 : : * Copyright (C) 2002, 2003, 2006, 2007, 2008, 2010 Simon Josefsson
3 : : *
4 : : * This file is part of Shishi.
5 : : *
6 : : * Shishi 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 : : * Shishi 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 Shishi; if not, see http://www.gnu.org/licenses or write
18 : : * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19 : : * Floor, Boston, MA 02110-1301, USA
20 : : *
21 : : */
22 : :
23 : : #include "utils.c"
24 : : #include "read-file.h"
25 : :
26 : : void
27 : 1 : test (Shishi * handle)
28 : : {
29 : : Shishi_keys *keys;
30 : : const Shishi_key *key;
31 : 1 : const char *keytab = getenv ("KEYTAB1");
32 : : char *data, *data2;
33 : : size_t len, len2;
34 : : int rc;
35 : 1 : int keyno = 0;
36 : :
37 [ - + ]: 1 : if (!keytab)
38 : 0 : keytab = "keytab1.bin";
39 : :
40 : 1 : data = read_binary_file (keytab, &len);
41 [ - + ]: 1 : if (data == NULL)
42 : 0 : fail ("cannot read keytab file %s", keytab);
43 : :
44 : 1 : rc = shishi_keys_from_keytab_mem (handle, data, len, &keys);
45 [ - + ]: 1 : if (rc != SHISHI_OK)
46 : 0 : fail ("shishi_keys_from_keytab_mem() failed (%d)\n", rc);
47 : :
48 [ - + ]: 1 : if (shishi_keys_size (keys) != 6)
49 : 0 : fail ("shishi_keys_size() failed (%d)\n", shishi_keys_size (keys));
50 : :
51 [ - + ]: 1 : if (debug)
52 : : {
53 [ # # ]: 0 : while ((key = shishi_keys_nth (keys, keyno++)) != NULL)
54 : : {
55 : 0 : rc = shishi_key_print (handle, stdout, key);
56 [ # # ]: 0 : if (rc != SHISHI_OK)
57 : 0 : fail ("shishi_key_print() failed (%d)\n", rc);
58 : : }
59 : : }
60 : :
61 : 1 : rc = shishi_keys_to_keytab_mem (handle, keys, &data2, &len2);
62 [ - + ]: 1 : if (rc != SHISHI_OK)
63 : 0 : fail ("shishi_keys_to_keytab_mem() failed (%d)\n", rc);
64 : :
65 [ + - ][ - + ]: 1 : if (len != len2 || memcmp (data, data2, len) != 0)
66 : 0 : fail ("memory comparison failed\n");
67 : :
68 : 1 : shishi_keys_done (&keys);
69 : 1 : }
|