[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: add gnsrecord tvg
From: |
gnunet |
Subject: |
[gnunet] branch master updated: add gnsrecord tvg |
Date: |
Sun, 10 May 2020 15:26:48 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new f6c7437bf add gnsrecord tvg
f6c7437bf is described below
commit f6c7437bf0a0371b2004b64ec24a68abb3d8e352
Author: Martin Schanzenbach <address@hidden>
AuthorDate: Sun May 10 15:21:47 2020 +0200
add gnsrecord tvg
---
src/gnsrecord/Makefile.am | 12 +++
src/gnsrecord/gnunet-gnsrecord-tvg.c | 191 +++++++++++++++++++++++++++++++++++
2 files changed, 203 insertions(+)
diff --git a/src/gnsrecord/Makefile.am b/src/gnsrecord/Makefile.am
index 3da9af9ca..2e6eca7ba 100644
--- a/src/gnsrecord/Makefile.am
+++ b/src/gnsrecord/Makefile.am
@@ -12,6 +12,10 @@ if USE_COVERAGE
XLIBS = -lgcov
endif
+bin_PROGRAMS = \
+ gnunet-gnsrecord-tvg
+
+
check_PROGRAMS = \
test_gnsrecord_crypto \
test_gnsrecord_serialization \
@@ -28,6 +32,14 @@ endif
lib_LTLIBRARIES = \
libgnunetgnsrecord.la
+gnunet_gnsrecord_tvg_SOURCES = \
+ gnunet-gnsrecord-tvg.c
+gnunet_gnsrecord_tvg_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ libgnunetgnsrecord.la \
+ $(GN_LIBINTL)
+
+
libgnunetgnsrecord_la_SOURCES = \
gnsrecord.c \
gnsrecord_serialization.c \
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c
b/src/gnsrecord/gnunet-gnsrecord-tvg.c
new file mode 100644
index 000000000..e0ac5881a
--- /dev/null
+++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c
@@ -0,0 +1,191 @@
+/*
+ This file is part of GNUnet.
+ Copyright (C) 2020 GNUnet e.V.
+
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
+
+/**
+ * @file util/gnunet-gns-tvg.c
+ * @brief Generate test vectors for GNS.
+ * @author Martin Schanzenbach
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_signatures.h"
+#include "gnunet_gns_service.h"
+#include "gnunet_gnsrecord_lib.h"
+#include "gnunet_dnsparser_lib.h"
+#include "gnunet_testing_lib.h"
+#include <inttypes.h>
+
+#define TEST_RECORD_LABEL "test"
+#define TEST_RECORD_A "1.2.3.4"
+#define TEST_RRCOUNT 2
+
+static void
+print_record(const struct GNUNET_GNSRECORD_Data *rd)
+{
+ char *data_enc;
+ char *string_v;
+ string_v = GNUNET_GNSRECORD_value_to_string (rd->record_type,
+ rd->data,
+ rd->data_size);
+ fprintf (stdout,
+ "EXPIRATION: %"PRIu64"\n", rd->expiration_time);
+ fprintf (stdout,
+ "DATA_SIZE: %"PRIu64"\n", rd->data_size);
+ fprintf (stdout,
+ "TYPE: %d\n", rd->record_type);
+ fprintf (stdout,
+ "FLAGS: %d\n", rd->flags);
+ GNUNET_STRINGS_base64_encode (rd->data,
+ rd->data_size,
+ &data_enc);
+ fprintf (stdout,
+ "DATA (base64):\n%s\n",
+ data_enc);
+ fprintf (stdout,
+ "DATA (Human readable):\n%s\n\n", string_v);
+ GNUNET_free (string_v);
+
+ GNUNET_free (data_enc);
+}
+
+/**
+ * Main function that will be run.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be
NULL!)
+ * @param cfg configuration
+ */
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ struct GNUNET_GNSRECORD_Data rd[2];
+ struct GNUNET_TIME_Absolute exp_abs = GNUNET_TIME_absolute_get();
+ struct GNUNET_GNSRECORD_Block *rrblock;
+ char *bdata;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey id_priv;
+ struct GNUNET_CRYPTO_EcdsaPublicKey id_pub;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey pkey_data_p;
+ struct GNUNET_CRYPTO_EcdsaPublicKey pkey_data;
+ void *data;
+ size_t data_size;
+ char *rdata;
+ size_t rdata_size;
+
+ GNUNET_CRYPTO_ecdsa_key_create (&id_priv);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&id_priv,
+ &id_pub);
+
+ GNUNET_CRYPTO_ecdsa_key_create (&pkey_data_p);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&pkey_data_p,
+ &pkey_data);
+ fprintf (stdout,
+ "Label: %s\nRRCOUNT: %d\n\n", TEST_RECORD_LABEL, TEST_RRCOUNT);
+ memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * 2);
+ GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_string_to_value
(GNUNET_DNSPARSER_TYPE_A, TEST_RECORD_A, &data, &data_size));
+ rd[0].data = data;
+ rd[0].data_size = data_size;
+ rd[0].expiration_time = exp_abs.abs_value_us;
+ rd[0].record_type = GNUNET_DNSPARSER_TYPE_A;
+ fprintf (stdout, "Record #0\n");
+ print_record (&rd[0]);
+
+ rd[1].data = &pkey_data;
+ rd[1].data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
+ rd[1].expiration_time = exp_abs.abs_value_us;
+ rd[1].record_type = GNUNET_GNSRECORD_TYPE_PKEY;
+ rd[1].flags = GNUNET_GNSRECORD_RF_PRIVATE;
+ fprintf (stdout, "Record #1\n");
+ print_record (&rd[1]);
+
+ rdata_size = GNUNET_GNSRECORD_records_get_size (2,
+ rd);
+ rdata = GNUNET_malloc (rdata_size);
+ GNUNET_GNSRECORD_records_serialize (2,
+ rd,
+ rdata_size,
+ rdata);
+ char* data_enc;
+ GNUNET_STRINGS_base64_encode (rdata,
+ rdata_size,
+ &data_enc);
+ fprintf(stdout, "RDATA:\n%s\n\n", data_enc);
+ GNUNET_free (data_enc);
+ rrblock = GNUNET_GNSRECORD_block_create (&id_priv,
+ exp_abs,
+ TEST_RECORD_LABEL,
+ rd,
+ TEST_RRCOUNT);
+ size_t bdata_size = ntohl (rrblock->purpose.size) -
+ sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) -
+ sizeof(struct GNUNET_TIME_AbsoluteNBO);
+ size_t rrblock_size = ntohl (rrblock->purpose.size) +
+ sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) +
+ sizeof(struct GNUNET_CRYPTO_EcdsaSignature);
+
+ bdata = (char*)&rrblock[1];
+ GNUNET_STRINGS_base64_encode (bdata,
+ bdata_size,
+ &data_enc);
+ fprintf(stdout, "BDATA:\n%s\n\n", data_enc);
+ GNUNET_free (data_enc);
+ GNUNET_STRINGS_base64_encode (rrblock,
+ rrblock_size,
+ &data_enc);
+ fprintf(stdout, "RRBLOCK:\n%s\n", data_enc);
+ GNUNET_free (data_enc);
+
+}
+
+
+/**
+ * The main function of the test vector generation tool.
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc,
+ char *const *argv)
+{
+ const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_log_setup ("gnunet-gns-tvg",
+ "INFO",
+ NULL));
+ if (GNUNET_OK !=
+ GNUNET_PROGRAM_run (argc, argv,
+ "gnunet-gns-tvg",
+ "Generate test vectors for GNS",
+ options,
+ &run, NULL))
+ return 1;
+ return 0;
+}
+
+
+/* end of gnunet-gns-tvg.c */
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: add gnsrecord tvg,
gnunet <=