aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/libgnunet.install1
-rw-r--r--doc/man/Makefile.am1
-rw-r--r--doc/man/gnunet-base32.174
-rw-r--r--src/util/.gitignore1
-rw-r--r--src/util/Makefile.am9
-rw-r--r--src/util/gnunet-base32.c152
-rw-r--r--src/util/gnunet-scrypt.c7
7 files changed, 241 insertions, 4 deletions
diff --git a/debian/libgnunet.install b/debian/libgnunet.install
index 7cf63853c..dd216d5ba 100644
--- a/debian/libgnunet.install
+++ b/debian/libgnunet.install
@@ -7,6 +7,7 @@ usr/lib/*/libgnunetutil.so.*
7usr/share/locale/ 7usr/share/locale/
8usr/share/gnunet/config.d/util.conf 8usr/share/gnunet/config.d/util.conf
9usr/bin/gnunet-arm 9usr/bin/gnunet-arm
10usr/bin/gnunet-base32
10usr/bin/gnunet-bugreport 11usr/bin/gnunet-bugreport
11usr/bin/gnunet-config 12usr/bin/gnunet-config
12usr/bin/gnunet-ecc 13usr/bin/gnunet-ecc
diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am
index a0283cf44..e7045e8bf 100644
--- a/doc/man/Makefile.am
+++ b/doc/man/Makefile.am
@@ -50,6 +50,7 @@ man_MANS = \
50 gnunet-arm.1 \ 50 gnunet-arm.1 \
51 gnunet-ats.1 \ 51 gnunet-ats.1 \
52 gnunet-auto-share.1 \ 52 gnunet-auto-share.1 \
53 gnunet-base32.1 \
53 gnunet-bcd.1 \ 54 gnunet-bcd.1 \
54 gnunet-bugreport.1 \ 55 gnunet-bugreport.1 \
55 gnunet-config.1 \ 56 gnunet-config.1 \
diff --git a/doc/man/gnunet-base32.1 b/doc/man/gnunet-base32.1
new file mode 100644
index 000000000..2e1224279
--- /dev/null
+++ b/doc/man/gnunet-base32.1
@@ -0,0 +1,74 @@
1.\" This file is part of GNUnet.
2.\" Copyright (C) 2021 GNUnet e.V.
3.\"
4.\" Permission is granted to copy, distribute and/or modify this document
5.\" under the terms of the GNU Free Documentation License, Version 1.3 or
6.\" any later version published by the Free Software Foundation; with no
7.\" Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
8.\" copy of the license is included in the file
9.\" FDL-1.3.
10.\"
11.\" A copy of the license is also available from the Free Software
12.\" Foundation Web site at http://www.gnu.org/licenses/fdl.html}.
13.\"
14.\" Alternately, this document is also available under the General
15.\" Public License, version 3 or later, as published by the Free Software
16.\" Foundation. A copy of the license is included in the file
17.\" GPL3.
18.\"
19.\" A copy of the license is also available from the Free Software
20.\" Foundation Web site at http://www.gnu.org/licenses/gpl.html
21.\"
22.\" SPDX-License-Identifier: GPL3.0-or-later OR FDL1.3-or-later
23.\"
24.Dd March 5, 2021
25.Dt GNUNET-BASE32 1
26.Os
27.Sh NAME
28.Nm gnunet-base32
29.Nd encode/decode to Crockford base32 encoding
30.Sh SYNOPSIS
31.Nm
32.Op Fl d | -decode
33.sp
34.Sh DESCRIPTION
35.Nm
36By default, encodes data read from standard input into
37Crockford base32 and writes the result to standard output.
38The inverse operation is performed if the option
39.Fl --decode
40is given. Note that the tool keeps all of the data in
41memory and is largely intended for quick debugging and
42not for high performance.
43.Bl -tag -width indent
44.It Fl d | -decode
45Run in decode mode instead of in encode mode.
46.It Fl h | -help
47Print short help on options.
48.It Fl v | -version
49Print GNUnet version number.
50.El
51.Sh SEE ALSO
52The full documentation for gnunet is maintained as a Texinfo manual.
53If the
54.Xr info 1
55and gnunet programs are properly installed at your site, the command
56.Pp
57.Dl info gnunet
58.Pp
59should give you access to the complete handbook,
60.Pp
61.Dl info gnunet-c-tutorial
62.Pp
63will give you access to a tutorial for developers.
64.sp
65Depending on your installation, this information is also available in
66.Xr gnunet 7 and
67.Xr gnunet-c-tutorial 7 .
68.\".Sh HISTORY
69.\".Sh AUTHORS
70.Sh BUGS
71Report bugs by using
72.Lk https://bugs.gnunet.org
73or by sending electronic mail to
74.Aq Mt gnunet-developers@gnu.org .
diff --git a/src/util/.gitignore b/src/util/.gitignore
index 8556ee7b8..7c7b7045d 100644
--- a/src/util/.gitignore
+++ b/src/util/.gitignore
@@ -80,3 +80,4 @@ python27_location
80perf_malloc 80perf_malloc
81perf_mq 81perf_mq
82perf_scheduler 82perf_scheduler
83gnunet-base32
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 33fe26e34..6b9e083a7 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -152,9 +152,10 @@ libexec_PROGRAMS = \
152 gnunet-timeout 152 gnunet-timeout
153 153
154bin_PROGRAMS = \ 154bin_PROGRAMS = \
155 gnunet-resolver \ 155 gnunet-base32 \
156 gnunet-config \ 156 gnunet-config \
157 gnunet-crypto-tvg \ 157 gnunet-crypto-tvg \
158 gnunet-resolver \
158 $(GNUNET_ECC) \ 159 $(GNUNET_ECC) \
159 $(GNUNET_SCRYPT) \ 160 $(GNUNET_SCRYPT) \
160 gnunet-uri 161 gnunet-uri
@@ -203,6 +204,12 @@ gnunet_ecc_LDADD = \
203 libgnunetutil.la \ 204 libgnunetutil.la \
204 $(GN_LIBINTL) -lgcrypt 205 $(GN_LIBINTL) -lgcrypt
205 206
207gnunet_base32_SOURCES = \
208 gnunet-base32.c
209gnunet_base32_LDADD = \
210 libgnunetutil.la \
211 $(GN_LIBINTL)
212
206gnunet_scrypt_SOURCES = \ 213gnunet_scrypt_SOURCES = \
207 gnunet-scrypt.c 214 gnunet-scrypt.c
208gnunet_scrypt_LDADD = \ 215gnunet_scrypt_LDADD = \
diff --git a/src/util/gnunet-base32.c b/src/util/gnunet-base32.c
new file mode 100644
index 000000000..2c797f56e
--- /dev/null
+++ b/src/util/gnunet-base32.c
@@ -0,0 +1,152 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2021 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 * @file util/gnunet-base32.c
23 * @brief tool to encode/decode from/to the Crockford Base32 encoding GNUnet uses
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28
29
30/**
31 * The main function of gnunet-base32
32 *
33 * @param argc number of arguments from the command line
34 * @param argv command line arguments
35 * @return 0 ok, 1 on error
36 */
37int
38main (int argc,
39 char *const *argv)
40{
41 int decode = 0;
42 const struct GNUNET_GETOPT_CommandLineOption options[] = {
43 GNUNET_GETOPT_option_flag ('d',
44 "decode",
45 gettext_noop ("run decoder modus, otherwise runs as encoder"),
46 &decode),
47 GNUNET_GETOPT_option_help ("Crockford base32 encoder/decoder"),
48 GNUNET_GETOPT_option_version (PACKAGE_VERSION),
49 GNUNET_GETOPT_OPTION_END
50 };
51 int ret;
52 char *in;
53 unsigned int in_size;
54 ssize_t iret;
55 char *out;
56 size_t out_size;
57
58 if (GNUNET_OK !=
59 GNUNET_STRINGS_get_utf8_args (argc, argv,
60 &argc, &argv))
61 return 2;
62 ret = GNUNET_GETOPT_run ("gnunet-base32",
63 options,
64 argc,
65 argv);
66 if (ret < 0)
67 return 1;
68 if (0 == ret)
69 return 0;
70 in_size = 0;
71 in = NULL;
72 iret = 1;
73 while (iret > 0)
74 {
75 /* read in blocks of 4k */
76 char buf[4092];
77
78 iret = read (0,
79 buf,
80 sizeof (buf));
81 if (iret < 0)
82 {
83 GNUNET_free (in);
84 return 2;
85 }
86 if (iret > 0)
87 {
88 if (iret + in_size < in_size)
89 {
90 GNUNET_break (0);
91 GNUNET_free (in);
92 return 1;
93 }
94 GNUNET_array_grow (in,
95 in_size,
96 in_size + iret);
97 memcpy (&in[in_size - iret],
98 buf,
99 iret);
100 }
101 }
102 if (decode)
103 {
104 /* This formula can overestimate by 1 byte, so we try both
105 out_size and out_size-1 below */
106 out_size = in_size * 5 / 8;
107 out = GNUNET_malloc (out_size);
108 if (GNUNET_OK !=
109 GNUNET_STRINGS_string_to_data (in,
110 in_size,
111 out,
112 out_size))
113 {
114 out_size--;
115 if (GNUNET_OK !=
116 GNUNET_STRINGS_string_to_data (in,
117 in_size,
118 out,
119 out_size))
120 {
121 GNUNET_free (out);
122 GNUNET_free (in);
123 return 3;
124 }
125 }
126 }
127 else
128 {
129 out = GNUNET_STRINGS_data_to_string_alloc (in,
130 in_size);
131 out_size = strlen (out);
132 }
133 {
134 size_t pos = 0;
135
136 while (pos < out_size)
137 {
138 iret = write (1,
139 &out[pos],
140 out_size - pos);
141 if (iret <= 0)
142 return 4;
143 pos += iret;
144 }
145 }
146 GNUNET_free (out);
147 GNUNET_free_nz ((void *) argv);
148 return 0;
149}
150
151
152/* end of gnunet-uri.c */
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c
index 5c3dfc12e..fe8b6769f 100644
--- a/src/util/gnunet-scrypt.c
+++ b/src/util/gnunet-scrypt.c
@@ -290,8 +290,8 @@ run (void *cls,
290int 290int
291main (int argc, char *const *argv) 291main (int argc, char *const *argv)
292{ 292{
293 struct GNUNET_GETOPT_CommandLineOption options[] = 293 struct GNUNET_GETOPT_CommandLineOption options[] = {
294 { GNUNET_GETOPT_option_ulong ( 294 GNUNET_GETOPT_option_ulong (
295 'b', 295 'b',
296 "bits", 296 "bits",
297 "BITS", 297 "BITS",
@@ -315,7 +315,8 @@ main (int argc, char *const *argv)
315 gettext_noop ( 315 gettext_noop (
316 "time to wait between calculations"), 316 "time to wait between calculations"),
317 &proof_find_delay), 317 &proof_find_delay),
318 GNUNET_GETOPT_OPTION_END }; 318 GNUNET_GETOPT_OPTION_END
319 };
319 int ret; 320 int ret;
320 321
321 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 322 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))