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_namestore_service.h"
26 #include "namestore.h"
30 #define TEST_RECORD_TYPE 1234
32 #define TEST_RECORD_DATALEN 123
34 #define TEST_RECORD_DATA 'a'
36 #define TEST_REMOVE_RECORD_TYPE 4321
38 #define TEST_REMOVE_RECORD_DATALEN 255
40 #define TEST_REMOVE_RECORD_DATA 'b'
43 static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey;
45 static struct GNUNET_NAMESTORE_RecordData *s_rd;
52 static struct GNUNET_NAMESTORE_RecordData *
53 create_record (int count)
56 struct GNUNET_NAMESTORE_RecordData * rd;
58 rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData));
59 for (c = 0; c < count; c++)
61 rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us;
62 rd[c].record_type = TEST_RECORD_TYPE;
63 rd[c].data_size = TEST_RECORD_DATALEN;
64 rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
65 memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
72 rd_decrypt_cb (void *cls,
73 unsigned int rd_count,
74 const struct GNUNET_NAMESTORE_RecordData *rd)
76 char rd_cmp_data[TEST_RECORD_DATALEN];
80 GNUNET_assert (RECORDS == rd_count);
81 GNUNET_assert (NULL != rd);
83 memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN);
85 for (c = 0; c < rd_count; c++)
87 GNUNET_assert (TEST_RECORD_TYPE == rd[c].record_type);
88 GNUNET_assert (TEST_RECORD_DATALEN == rd[c].data_size);
89 GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[c].data, TEST_RECORD_DATALEN));
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
92 "Block was decrypted successfully \n");
98 run (void *cls, char *const *args, const char *cfgfile,
99 const struct GNUNET_CONFIGURATION_Handle *cfg)
101 struct GNUNET_NAMESTORE_Block *block;
102 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
104 /* load privat key */
106 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
107 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
109 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
110 GNUNET_free (hostkey_file);
111 GNUNET_assert (privkey != NULL);
112 struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get();
114 GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey);
117 s_name = "DUMMY.dummy.gnunet";
118 s_rd = create_record (RECORDS);
121 GNUNET_assert (NULL != (block = GNUNET_NAMESTORE_block_create (privkey, expire,s_name, s_rd, RECORDS)));
122 GNUNET_assert (GNUNET_OK == GNUNET_NAMESTORE_block_verify (block));
123 GNUNET_assert (GNUNET_OK == GNUNET_NAMESTORE_block_decrypt (block, &pubkey, s_name, &rd_decrypt_cb, s_name));
130 main (int argc, char *argv[])
132 static char *const argvx[] = { "test-namestore-api",
134 "test_namestore_api.conf",
137 static struct GNUNET_GETOPT_CommandLineOption options[] = {
138 GNUNET_GETOPT_OPTION_END
142 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, "test-namestore-api",
143 "nohelp", options, &run, &res);
147 /* end of test_namestore_api_blocks.c */