2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file namestore/test_namestore_api_blocks.c
22 * @brief testcase for block creation, verification and decryption
25 #include "gnunet_common.h"
26 #include "gnunet_namestore_service.h"
27 #include "namestore.h"
28 #include "gnunet_signatures.h"
32 #define TEST_RECORD_TYPE 1234
34 #define TEST_RECORD_DATALEN 123
36 #define TEST_RECORD_DATA 'a'
38 #define TEST_REMOVE_RECORD_TYPE 4321
40 #define TEST_REMOVE_RECORD_DATALEN 255
42 #define TEST_REMOVE_RECORD_DATA 'b'
45 static struct GNUNET_CRYPTO_EccPrivateKey * privkey;
47 static struct GNUNET_NAMESTORE_RecordData *s_rd;
54 static struct GNUNET_NAMESTORE_RecordData *
55 create_record (int count)
58 struct GNUNET_NAMESTORE_RecordData * rd;
60 rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData));
61 for (c = 0; c < count; c++)
63 rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us;
64 rd[c].record_type = TEST_RECORD_TYPE;
65 rd[c].data_size = TEST_RECORD_DATALEN;
66 rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
67 memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
74 rd_decrypt_cb (void *cls,
75 unsigned int rd_count,
76 const struct GNUNET_NAMESTORE_RecordData *rd)
78 char rd_cmp_data[TEST_RECORD_DATALEN];
82 GNUNET_assert (RECORDS == rd_count);
83 GNUNET_assert (NULL != rd);
85 memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN);
87 for (c = 0; c < rd_count; c++)
89 GNUNET_assert (TEST_RECORD_TYPE == rd[c].record_type);
90 GNUNET_assert (TEST_RECORD_DATALEN == rd[c].data_size);
91 GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[c].data, TEST_RECORD_DATALEN));
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
94 "Block was decrypted successfully \n");
100 run (void *cls, char *const *args, const char *cfgfile,
101 const struct GNUNET_CONFIGURATION_Handle *cfg)
103 struct GNUNET_NAMESTORE_Block *block;
104 struct GNUNET_CRYPTO_EccPublicSignKey pubkey;
106 /* load privat key */
108 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
109 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
111 privkey = GNUNET_CRYPTO_ecc_key_create_from_file(hostkey_file);
112 GNUNET_free (hostkey_file);
113 GNUNET_assert (privkey != NULL);
114 struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get();
116 GNUNET_CRYPTO_ecc_key_get_public_for_signature(privkey, &pubkey);
119 s_name = "DUMMY.dummy.gnunet";
120 s_rd = create_record (RECORDS);
123 GNUNET_assert (NULL != (block = GNUNET_NAMESTORE_block_create (privkey, expire,s_name, s_rd, RECORDS)));
124 GNUNET_assert (GNUNET_OK == GNUNET_NAMESTORE_block_verify (block));
125 GNUNET_assert (GNUNET_OK == GNUNET_NAMESTORE_block_decrypt (block, &pubkey, s_name, &rd_decrypt_cb, s_name));
132 main (int argc, char *argv[])
134 static char *const argvx[] = { "test-namestore-api",
136 "test_namestore_api.conf",
139 static struct GNUNET_GETOPT_CommandLineOption options[] = {
140 GNUNET_GETOPT_OPTION_END
144 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, "test-namestore-api",
145 "nohelp", options, &run, &res);
149 /* end of test_namestore_api_blocks.c */