use NULL value in load_path_suffix to NOT load any files
[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      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
19
20  */
21 /**
22  * @author Martin Schanzenbach
23  * @file util/test_crypto_abe.c
24  * @brief test for ABE ciphers
25  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_abe_lib.h"
29
30 #define TESTSTRING "Hello World!"
31
32 static int
33 testAbecipher ()
34 {
35   struct GNUNET_ABE_AbeMasterKey *msk;
36   struct GNUNET_ABE_AbeKey *key;
37   char *result;
38   char **attrs;
39   int size;
40   char *res;
41
42   msk = GNUNET_ABE_cpabe_create_master_key ();
43   size = GNUNET_ABE_cpabe_encrypt (TESTSTRING, strlen (TESTSTRING) + 1,
44                                    "testattr",    // Policy
45                                    msk,
46                                    (void *) &result);
47   GNUNET_assert (-1 != size);
48   attrs = GNUNET_malloc (2 * sizeof(char*));
49   attrs[0] = "testattr";
50   attrs[1] = NULL;
51   key = GNUNET_ABE_cpabe_create_key (msk,
52                                      attrs);
53
54   size = GNUNET_ABE_cpabe_decrypt (result, size,
55                                    key,
56                                    (void *) &res);
57   if (strlen (TESTSTRING) + 1 != size)
58   {
59     printf ("abeciphertest failed: decryptBlock returned %d\n", size);
60     return 1;
61   }
62   if (0 != strcmp (res, TESTSTRING))
63   {
64     printf ("abeciphertest failed: %s != %s\n", res, TESTSTRING);
65     return 1;
66   }
67   else
68     return 0;
69 }
70
71
72 int
73 main (int argc, char *argv[])
74 {
75   int failureCount = 0;
76
77   GNUNET_log_setup ("test-crypto-abe", "WARNING", NULL);
78   failureCount += testAbecipher ();
79
80   if (failureCount != 0)
81   {
82     printf ("%d TESTS FAILED!\n", failureCount);
83     return -1;
84   }
85   return 0;
86 }
87
88
89 /* end of test_crypto_aes.c */