aboutsummaryrefslogtreecommitdiff
path: root/src/util/gnunet-base32.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/gnunet-base32.c')
-rw-r--r--src/util/gnunet-base32.c154
1 files changed, 0 insertions, 154 deletions
diff --git a/src/util/gnunet-base32.c b/src/util/gnunet-base32.c
deleted file mode 100644
index 217185ed0..000000000
--- a/src/util/gnunet-base32.c
+++ /dev/null
@@ -1,154 +0,0 @@
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 (
46 "run decoder modus, otherwise runs as encoder"),
47 &decode),
48 GNUNET_GETOPT_option_help ("Crockford base32 encoder/decoder"),
49 GNUNET_GETOPT_option_version (PACKAGE_VERSION),
50 GNUNET_GETOPT_OPTION_END
51 };
52 int ret;
53 char *in;
54 unsigned int in_size;
55 ssize_t iret;
56 char *out;
57 size_t out_size;
58
59 if (GNUNET_OK !=
60 GNUNET_STRINGS_get_utf8_args (argc, argv,
61 &argc, &argv))
62 return 2;
63 ret = GNUNET_GETOPT_run ("gnunet-base32",
64 options,
65 argc,
66 argv);
67 if (ret < 0)
68 return 1;
69 if (0 == ret)
70 return 0;
71 in_size = 0;
72 in = NULL;
73 iret = 1;
74 while (iret > 0)
75 {
76 /* read in blocks of 4k */
77 char buf[4092];
78
79 iret = read (0,
80 buf,
81 sizeof (buf));
82 if (iret < 0)
83 {
84 GNUNET_free (in);
85 return 2;
86 }
87 if (iret > 0)
88 {
89 if (iret + in_size < in_size)
90 {
91 GNUNET_break (0);
92 GNUNET_free (in);
93 return 1;
94 }
95 GNUNET_array_grow (in,
96 in_size,
97 in_size + iret);
98 memcpy (&in[in_size - iret],
99 buf,
100 iret);
101 }
102 }
103 if (decode)
104 {
105 /* This formula can overestimate by 1 byte, so we try both
106 out_size and out_size-1 below */
107 out_size = in_size * 5 / 8;
108 out = GNUNET_malloc (out_size);
109 if ( (GNUNET_OK !=
110 GNUNET_STRINGS_string_to_data (in,
111 in_size,
112 out,
113 out_size)) &&
114 (out_size > 0) )
115 {
116 out_size--;
117 if (GNUNET_OK !=
118 GNUNET_STRINGS_string_to_data (in,
119 in_size,
120 out,
121 out_size))
122 {
123 GNUNET_free (out);
124 GNUNET_free (in);
125 return 3;
126 }
127 }
128 }
129 else
130 {
131 out = GNUNET_STRINGS_data_to_string_alloc (in,
132 in_size);
133 out_size = strlen (out);
134 }
135 {
136 size_t pos = 0;
137
138 while (pos < out_size)
139 {
140 iret = write (1,
141 &out[pos],
142 out_size - pos);
143 if (iret <= 0)
144 return 4;
145 pos += iret;
146 }
147 }
148 GNUNET_free (out);
149 GNUNET_free_nz ((void *) argv);
150 return 0;
151}
152
153
154/* end of gnunet-uri.c */