glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / abe / test_cpabe.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2002, 2003, 2004, 2006 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14
15 */
16 /**
17  * @author Martin Schanzenbach
18  * @file util/test_crypto_abe.c
19  * @brief test for ABE ciphers
20  */
21 #include "platform.h"
22 #include "gnunet_util_lib.h"
23 #include "gnunet_abe_lib.h"
24
25 #define TESTSTRING "Hello World!"
26
27 static int
28 testAbecipher ()
29 {
30   struct GNUNET_ABE_AbeMasterKey *msk;
31   struct GNUNET_ABE_AbeKey *key;
32   char *result;
33   char **attrs;
34   int size;
35   char *res;
36   msk = GNUNET_ABE_cpabe_create_master_key ();
37   size = GNUNET_ABE_cpabe_encrypt (TESTSTRING, strlen (TESTSTRING) + 1,
38                                       "testattr", //Policy
39                                       msk,
40                                       (void*)&result);
41   GNUNET_assert (-1 != size);
42   attrs = GNUNET_malloc (2 * sizeof (char*));
43   attrs[0] = "testattr";
44   attrs[1] = NULL;
45   key = GNUNET_ABE_cpabe_create_key (msk,
46                                         attrs);
47
48   size = GNUNET_ABE_cpabe_decrypt (result, size,
49                                       key,
50                                       (void*)&res);
51   if (strlen (TESTSTRING) + 1 != size)
52   {
53     printf ("abeciphertest failed: decryptBlock returned %d\n", size);
54     return 1;
55   }
56   if (0 != strcmp (res, TESTSTRING))
57   {
58     printf ("abeciphertest failed: %s != %s\n", res, TESTSTRING);
59     return 1;
60   }
61   else
62     return 0;
63 }
64
65
66 int
67 main (int argc, char *argv[])
68 {
69   int failureCount = 0;
70
71   GNUNET_log_setup ("test-crypto-abe", "WARNING", NULL);
72   failureCount += testAbecipher ();
73
74   if (failureCount != 0)
75   {
76     printf ("%d TESTS FAILED!\n", failureCount);
77     return -1;
78   }
79   return 0;
80 }
81
82 /* end of test_crypto_aes.c */