aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-07-06 01:48:19 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-07-06 01:48:19 -0800
commitce96f256004d018cd27eda3543d11313d469c2f0 (patch)
tree1e0e5f29dfaa802f40088a6644fdbec412310963
parente51826f6090c998151ce71af0fd472367b03bb98 (diff)
downloadbindletools-ce96f256004d018cd27eda3543d11313d469c2f0.tar.gz
bindletools-ce96f256004d018cd27eda3543d11313d469c2f0.tar.bz2
bindletools-ce96f256004d018cd27eda3543d11313d469c2f0.tar.xz
bindletools-ce96f256004d018cd27eda3543d11313d469c2f0.zip
libbindle: adding data encoding/decoding functions
-rw-r--r--build-aux/makefile-libbindle.am197
-rw-r--r--checks/bindle-enc-b32-dec.c56
-rw-r--r--checks/bindle-enc-b32-enc.c56
-rw-r--r--checks/bindle-enc-b32-val.c56
-rw-r--r--checks/bindle-enc-b32h-dec.c56
-rw-r--r--checks/bindle-enc-b32h-enc.c56
-rw-r--r--checks/bindle-enc-b32h-val.c56
-rw-r--r--checks/bindle-enc-b64-dec.c57
-rw-r--r--checks/bindle-enc-b64-enc.c57
-rw-r--r--checks/bindle-enc-b64-val.c56
-rw-r--r--checks/bindle-enc-crock-dec.c56
-rw-r--r--checks/bindle-enc-crock-enc.c56
-rw-r--r--checks/bindle-enc-crock-val.c56
-rw-r--r--checks/bindle-enc-hex-dec.c57
-rw-r--r--checks/bindle-enc-hex-enc.c57
-rw-r--r--checks/bindle-enc-hex-val.c56
-rw-r--r--checks/bindle-enc-strings.c592
-rw-r--r--checks/bindle-enc-strings.h110
-rw-r--r--include/bindle.h52
-rw-r--r--lib/libbindle/lencoding.c1084
-rw-r--r--lib/libbindle/lencoding.h45
21 files changed, 2924 insertions, 0 deletions
diff --git a/build-aux/makefile-libbindle.am b/build-aux/makefile-libbindle.am
index a5a3548..627e2dd 100644
--- a/build-aux/makefile-libbindle.am
+++ b/build-aux/makefile-libbindle.am
@@ -31,6 +31,21 @@
31EXTRA_PROGRAMS += tests/bindle-array-queue \ 31EXTRA_PROGRAMS += tests/bindle-array-queue \
32 tests/bindle-array-sorted \ 32 tests/bindle-array-sorted \
33 tests/bindle-array-stack \ 33 tests/bindle-array-stack \
34 tests/bindle-enc-b32-dec \
35 tests/bindle-enc-b32-enc \
36 tests/bindle-enc-b32-val \
37 tests/bindle-enc-b32h-dec \
38 tests/bindle-enc-b32h-enc \
39 tests/bindle-enc-b32h-val \
40 tests/bindle-enc-b64-dec \
41 tests/bindle-enc-b64-enc \
42 tests/bindle-enc-b64-val \
43 tests/bindle-enc-crock-dec \
44 tests/bindle-enc-crock-enc \
45 tests/bindle-enc-crock-val \
46 tests/bindle-enc-hex-dec \
47 tests/bindle-enc-hex-enc \
48 tests/bindle-enc-hex-val \
34 tests/bindle-str-basename \ 49 tests/bindle-str-basename \
35 tests/bindle-str-chomp \ 50 tests/bindle-str-chomp \
36 tests/bindle-str-dirname \ 51 tests/bindle-str-dirname \
@@ -41,6 +56,21 @@ EXTRA_PROGRAMS += tests/bindle-array-queue \
41LIBBINDLE_TESTS = tests/bindle-array-queue \ 56LIBBINDLE_TESTS = tests/bindle-array-queue \
42 tests/bindle-array-sorted \ 57 tests/bindle-array-sorted \
43 tests/bindle-array-stack \ 58 tests/bindle-array-stack \
59 tests/bindle-enc-b32-dec \
60 tests/bindle-enc-b32-enc \
61 tests/bindle-enc-b32-val \
62 tests/bindle-enc-b32h-dec \
63 tests/bindle-enc-b32h-enc \
64 tests/bindle-enc-b32h-val \
65 tests/bindle-enc-b64-dec \
66 tests/bindle-enc-b64-enc \
67 tests/bindle-enc-b64-val \
68 tests/bindle-enc-crock-dec \
69 tests/bindle-enc-crock-enc \
70 tests/bindle-enc-crock-val \
71 tests/bindle-enc-hex-dec \
72 tests/bindle-enc-hex-enc \
73 tests/bindle-enc-hex-val \
44 tests/bindle-str-basename \ 74 tests/bindle-str-basename \
45 tests/bindle-str-chomp \ 75 tests/bindle-str-chomp \
46 tests/bindle-str-dirname \ 76 tests/bindle-str-dirname \
@@ -69,6 +99,8 @@ lib_libbindle_a_SOURCES = $(srcdir)/$(bindletools_srcdir)/include/bindle.h \
69 $(srcdir)/$(bindletools_srcdir)/lib/libbindle/larray.h \ 99 $(srcdir)/$(bindletools_srcdir)/lib/libbindle/larray.h \
70 $(srcdir)/$(bindletools_srcdir)/lib/libbindle/ldebug.c \ 100 $(srcdir)/$(bindletools_srcdir)/lib/libbindle/ldebug.c \
71 $(srcdir)/$(bindletools_srcdir)/lib/libbindle/ldebug.h \ 101 $(srcdir)/$(bindletools_srcdir)/lib/libbindle/ldebug.h \
102 $(srcdir)/$(bindletools_srcdir)/lib/libbindle/lencoding.c \
103 $(srcdir)/$(bindletools_srcdir)/lib/libbindle/lencoding.h \
72 $(srcdir)/$(bindletools_srcdir)/lib/libbindle/lfile.c \ 104 $(srcdir)/$(bindletools_srcdir)/lib/libbindle/lfile.c \
73 $(srcdir)/$(bindletools_srcdir)/lib/libbindle/lfile.h \ 105 $(srcdir)/$(bindletools_srcdir)/lib/libbindle/lfile.h \
74 $(srcdir)/$(bindletools_srcdir)/lib/libbindle/lmap.c \ 106 $(srcdir)/$(bindletools_srcdir)/lib/libbindle/lmap.c \
@@ -116,6 +148,171 @@ tests_bindle_array_stack_SOURCES = $(bindletools_srcdir)/include/bindle.h \
116 $(bindletools_srcdir)/checks/bindle-array-stack.c 148 $(bindletools_srcdir)/checks/bindle-array-stack.c
117 149
118 150
151# macros for tests/bindle-enc-b32-dec
152tests_bindle_enc_b32_dec_DEPENDENCIES = lib/libbindle.a
153tests_bindle_enc_b32_dec_LDADD = lib/libbindle.a
154tests_bindle_enc_b32_dec_SOURCES = $(bindletools_srcdir)/include/bindle.h \
155 $(bindletools_srcdir)/checks/bindle-tests.h \
156 $(bindletools_srcdir)/checks/bindle-tests.c \
157 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
158 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
159 $(bindletools_srcdir)/checks/bindle-enc-b32-dec.c
160
161
162# macros for tests/bindle-enc-b32-enc
163tests_bindle_enc_b32_enc_DEPENDENCIES = lib/libbindle.a
164tests_bindle_enc_b32_enc_LDADD = lib/libbindle.a
165tests_bindle_enc_b32_enc_SOURCES = $(bindletools_srcdir)/include/bindle.h \
166 $(bindletools_srcdir)/checks/bindle-tests.h \
167 $(bindletools_srcdir)/checks/bindle-tests.c \
168 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
169 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
170 $(bindletools_srcdir)/checks/bindle-enc-b32-enc.c
171
172
173# macros for tests/bindle-enc-b32-val
174tests_bindle_enc_b32_val_DEPENDENCIES = lib/libbindle.a
175tests_bindle_enc_b32_val_LDADD = lib/libbindle.a
176tests_bindle_enc_b32_val_SOURCES = $(bindletools_srcdir)/include/bindle.h \
177 $(bindletools_srcdir)/checks/bindle-tests.h \
178 $(bindletools_srcdir)/checks/bindle-tests.c \
179 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
180 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
181 $(bindletools_srcdir)/checks/bindle-enc-b32-val.c
182
183
184# macros for tests/bindle-enc-b32h-dec
185tests_bindle_enc_b32h_dec_DEPENDENCIES = lib/libbindle.a
186tests_bindle_enc_b32h_dec_LDADD = lib/libbindle.a
187tests_bindle_enc_b32h_dec_SOURCES = $(bindletools_srcdir)/include/bindle.h \
188 $(bindletools_srcdir)/checks/bindle-tests.h \
189 $(bindletools_srcdir)/checks/bindle-tests.c \
190 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
191 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
192 $(bindletools_srcdir)/checks/bindle-enc-b32h-dec.c
193
194
195# macros for tests/bindle-enc-b32h-enc
196tests_bindle_enc_b32h_enc_DEPENDENCIES = lib/libbindle.a
197tests_bindle_enc_b32h_enc_LDADD = lib/libbindle.a
198tests_bindle_enc_b32h_enc_SOURCES = $(bindletools_srcdir)/include/bindle.h \
199 $(bindletools_srcdir)/checks/bindle-tests.h \
200 $(bindletools_srcdir)/checks/bindle-tests.c \
201 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
202 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
203 $(bindletools_srcdir)/checks/bindle-enc-b32h-enc.c
204
205
206# macros for tests/bindle-enc-b32h-val
207tests_bindle_enc_b32h_val_DEPENDENCIES = lib/libbindle.a
208tests_bindle_enc_b32h_val_LDADD = lib/libbindle.a
209tests_bindle_enc_b32h_val_SOURCES = $(bindletools_srcdir)/include/bindle.h \
210 $(bindletools_srcdir)/checks/bindle-tests.h \
211 $(bindletools_srcdir)/checks/bindle-tests.c \
212 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
213 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
214 $(bindletools_srcdir)/checks/bindle-enc-b32h-val.c
215
216
217# macros for tests/bindle-enc-b64-dec
218tests_bindle_enc_b64_dec_DEPENDENCIES = lib/libbindle.a
219tests_bindle_enc_b64_dec_LDADD = lib/libbindle.a
220tests_bindle_enc_b64_dec_SOURCES = $(bindletools_srcdir)/include/bindle.h \
221 $(bindletools_srcdir)/checks/bindle-tests.h \
222 $(bindletools_srcdir)/checks/bindle-tests.c \
223 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
224 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
225 $(bindletools_srcdir)/checks/bindle-enc-b64-dec.c
226
227
228# macros for tests/bindle-enc-b64-enc
229tests_bindle_enc_b64_enc_DEPENDENCIES = lib/libbindle.a
230tests_bindle_enc_b64_enc_LDADD = lib/libbindle.a
231tests_bindle_enc_b64_enc_SOURCES = $(bindletools_srcdir)/include/bindle.h \
232 $(bindletools_srcdir)/checks/bindle-tests.h \
233 $(bindletools_srcdir)/checks/bindle-tests.c \
234 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
235 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
236 $(bindletools_srcdir)/checks/bindle-enc-b64-enc.c
237
238
239# macros for tests/bindle-enc-b64-val
240tests_bindle_enc_b64_val_DEPENDENCIES = lib/libbindle.a
241tests_bindle_enc_b64_val_LDADD = lib/libbindle.a
242tests_bindle_enc_b64_val_SOURCES = $(bindletools_srcdir)/include/bindle.h \
243 $(bindletools_srcdir)/checks/bindle-tests.h \
244 $(bindletools_srcdir)/checks/bindle-tests.c \
245 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
246 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
247 $(bindletools_srcdir)/checks/bindle-enc-b64-val.c
248
249
250# macros for tests/bindle-enc-crock-dec
251tests_bindle_enc_crock_dec_DEPENDENCIES = lib/libbindle.a
252tests_bindle_enc_crock_dec_LDADD = lib/libbindle.a
253tests_bindle_enc_crock_dec_SOURCES = $(bindletools_srcdir)/include/bindle.h \
254 $(bindletools_srcdir)/checks/bindle-tests.h \
255 $(bindletools_srcdir)/checks/bindle-tests.c \
256 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
257 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
258 $(bindletools_srcdir)/checks/bindle-enc-crock-dec.c
259
260
261# macros for tests/bindle-enc-crock-enc
262tests_bindle_enc_crock_enc_DEPENDENCIES = lib/libbindle.a
263tests_bindle_enc_crock_enc_LDADD = lib/libbindle.a
264tests_bindle_enc_crock_enc_SOURCES = $(bindletools_srcdir)/include/bindle.h \
265 $(bindletools_srcdir)/checks/bindle-tests.h \
266 $(bindletools_srcdir)/checks/bindle-tests.c \
267 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
268 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
269 $(bindletools_srcdir)/checks/bindle-enc-crock-enc.c
270
271
272# macros for tests/bindle-enc-crock-val
273tests_bindle_enc_crock_val_DEPENDENCIES = lib/libbindle.a
274tests_bindle_enc_crock_val_LDADD = lib/libbindle.a
275tests_bindle_enc_crock_val_SOURCES = $(bindletools_srcdir)/include/bindle.h \
276 $(bindletools_srcdir)/checks/bindle-tests.h \
277 $(bindletools_srcdir)/checks/bindle-tests.c \
278 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
279 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
280 $(bindletools_srcdir)/checks/bindle-enc-crock-val.c
281
282
283# macros for tests/bindle-enc-hex-dec
284tests_bindle_enc_hex_dec_DEPENDENCIES = lib/libbindle.a
285tests_bindle_enc_hex_dec_LDADD = lib/libbindle.a
286tests_bindle_enc_hex_dec_SOURCES = $(bindletools_srcdir)/include/bindle.h \
287 $(bindletools_srcdir)/checks/bindle-tests.h \
288 $(bindletools_srcdir)/checks/bindle-tests.c \
289 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
290 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
291 $(bindletools_srcdir)/checks/bindle-enc-hex-dec.c
292
293
294# macros for tests/bindle-enc-hex-enc
295tests_bindle_enc_hex_enc_DEPENDENCIES = lib/libbindle.a
296tests_bindle_enc_hex_enc_LDADD = lib/libbindle.a
297tests_bindle_enc_hex_enc_SOURCES = $(bindletools_srcdir)/include/bindle.h \
298 $(bindletools_srcdir)/checks/bindle-tests.h \
299 $(bindletools_srcdir)/checks/bindle-tests.c \
300 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
301 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
302 $(bindletools_srcdir)/checks/bindle-enc-hex-enc.c
303
304
305# macros for tests/bindle-enc-hex-val
306tests_bindle_enc_hex_val_DEPENDENCIES = lib/libbindle.a
307tests_bindle_enc_hex_val_LDADD = lib/libbindle.a
308tests_bindle_enc_hex_val_SOURCES = $(bindletools_srcdir)/include/bindle.h \
309 $(bindletools_srcdir)/checks/bindle-tests.h \
310 $(bindletools_srcdir)/checks/bindle-tests.c \
311 $(bindletools_srcdir)/checks/bindle-enc-strings.h \
312 $(bindletools_srcdir)/checks/bindle-enc-strings.c \
313 $(bindletools_srcdir)/checks/bindle-enc-hex-val.c
314
315
119# macros for tests/bindle-str-basename 316# macros for tests/bindle-str-basename
120tests_bindle_str_basename_DEPENDENCIES = lib/libbindle.a 317tests_bindle_str_basename_DEPENDENCIES = lib/libbindle.a
121tests_bindle_str_basename_LDADD = lib/libbindle.a 318tests_bindle_str_basename_LDADD = lib/libbindle.a
diff --git a/checks/bindle-enc-b32-dec.c b/checks/bindle-enc-b32-dec.c
new file mode 100644
index 0000000..6b165bd
--- /dev/null
+++ b/checks/bindle-enc-b32-dec.c
@@ -0,0 +1,56 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_B32_DEC_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_decode("bindle-enc-b32-dec", argc, argv, BNDL_BASE32, base32_strings));
54}
55
56/* end of source file */
diff --git a/checks/bindle-enc-b32-enc.c b/checks/bindle-enc-b32-enc.c
new file mode 100644
index 0000000..3125d19
--- /dev/null
+++ b/checks/bindle-enc-b32-enc.c
@@ -0,0 +1,56 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_B32_ENC_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_encode("bindle-enc-b32-enc", argc, argv, BNDL_BASE32, base32_strings));
54}
55
56/* end of source file */
diff --git a/checks/bindle-enc-b32-val.c b/checks/bindle-enc-b32-val.c
new file mode 100644
index 0000000..ee42990
--- /dev/null
+++ b/checks/bindle-enc-b32-val.c
@@ -0,0 +1,56 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_B32_VAL_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_validate("bindle-enc-b32-val", argc, argv, BNDL_BASE32, base32_strings));
54}
55
56/* end of source file */
diff --git a/checks/bindle-enc-b32h-dec.c b/checks/bindle-enc-b32h-dec.c
new file mode 100644
index 0000000..366091e
--- /dev/null
+++ b/checks/bindle-enc-b32h-dec.c
@@ -0,0 +1,56 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_B32H_DEC_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_decode("bindle-enc-b32h-dec", argc, argv, BNDL_BASE32HEX, base32hex_strings));
54}
55
56/* end of source file */
diff --git a/checks/bindle-enc-b32h-enc.c b/checks/bindle-enc-b32h-enc.c
new file mode 100644
index 0000000..619f3ac
--- /dev/null
+++ b/checks/bindle-enc-b32h-enc.c
@@ -0,0 +1,56 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_B32H_ENC_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_encode("bindle-enc-b32h-enc", argc, argv, BNDL_BASE32HEX, base32hex_strings));
54}
55
56/* end of source file */
diff --git a/checks/bindle-enc-b32h-val.c b/checks/bindle-enc-b32h-val.c
new file mode 100644
index 0000000..a237571
--- /dev/null
+++ b/checks/bindle-enc-b32h-val.c
@@ -0,0 +1,56 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_B32H_VAL_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_validate("bindle-enc-b32h-val", argc, argv, BNDL_BASE32HEX, base32hex_strings));
54}
55
56/* end of source file */
diff --git a/checks/bindle-enc-b64-dec.c b/checks/bindle-enc-b64-dec.c
new file mode 100644
index 0000000..fd634d5
--- /dev/null
+++ b/checks/bindle-enc-b64-dec.c
@@ -0,0 +1,57 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_B64_DEC_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_decode("bindle-enc-b64-dec", argc, argv, BNDL_BASE64, base64_strings));
54}
55
56
57/* end of source file */
diff --git a/checks/bindle-enc-b64-enc.c b/checks/bindle-enc-b64-enc.c
new file mode 100644
index 0000000..0dd6287
--- /dev/null
+++ b/checks/bindle-enc-b64-enc.c
@@ -0,0 +1,57 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_B64_ENC_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_encode("bindle-enc-b64-enc", argc, argv, BNDL_BASE64, base64_strings));
54}
55
56
57/* end of source file */
diff --git a/checks/bindle-enc-b64-val.c b/checks/bindle-enc-b64-val.c
new file mode 100644
index 0000000..5a8943f
--- /dev/null
+++ b/checks/bindle-enc-b64-val.c
@@ -0,0 +1,56 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_B64_VAL_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_validate("bindle-enc-b64-val", argc, argv, BNDL_BASE64, base64_strings));
54}
55
56/* end of source file */
diff --git a/checks/bindle-enc-crock-dec.c b/checks/bindle-enc-crock-dec.c
new file mode 100644
index 0000000..2aa210a
--- /dev/null
+++ b/checks/bindle-enc-crock-dec.c
@@ -0,0 +1,56 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_CROCK_DEC_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_decode("bindle-enc-crock-dec", argc, argv, BNDL_CROCKFORD, crockford_strings));
54}
55
56/* end of source file */
diff --git a/checks/bindle-enc-crock-enc.c b/checks/bindle-enc-crock-enc.c
new file mode 100644
index 0000000..1983dd4
--- /dev/null
+++ b/checks/bindle-enc-crock-enc.c
@@ -0,0 +1,56 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_CROCK_ENC_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_encode("bindle-enc-crock-enc", argc, argv, BNDL_CROCKFORD, crockford_strings));
54}
55
56/* end of source file */
diff --git a/checks/bindle-enc-crock-val.c b/checks/bindle-enc-crock-val.c
new file mode 100644
index 0000000..596dd43
--- /dev/null
+++ b/checks/bindle-enc-crock-val.c
@@ -0,0 +1,56 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_CROCK_VAL_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_validate("bindle-enc-crock-val", argc, argv, BNDL_CROCKFORD, crockford_strings));
54}
55
56/* end of source file */
diff --git a/checks/bindle-enc-hex-dec.c b/checks/bindle-enc-hex-dec.c
new file mode 100644
index 0000000..3c31d7c
--- /dev/null
+++ b/checks/bindle-enc-hex-dec.c
@@ -0,0 +1,57 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_HEX_DEC_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_decode("bindle-enc-hex-dec", argc, argv, BNDL_HEX, hex_strings));
54}
55
56
57/* end of source file */
diff --git a/checks/bindle-enc-hex-enc.c b/checks/bindle-enc-hex-enc.c
new file mode 100644
index 0000000..a0304f0
--- /dev/null
+++ b/checks/bindle-enc-hex-enc.c
@@ -0,0 +1,57 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_HEX_ENC_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_encode("bindle-enc-hex-enc", argc, argv, BNDL_HEX, hex_strings));
54}
55
56
57/* end of source file */
diff --git a/checks/bindle-enc-hex-val.c b/checks/bindle-enc-hex-val.c
new file mode 100644
index 0000000..829a9fe
--- /dev/null
+++ b/checks/bindle-enc-hex-val.c
@@ -0,0 +1,56 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_HEX_VAL_C 1
32#include "bindle-enc-strings.h"
33
34//////////////////
35// //
36// Prototypes //
37// //
38//////////////////
39#pragma mark - Prototypes
40
41int main(int argc, char * argv[]);
42
43
44/////////////////
45// //
46// Functions //
47// //
48/////////////////
49#pragma mark - Functions
50
51int main(int argc, char * argv[])
52{
53 return(bindle_test_validate("bindle-enc-hex-val", argc, argv, BNDL_HEX, hex_strings));
54}
55
56/* end of source file */
diff --git a/checks/bindle-enc-strings.c b/checks/bindle-enc-strings.c
new file mode 100644
index 0000000..8734b33
--- /dev/null
+++ b/checks/bindle-enc-strings.c
@@ -0,0 +1,592 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _TESTS_BINDLE_ENC_STRINGS_C 1
32#include "bindle-enc-strings.h"
33
34///////////////
35// //
36// Headers //
37// //
38///////////////
39#pragma mark - Headers
40
41#include <stdio.h>
42#include <string.h>
43#include <strings.h>
44#include <stdlib.h>
45#include <errno.h>
46#include <getopt.h>
47
48#include <bindle.h>
49
50
51/////////////////
52// //
53// Variables //
54// //
55/////////////////
56#pragma mark - Variables
57
58#pragma mark base32_strings[]
59struct test_data base32_strings[] =
60{
61 { .dec = "", .enc = "", .nopad = 0 },
62 { .dec = NULL, .enc = "M=======", .nopad = 0 },
63 { .dec = NULL, .enc = "MY=====", .nopad = 0 },
64 { .dec = "f", .enc = "MY======", .nopad = 0 },
65 { .dec = NULL, .enc = "MZX=====", .nopad = 0 },
66 { .dec = "fo", .enc = "MZXQ====", .nopad = 0 },
67 { .dec = "foo", .enc = "MZXW6===", .nopad = 0 },
68 { .dec = "foob", .enc = "MZXW6YQ=", .nopad = 0 },
69 { .dec = "fooba", .enc = "MZXW6YTB", .nopad = 0 },
70 { .dec = "foobar", .enc = "MZXW6YTBOI======", .nopad = 0 },
71 { .dec = "foobarb", .enc = "MZXW6YTBOJRA====", .nopad = 0 },
72 { .dec = "foobarba", .enc = "MZXW6YTBOJRGC===", .nopad = 0 },
73 { .dec = "foobarbar", .enc = "MZXW6YTBOJRGC4Q=", .nopad = 0 },
74 { .dec = "foobarbarf", .enc = "MZXW6YTBOJRGC4TG", .nopad = 0 },
75 { .dec = "foobarbarfo", .enc = "MZXW6YTBOJRGC4TGN4======", .nopad = 0 },
76 { .dec = "foobarbarfoo", .enc = "MZXW6YTBOJRGC4TGN5XQ====", .nopad = 0 },
77 { .dec = "", .enc = "", .nopad = 1 },
78 { .dec = "f", .enc = "MY", .nopad = 1 },
79 { .dec = "fo", .enc = "MZXQ", .nopad = 1 },
80 { .dec = "foo", .enc = "MZXW6", .nopad = 1 },
81 { .dec = "foob", .enc = "MZXW6YQ", .nopad = 1 },
82 { .dec = "fooba", .enc = "MZXW6YTB", .nopad = 1 },
83 { .dec = "foobar", .enc = "MZXW6YTBOI", .nopad = 1 },
84 { .dec = "foobarb", .enc = "MZXW6YTBOJRA", .nopad = 1 },
85 { .dec = "foobarba", .enc = "MZXW6YTBOJRGC", .nopad = 1 },
86 { .dec = "foobarbar", .enc = "MZXW6YTBOJRGC4Q", .nopad = 1 },
87 { .dec = "foobarbarf", .enc = "MZXW6YTBOJRGC4TG", .nopad = 1 },
88 { .dec = "foobarbarfo", .enc = "MZXW6YTBOJRGC4TGN4", .nopad = 1 },
89 { .dec = "foobarbarfoo", .enc = "MZXW6YTBOJRGC4TGN5XQ", .nopad = 1 },
90 { .dec = NULL, .enc = NULL, .nopad = 0 }
91};
92
93
94#pragma mark base32hex_strings[]
95struct test_data base32hex_strings[] =
96{
97 { .dec = "", .enc = "", .nopad = 0 },
98 { .dec = "f", .enc = "CO======", .nopad = 0 },
99 { .dec = "fo", .enc = "CPNG====", .nopad = 0 },
100 { .dec = "foo", .enc = "CPNMU===", .nopad = 0 },
101 { .dec = "foob", .enc = "CPNMUOG=", .nopad = 0 },
102 { .dec = "fooba", .enc = "CPNMUOJ1", .nopad = 0 },
103 { .dec = "foobar", .enc = "CPNMUOJ1E8======", .nopad = 0 },
104 { .dec = "foobarb", .enc = "CPNMUOJ1E9H0====", .nopad = 0 },
105 { .dec = "foobarba", .enc = "CPNMUOJ1E9H62===", .nopad = 0 },
106 { .dec = "foobarbar", .enc = "CPNMUOJ1E9H62SG=", .nopad = 0 },
107 { .dec = "foobarbarf", .enc = "CPNMUOJ1E9H62SJ6", .nopad = 0 },
108 { .dec = "foobarbarfo", .enc = "CPNMUOJ1E9H62SJ6DS======", .nopad = 0 },
109 { .dec = "foobarbarfoo", .enc = "CPNMUOJ1E9H62SJ6DTNG====", .nopad = 0 },
110 { .dec = "", .enc = "", .nopad = 1 },
111 { .dec = "f", .enc = "CO", .nopad = 1 },
112 { .dec = "fo", .enc = "CPNG", .nopad = 1 },
113 { .dec = "foo", .enc = "CPNMU", .nopad = 1 },
114 { .dec = "foob", .enc = "CPNMUOG", .nopad = 1 },
115 { .dec = "fooba", .enc = "CPNMUOJ1", .nopad = 1 },
116 { .dec = "foobar", .enc = "CPNMUOJ1E8", .nopad = 1 },
117 { .dec = "foobarb", .enc = "CPNMUOJ1E9H0", .nopad = 1 },
118 { .dec = "foobarba", .enc = "CPNMUOJ1E9H62", .nopad = 1 },
119 { .dec = "foobarbar", .enc = "CPNMUOJ1E9H62SG", .nopad = 1 },
120 { .dec = "foobarbarf", .enc = "CPNMUOJ1E9H62SJ6", .nopad = 1 },
121 { .dec = "foobarbarfo", .enc = "CPNMUOJ1E9H62SJ6DS", .nopad = 1 },
122 { .dec = "foobarbarfoo", .enc = "CPNMUOJ1E9H62SJ6DTNG", .nopad = 1 },
123 { .dec = NULL, .enc = NULL, .nopad = 0 }
124};
125
126
127#pragma mark base64_strings[]
128struct test_data base64_strings[] =
129{
130 { .dec = "", .enc = "", .nopad = 0 },
131 { .dec = "f", .enc = "Zg==", .nopad = 0 },
132 { .dec = "fo", .enc = "Zm8=", .nopad = 0 },
133 { .dec = "foo", .enc = "Zm9v", .nopad = 0 },
134 { .dec = "foob", .enc = "Zm9vYg==", .nopad = 0 },
135 { .dec = "fooba", .enc = "Zm9vYmE=", .nopad = 0 },
136 { .dec = "foobar", .enc = "Zm9vYmFy", .nopad = 0 },
137 { .dec = "foobarb", .enc = "Zm9vYmFyYg==", .nopad = 0 },
138 { .dec = "foobarba", .enc = "Zm9vYmFyYmE=", .nopad = 0 },
139 { .dec = "foobarbar", .enc = "Zm9vYmFyYmFy", .nopad = 0 },
140 { .dec = "foobarbarf", .enc = "Zm9vYmFyYmFyZg==", .nopad = 0 },
141 { .dec = "foobarbarfo", .enc = "Zm9vYmFyYmFyZm8=", .nopad = 0 },
142 { .dec = "foobarbarfoo", .enc = "Zm9vYmFyYmFyZm9v", .nopad = 0 },
143 { .dec = "", .enc = "", .nopad = 1 },
144 { .dec = "f", .enc = "Zg", .nopad = 1 },
145 { .dec = "fo", .enc = "Zm8", .nopad = 1 },
146 { .dec = "foo", .enc = "Zm9v", .nopad = 1 },
147 { .dec = "foob", .enc = "Zm9vYg", .nopad = 1 },
148 { .dec = "fooba", .enc = "Zm9vYmE", .nopad = 1 },
149 { .dec = "foobar", .enc = "Zm9vYmFy", .nopad = 1 },
150 { .dec = "foobarb", .enc = "Zm9vYmFyYg", .nopad = 1 },
151 { .dec = "foobarba", .enc = "Zm9vYmFyYmE", .nopad = 1 },
152 { .dec = "foobarbar", .enc = "Zm9vYmFyYmFy", .nopad = 1 },
153 { .dec = "foobarbarf", .enc = "Zm9vYmFyYmFyZg", .nopad = 1 },
154 { .dec = "foobarbarfo", .enc = "Zm9vYmFyYmFyZm8", .nopad = 1 },
155 { .dec = "foobarbarfoo", .enc = "Zm9vYmFyYmFyZm9v", .nopad = 1 },
156 { .dec = "5nuvF7DY4/PY+APIzP", .enc = "NW51dkY3RFk0L1BZK0FQSXpQ", .nopad = 1 },
157 { .dec = "wpq83IwsEv3ci0hf2S", .enc = "d3BxODNJd3NFdjNjaTBoZjJT", .nopad = 1 },
158 { .dec = "4ltI0yv+ddKjyEN6IU", .enc = "NGx0STB5ditkZEtqeUVONklV", .nopad = 1 },
159 { .dec = "sLo8FOEOQGzDtXIE72", .enc = "c0xvOEZPRU9RR3pEdFhJRTcy", .nopad = 1 },
160 { .dec = "uQBsjzE1uZ287j0hIW", .enc = "dVFCc2p6RTF1WjI4N2owaElX", .nopad = 1 },
161 { .dec = "5OcM4X4uibUIsf0KF/", .enc = "NU9jTTRYNHVpYlVJc2YwS0Yv", .nopad = 1 },
162 { .dec = "2WGVwxQBvpMz6d/a+O", .enc = "MldHVnd4UUJ2cE16NmQvYStP", .nopad = 1 },
163 { .dec = "u1OAtBFMPKCWnS7fw8", .enc = "dTFPQXRCRk1QS0NXblM3Znc4", .nopad = 1 },
164 { .dec = "XsbP5uIZ1RMOLH8Tzo", .enc = "WHNiUDV1SVoxUk1PTEg4VHpv", .nopad = 1 },
165 { .dec = "L8C0IUt45j42ic36+k", .enc = "TDhDMElVdDQ1ajQyaWMzNitr", .nopad = 1 },
166 { .dec = "HqC2LnE2qxADXk3g7+", .enc = "SHFDMkxuRTJxeEFEWGszZzcr", .nopad = 1 },
167 { .dec = "ko4QuyAGFQD2IUPZU8", .enc = "a280UXV5QUdGUUQySVVQWlU4", .nopad = 1 },
168 { .dec = NULL, .enc = NULL, .nopad = 0 }
169};
170
171
172#pragma mark crockford_strings[]
173struct test_data crockford_strings[] =
174{
175 { .dec = "", .enc = "", .nopad = 0 },
176 { .dec = "f", .enc = "CR", .nopad = 0 },
177 { .dec = "fo", .enc = "CSQG", .nopad = 0 },
178 { .dec = "foo", .enc = "CSQPY", .nopad = 0 },
179 { .dec = "foob", .enc = "CSQPYRG", .nopad = 0 },
180 { .dec = "fooba", .enc = "CSQPYRK1", .nopad = 0 },
181 { .dec = "foobar", .enc = "CSQPYRK1E8", .nopad = 0 },
182 { .dec = "foobarb", .enc = "CSQPYRK1E9H0", .nopad = 0 },
183 { .dec = "foobarba", .enc = "CSQPYRK1E9H62", .nopad = 0 },
184 { .dec = "foobarbar", .enc = "CSQPYRK1E9H62WG", .nopad = 0 },
185 { .dec = "foobarbarf", .enc = "CSQPYRK1E9H62WK6", .nopad = 0 },
186 { .dec = "foobarbarfo", .enc = "CSQPYRK1E9H62WK6DW", .nopad = 0 },
187 { .dec = "foobarbarfoo", .enc = "CSQPYRK1E9H62WK6DXQG", .nopad = 0 },
188 { .dec = NULL, .enc = NULL, .nopad = 0 }
189};
190
191
192#pragma mark hex_strings[]
193struct test_data hex_strings[] =
194{
195 { .dec = "", .enc = "", .nopad = 0 },
196 { .dec = "f", .enc = "66", .nopad = 0 },
197 { .dec = "fo", .enc = "666f", .nopad = 0 },
198 { .dec = "foo", .enc = "666f6f", .nopad = 0 },
199 { .dec = "foob", .enc = "666f6f62", .nopad = 0 },
200 { .dec = "fooba", .enc = "666f6f6261", .nopad = 0 },
201 { .dec = "foobar", .enc = "666f6f626172", .nopad = 0 },
202 { .dec = "foobarb", .enc = "666f6f62617262", .nopad = 0 },
203 { .dec = "foobarba", .enc = "666f6f6261726261", .nopad = 0 },
204 { .dec = "foobarbar", .enc = "666f6f626172626172", .nopad = 0 },
205 { .dec = "foobarbarf", .enc = "666f6f62617262617266", .nopad = 0 },
206 { .dec = "foobarbarfo", .enc = "666f6f626172626172666f", .nopad = 0 },
207 { .dec = "foobarbarfoo", .enc = "666f6f626172626172666f6f", .nopad = 0 },
208 { .dec = NULL, .enc = NULL, .nopad = 0 }
209};
210
211
212/////////////////
213// //
214// Functions //
215// //
216/////////////////
217#pragma mark - Functions
218
219int
220bindle_test_decode(
221 const char * prog_name,
222 int argc,
223 char * argv[],
224 int method,
225 struct test_data * data )
226{
227 int opt;
228 int c;
229 int opt_index;
230 unsigned opts;
231 size_t pos;
232 char buff[24];
233 ssize_t len;
234 const char * dec;
235 const char * enc;
236 int exit_code;
237 char msg[128];
238
239 // getopt options
240 static char short_opt[] = "dhVvq";
241 static struct option long_opt[] =
242 {
243 {"debug", no_argument, NULL, 'd' },
244 {"help", no_argument, NULL, 'h' },
245 {"quiet", no_argument, NULL, 'q' },
246 {"silent", no_argument, NULL, 'q' },
247 {"version", no_argument, NULL, 'V' },
248 {"verbose", no_argument, NULL, 'v' },
249 { NULL, 0, NULL, 0 }
250 };
251
252 bindle_tests_initialize(prog_name);
253
254 opts = 0;
255 exit_code = 0;
256
257 while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1)
258 {
259 switch(c)
260 {
261 case -1: /* no more arguments */
262 case 0: /* long options toggles */
263 break;
264
265 case 'd':
266 opt = BNDL_DEBUG_ANY;
267 bindle_set_option(NULL, BNDL_OPT_DEBUG_LEVEL, &opt);
268 break;
269
270 case 'h':
271 printf("Usage: %s [OPTIONS]\n", prog_name);
272 printf("OPTIONS:\n");
273 printf(" -d, --debug print debug messages\n");
274 printf(" -h, --help print this help and exit\n");
275 printf(" -q, --quiet, --silent do not print messages\n");
276 printf(" -V, --version print version number and exit\n");
277 printf(" -v, --verbose print verbose messages\n");
278 printf("\n");
279 return(0);
280
281 case 'q':
282 opts |= BNDLTEST_OPT_QUIET;
283 opts &= ~BNDLTEST_OPT_VERBOSE;
284 break;
285
286 case 'V':
287 bindle_tests_version();
288 return(0);
289
290 case 'v':
291 opts |= BNDLTEST_OPT_VERBOSE;
292 opts &= ~BNDLTEST_OPT_QUIET;
293 break;
294
295 case '?':
296 fprintf(stderr, "Try `%s --help' for more information.\n", prog_name);
297 return(1);
298
299 default:
300 fprintf(stderr, "%s: unrecognized option `--%c'\n", prog_name, c);
301 fprintf(stderr, "Try `%s --help' for more information.\n", prog_name);
302 return(1);
303 };
304 };
305 if (optind < argc)
306 {
307 fprintf(stderr, "%s: unknown argument `%s'\n", prog_name, argv[optind]);
308 fprintf(stderr, "Try `%s --help' for more information.\n", prog_name);
309 return(1);
310 };
311
312 for(pos = 0; (((data[pos].dec)) || ((data[pos].enc))); pos++)
313 {
314 dec = data[pos].dec;
315 enc = data[pos].enc;
316
317 if ( (!(dec)) || (!(enc)) )
318 continue;
319
320 snprintf(msg, sizeof(msg), "decoding \"%s\" ... ", enc);
321 printf("%-40s", msg);
322
323 len = bindle_decode(method, buff, sizeof(buff), enc, strlen(enc));
324 if (len == -1)
325 {
326 printf("FAIL -- %s\n", strerror(errno));
327 exit_code = 1;
328 } else {
329 buff[len] = '\0';
330 if (!(strcmp(dec, buff)))
331 {
332 printf("PASS\n");
333 } else {
334 printf("FAIL \"%s\"\n", buff);
335 exit_code = 1;
336 };
337 };
338 };
339
340 return(exit_code);
341}
342
343
344int
345bindle_test_encode(
346 const char * prog_name,
347 int argc,
348 char * argv[],
349 int method,
350 struct test_data * data )
351{
352 int opt;
353 int c;
354 int opt_index;
355 unsigned opts;
356 size_t pos;
357 char buff[24];
358 ssize_t len;
359 const char * dec;
360 const char * enc;
361 int exit_code;
362 int nopad;
363 char msg[128];
364
365 // getopt options
366 static char short_opt[] = "dhVvq";
367 static struct option long_opt[] =
368 {
369 {"debug", no_argument, NULL, 'd' },
370 {"help", no_argument, NULL, 'h' },
371 {"quiet", no_argument, NULL, 'q' },
372 {"silent", no_argument, NULL, 'q' },
373 {"version", no_argument, NULL, 'V' },
374 {"verbose", no_argument, NULL, 'v' },
375 { NULL, 0, NULL, 0 }
376 };
377
378 bindle_tests_initialize(prog_name);
379
380 opts = 0;
381 exit_code = 0;
382
383 while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1)
384 {
385 switch(c)
386 {
387 case -1: /* no more arguments */
388 case 0: /* long options toggles */
389 break;
390
391 case 'd':
392 opt = BNDL_DEBUG_ANY;
393 bindle_set_option(NULL, BNDL_OPT_DEBUG_LEVEL, &opt);
394 break;
395
396 case 'h':
397 printf("Usage: %s [OPTIONS]\n", prog_name);
398 printf("OPTIONS:\n");
399 printf(" -d, --debug print debug messages\n");
400 printf(" -h, --help print this help and exit\n");
401 printf(" -q, --quiet, --silent do not print messages\n");
402 printf(" -V, --version print version number and exit\n");
403 printf(" -v, --verbose print verbose messages\n");
404 printf("\n");
405 return(0);
406
407 case 'q':
408 opts |= BNDLTEST_OPT_QUIET;
409 opts &= ~BNDLTEST_OPT_VERBOSE;
410 break;
411
412 case 'V':
413 bindle_tests_version();
414 return(0);
415
416 case 'v':
417 opts |= BNDLTEST_OPT_VERBOSE;
418 opts &= ~BNDLTEST_OPT_QUIET;
419 break;
420
421 case '?':
422 fprintf(stderr, "Try `%s --help' for more information.\n", prog_name);
423 return(1);
424
425 default:
426 fprintf(stderr, "%s: unrecognized option `--%c'\n", prog_name, c);
427 fprintf(stderr, "Try `%s --help' for more information.\n", prog_name);
428 return(1);
429 };
430 };
431 if (optind < argc)
432 {
433 fprintf(stderr, "%s: unknown argument `%s'\n", prog_name, argv[optind]);
434 fprintf(stderr, "Try `%s --help' for more information.\n", prog_name);
435 return(1);
436 };
437
438 for(pos = 0; (((data[pos].dec)) || ((data[pos].enc))); pos++)
439 {
440 dec = data[pos].dec;
441 enc = data[pos].enc;
442 nopad = (int)data[pos].nopad;
443
444 if ( (!(dec)) || (!(enc)) )
445 continue;
446
447 snprintf(msg, sizeof(msg), "encoding \"%s\" ... ", dec);
448 printf("%-35s", msg);
449
450 len = bindle_encode(method, buff, sizeof(buff), dec, strlen(dec), nopad);
451 if (len == -1)
452 {
453 printf("FAIL -- %s\n", strerror(errno));
454 exit_code = 1;
455 } else {
456 buff[len] = '\0';
457 if (!(strcmp(enc, buff)))
458 {
459 printf("PASS\n");
460 } else {
461 printf("FAIL expected: \"%s\"; received: \"%s\"\n", enc, buff);
462 exit_code = 1;
463 };
464 };
465 };
466
467 return(exit_code);
468}
469
470
471int
472bindle_test_validate(
473 const char * prog_name,
474 int argc,
475 char * argv[],
476 int method,
477 struct test_data * data )
478{
479 int opt;
480 int c;
481 int opt_index;
482 unsigned opts;
483 size_t pos;
484 ssize_t rc;
485 ssize_t len;
486 const char * dec;
487 const char * enc;
488 int exit_code;
489 char msg[128];
490
491 // getopt options
492 static char short_opt[] = "dhVvq";
493 static struct option long_opt[] =
494 {
495 {"debug", no_argument, NULL, 'd' },
496 {"help", no_argument, NULL, 'h' },
497 {"quiet", no_argument, NULL, 'q' },
498 {"silent", no_argument, NULL, 'q' },
499 {"version", no_argument, NULL, 'V' },
500 {"verbose", no_argument, NULL, 'v' },
501 { NULL, 0, NULL, 0 }
502 };
503
504 bindle_tests_initialize(prog_name);
505
506 opts = 0;
507 exit_code = 0;
508
509 while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1)
510 {
511 switch(c)
512 {
513 case -1: /* no more arguments */
514 case 0: /* long options toggles */
515 break;
516
517 case 'd':
518 opt = BNDL_DEBUG_ANY;
519 bindle_set_option(NULL, BNDL_OPT_DEBUG_LEVEL, &opt);
520 break;
521
522 case 'h':
523 printf("Usage: %s [OPTIONS]\n", prog_name);
524 printf("OPTIONS:\n");
525 printf(" -d, --debug print debug messages\n");
526 printf(" -h, --help print this help and exit\n");
527 printf(" -q, --quiet, --silent do not print messages\n");
528 printf(" -V, --version print version number and exit\n");
529 printf(" -v, --verbose print verbose messages\n");
530 printf("\n");
531 return(0);
532
533 case 'q':
534 opts |= BNDLTEST_OPT_QUIET;
535 opts &= ~BNDLTEST_OPT_VERBOSE;
536 break;
537
538 case 'V':
539 bindle_tests_version();
540 return(0);
541
542 case 'v':
543 opts |= BNDLTEST_OPT_VERBOSE;
544 opts &= ~BNDLTEST_OPT_QUIET;
545 break;
546
547 case '?':
548 fprintf(stderr, "Try `%s --help' for more information.\n", prog_name);
549 return(1);
550
551 default:
552 fprintf(stderr, "%s: unrecognized option `--%c'\n", prog_name, c);
553 fprintf(stderr, "Try `%s --help' for more information.\n", prog_name);
554 return(1);
555 };
556 };
557 if (optind < argc)
558 {
559 fprintf(stderr, "%s: unknown argument `%s'\n", prog_name, argv[optind]);
560 fprintf(stderr, "Try `%s --help' for more information.\n", prog_name);
561 return(1);
562 };
563
564 for(pos = 0; ((data[pos].enc)); pos++)
565 {
566 dec = data[pos].dec;
567 enc = data[pos].enc;
568
569 snprintf(msg, sizeof(msg), "validating \"%s\" ... ", enc);
570 printf("%-45s", msg);
571
572 rc = bindle_encoding_verify(method, enc, strlen(enc));
573 len = ((dec)) ? ((ssize_t)strlen(dec)) : -1;
574
575 if ( (!(dec)) && (len >= 0) )
576 {
577 printf("FAIL -- validate passed bad string\n");
578 exit_code = 1;
579 } else if (len != rc)
580 {
581 printf("FAIL -- validate reported incorrect length\n");
582 exit_code = 1;
583 } else
584 {
585 printf(((dec)) ? "PASS\n" : "PASS (caught bad encoding)\n");
586 };
587 };
588
589 return(exit_code);
590}
591
592/* end of source file */
diff --git a/checks/bindle-enc-strings.h b/checks/bindle-enc-strings.h
new file mode 100644
index 0000000..1c33cc8
--- /dev/null
+++ b/checks/bindle-enc-strings.h
@@ -0,0 +1,110 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#ifndef _TESTS_BINDLE_ENC_STRINGS_H
32#define _TESTS_BINDLE_ENC_STRINGS_H 1
33
34///////////////
35// //
36// Headers //
37// //
38///////////////
39#pragma mark - Headers
40
41#include "bindle-tests.h"
42
43#include <string.h>
44#include <strings.h>
45#include <stdlib.h>
46
47
48/////////////////
49// //
50// Datatypes //
51// //
52/////////////////
53#pragma mark - Datatypes
54
55struct test_data
56{
57 const char * dec;
58 const char * enc;
59 intptr_t nopad;
60};
61
62
63/////////////////
64// //
65// Variables //
66// //
67/////////////////
68#pragma mark - Variables
69
70extern struct test_data base32_strings[];
71extern struct test_data base32hex_strings[];
72extern struct test_data base64_strings[];
73extern struct test_data crockford_strings[];
74extern struct test_data hex_strings[];
75
76
77//////////////////
78// //
79// Prototypes //
80// //
81//////////////////
82#pragma mark - Prototypes
83
84int
85bindle_test_decode(
86 const char * prog_name,
87 int argc,
88 char * argv[],
89 int method,
90 struct test_data * data );
91
92
93int
94bindle_test_encode(
95 const char * prog_name,
96 int argc,
97 char * argv[],
98 int method,
99 struct test_data * data );
100
101
102int
103bindle_test_validate(
104 const char * prog_name,
105 int argc,
106 char * argv[],
107 int method,
108 struct test_data * data );
109
110#endif /* end of header file */
diff --git a/include/bindle.h b/include/bindle.h
index 1df829d..efbbbe4 100644
--- a/include/bindle.h
+++ b/include/bindle.h
@@ -139,6 +139,15 @@
139#define BNDL_ARRAY_MASK ( BNDL_ARRAY_MASK_ACTION | BNDL_ARRAY_MASK_DUPS ) ///< mask of all sorted array options 139#define BNDL_ARRAY_MASK ( BNDL_ARRAY_MASK_ACTION | BNDL_ARRAY_MASK_DUPS ) ///< mask of all sorted array options
140 140
141 141
142// encoding methods
143#define BNDL_NONE 0
144#define BNDL_BASE32 1
145#define BNDL_BASE32HEX 2
146#define BNDL_BASE64 3
147#define BNDL_HEX 4
148#define BNDL_CROCKFORD 5
149
150
142////////////////// 151//////////////////
143// // 152// //
144// Data Types // 153// Data Types //
@@ -303,6 +312,49 @@ bindle_debug(
303 ... ); 312 ... );
304 313
305 314
315//---------------------//
316// encoding prototypes //
317//---------------------//
318#pragma mark encoding prototypes
319
320_BINDLE_F ssize_t
321bindle_decode(
322 int method,
323 void * dst,
324 size_t s,
325 const char * src,
326 size_t n );
327
328
329_BINDLE_F ssize_t
330bindle_decode_size(
331 int method,
332 size_t n );
333
334
335_BINDLE_F ssize_t
336bindle_encode(
337 int method,
338 char * dst,
339 size_t s,
340 const void * src,
341 size_t n,
342 int nopad );
343
344
345_BINDLE_F ssize_t
346bindle_encode_size(
347 int method,
348 size_t n );
349
350
351_BINDLE_F ssize_t
352bindle_encoding_verify(
353 int method,
354 const char * src,
355 size_t n );
356
357
306//-----------------// 358//-----------------//
307// file prototypes // 359// file prototypes //
308//-----------------// 360//-----------------//
diff --git a/lib/libbindle/lencoding.c b/lib/libbindle/lencoding.c
new file mode 100644
index 0000000..4c604fe
--- /dev/null
+++ b/lib/libbindle/lencoding.c
@@ -0,0 +1,1084 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _LIB_LIBBINDLE_LENCODING_C 1
32#include "lencoding.h"
33
34///////////////
35// //
36// Headers //
37// //
38///////////////
39#pragma mark - Headers
40
41#include <errno.h>
42#include <stdarg.h>
43#include <string.h>
44#include <strings.h>
45#include <stdlib.h>
46#include <assert.h>
47#include <errno.h>
48
49
50//////////////////
51// //
52// Prototypes //
53// //
54//////////////////
55#pragma mark - Prototypes
56
57static ssize_t
58bindle_base32_decode(
59 const int8_t * map,
60 uint8_t * dst,
61 size_t s,
62 const char * src,
63 size_t n );
64
65
66static ssize_t
67bindle_base32_encode(
68 const char * map,
69 char * dst,
70 size_t s,
71 const int8_t * src,
72 size_t n,
73 int nopad );
74
75
76static ssize_t
77bindle_base32_verify(
78 const int8_t * map,
79 const char * src,
80 size_t n );
81
82
83static ssize_t
84bindle_base64_decode(
85 const int8_t * map,
86 uint8_t * dst,
87 size_t s,
88 const char * src,
89 size_t n );
90
91
92static ssize_t
93bindle_base64_encode(
94 const char * map,
95 char * dst,
96 size_t s,
97 const int8_t * src,
98 size_t n,
99 int nopad );
100
101
102static ssize_t
103bindle_base64_verify(
104 const int8_t * map,
105 const char * src,
106 size_t n );
107
108
109static ssize_t
110bindle_hex_decode(
111 const int8_t * map,
112 uint8_t * dst,
113 size_t s,
114 const char * src,
115 size_t n );
116
117
118static ssize_t
119bindle_hex_encode(
120 const char * map,
121 char * dst,
122 size_t s,
123 const int8_t * src,
124 size_t n );
125
126
127static ssize_t
128bindle_hex_verify(
129 const int8_t * map,
130 const char * src,
131 size_t n );
132
133
134static int
135bindle_encode_method(
136 int method );
137
138
139ssize_t
140bindle_none_decode(
141 uint8_t * dst,
142 size_t s,
143 const char * src,
144 size_t n );
145
146
147ssize_t
148bindle_none_encode(
149 char * dst,
150 size_t s,
151 const int8_t * src,
152 size_t n );
153
154
155/////////////////
156// //
157// Variables //
158// //
159/////////////////
160#pragma mark - Variables
161
162#pragma mark base32_vals[]
163static const int8_t base32_vals[256] =
164{
165// This map cheats and interprets:
166// - the numeral zero as the letter "O" as in oscar
167// - the numeral one as the letter "L" as in lima
168// - the numeral eight as the letter "B" as in bravo
169// 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
170 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00
171 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10
172 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x20
173 14, 11, 26, 27, 28, 29, 30, 31, 1, -1, -1, -1, -1, 0, -1, -1, // 0x30
174 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 0x40
175 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, // 0x50
176 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 0x60
177 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, -1, -1, -1, -1, // 0x70
178 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x80
179 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x90
180 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xA0
181 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xB0
182 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xC0
183 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xD0
184 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xE0
185 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xF0
186};
187#pragma mark base32_chars[]
188static const char * base32_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=";
189
190
191#pragma mark base32hex_vals[]
192static const int8_t base32hex_vals[256] =
193{
194// 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
195 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00
196 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10
197 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x20
198 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, 0, -1, -1, // 0x30
199 -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // 0x40
200 25, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x50
201 -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // 0x60
202 25, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x70
203 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x80
204 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x90
205 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xA0
206 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xB0
207 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xC0
208 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xD0
209 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xE0
210 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xF0
211};
212#pragma mark base32hex_chars[]
213static const char * base32hex_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV=";
214
215
216#pragma mark base64_vals[]
217static const int8_t base64_vals[256] =
218{
219// 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
220 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00
221 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10
222 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, // 0x20
223 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, 0, -1, -1, // 0x30
224 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 0x40
225 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, // 0x50
226 -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 0x60
227 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, // 0x70
228 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x80
229 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x90
230 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xA0
231 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xB0
232 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xC0
233 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xD0
234 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xE0
235 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xF0
236};
237#pragma mark base64_chars[]
238static const char * base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
239
240
241#pragma mark crockford_vals[]
242static const int8_t crockford_vals[256] =
243{
244// 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
245 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00
246 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10
247 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x20
248 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, // 0x30
249 -1, 10, 11, 12, 13, 14, 15, 16, 17, 1, 18, 19, 1, 20, 21, 0, // 0x40
250 22, 23, 24, 25, 26, -1, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, // 0x50
251 -1, 10, 11, 12, 13, 14, 15, 16, 17, 1, 18, 19, 1, 20, 21, 0, // 0x60
252 22, 23, 24, 25, 26, -1, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, // 0x70
253 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x80
254 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x90
255 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xA0
256 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xB0
257 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xC0
258 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xD0
259 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xE0
260 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xF0
261};
262#pragma mark crockford_chars[]
263static const char * crockford_chars = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
264
265
266#pragma mark hex_vals[]
267static const int8_t hex_vals[256] =
268{
269// 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
270 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00
271 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10
272 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x20
273 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, // 0x30
274 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x40
275 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x50
276 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x60
277 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x70
278 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x80
279 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x90
280 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xA0
281 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xB0
282 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xC0
283 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xD0
284 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xE0
285 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xF0
286};
287#pragma mark hex_chars[]
288static const char * hex_chars = "0123456789abcdef";
289
290
291/////////////////
292// //
293// Functions //
294// //
295/////////////////
296#pragma mark - Functions
297
298//------------------//
299// base32 functions //
300//------------------//
301#pragma mark base32 functions
302
303ssize_t
304bindle_base32_decode(
305 const int8_t * map,
306 uint8_t * dst,
307 size_t s,
308 const char * src,
309 size_t n )
310{
311 size_t datlen;
312 size_t pos;
313 ssize_t rc;
314
315 assert(dst != NULL);
316 assert(src != NULL);
317 assert(s > 0);
318
319 // verifies encoded data contains only valid characters
320 if ((rc = bindle_base32_verify(map, (const char *)src, n)) == -1)
321 return(-1);
322 if ( (rc > (ssize_t)s) && ((dst)) )
323 {
324 errno = ENOBUFS;
325 return(-1);
326 };
327
328 // decodes base32 encoded data
329 datlen = 0;
330 for(pos = 0; (pos < n); pos++)
331 {
332 // MSB is Most Significant Bits (0x80 == 10000000 ~= MSB)
333 // MB is middle bits (0x7E == 01111110 ~= MB)
334 // LSB is Least Significant Bits (0x01 == 00000001 ~= LSB)
335 switch(pos%8)
336 {
337 // byte 0
338 case 1:
339 dst[datlen] = (map[(unsigned char)src[pos-1]] << 3) & 0xF8; // 5 MSB
340 dst[datlen] |= (map[(unsigned char)src[pos-0]] >> 2) & 0x07; // 3 LSB
341 datlen++;
342 break;
343
344 // byte 1
345 case 3:
346 dst[datlen] = (map[(unsigned char)src[pos-2]] << 6) & 0xC0; // 2 MSB
347 dst[datlen] |= (map[(unsigned char)src[pos-1]] << 1) & 0x3E; // 5 MB
348 dst[datlen] |= (map[(unsigned char)src[pos-0]] >> 4) & 0x01; // 1 LSB
349 datlen++;
350 break;
351
352 // byte 2
353 case 4:
354 dst[datlen] = (map[(unsigned char)src[pos-1]] << 4) & 0xF0; // 4 MSB
355 dst[datlen] |= (map[(unsigned char)src[pos-0]] >> 1) & 0x0F; // 4 LSB
356 datlen++;
357 break;
358
359 // byte 3
360 case 6:
361 dst[datlen] = (map[(unsigned char)src[pos-2]] << 7) & 0x80; // 1 MSB
362 dst[datlen] |= (map[(unsigned char)src[pos-1]] << 2) & 0x7C; // 5 MB
363 dst[datlen] |= (map[(unsigned char)src[pos-0]] >> 3) & 0x03; // 2 LSB
364 datlen++;
365 break;
366
367 // byte 4
368 case 7:
369 dst[datlen] = (map[(unsigned char)src[pos-1]] << 5) & 0xE0; // 3 MSB
370 dst[datlen] |= (map[(unsigned char)src[pos-0]] >> 0) & 0x1F; // 5 LSB
371 datlen++;
372
373 default:
374 if (src[pos] == '=')
375 return((ssize_t)datlen);
376 break;
377 };
378 };
379
380 return((ssize_t)datlen);
381}
382
383
384ssize_t
385bindle_base32_encode(
386 const char * map,
387 char * dst,
388 size_t s,
389 const int8_t * src,
390 size_t n,
391 int nopad )
392{
393 ssize_t len;
394 size_t dpos;
395 size_t spos;
396 size_t byte;
397
398 assert(dst != NULL);
399 assert(src != NULL);
400 assert(s > 0);
401
402 // calculates each digit's value
403 byte = 0;
404 dpos = 0;
405 for(spos = 0; (spos < n); spos++)
406 {
407 // MSB is Most Significant Bits (0x80 == 10000000 ~= MSB)
408 // MB is middle bits (0x7E == 01111110 ~= MB)
409 // LSB is Least Significant Bits (0x01 == 00000001 ~= LSB)
410 switch(byte)
411 {
412 case 0:
413 dst[dpos++] = src[spos] >> 3; // 5 MSB
414 dst[dpos++] = (src[spos] & 0x07) << 2; // 3 LSB 2 bits unused
415 byte++;
416 break;
417
418 case 1:
419 dst[dpos-1] |= (src[spos] >> 6) & 0x03; // 2 MSB
420 dst[dpos++] = (src[spos] >> 1) & 0x1f ; // 5 MB
421 dst[dpos++] = (src[spos] << 4) & 0x10; // 1 LSB 4 bits unused
422 byte++;
423 break;
424
425 case 2:
426 dst[dpos-1] |= src[spos] >> 4; // 4 MSB
427 dst[dpos++] = (src[spos] << 1) & 0x1e ; // 4 LSB 1 bits unused
428 byte++;
429 break;
430
431 case 3:
432 dst[dpos-1] |= src[spos] >> 7; // 1 MSB
433 dst[dpos++] = (src[spos] >> 2) & 0x1f ; // 5 MB
434 dst[dpos++] = (src[spos] << 3) & 0x18 ; // 2 LSB 3 bits unused
435 byte++;
436 break;
437
438 case 4:
439 dst[dpos-1] |= src[spos] >> 5; // 3 MSB
440 dst[dpos++] = src[spos] & 0x1f; // 5 LSB
441 byte = 0;
442 break;
443 };
444 };
445
446 // encodes each value
447 for(len = 0; ((size_t)len) < dpos; len++)
448 dst[len] = map[(unsigned char)dst[len]];
449
450 // add padding
451 if (!(nopad))
452 for(; ((len % 8)); len++)
453 dst[len] = '=';
454
455 dst[len] = '\0';
456
457 return(len);
458}
459
460
461ssize_t
462bindle_base32_verify(
463 const int8_t * map,
464 const char * src,
465 size_t n )
466{
467 size_t pos;
468 size_t datlen;
469
470 assert(map != NULL);
471 assert(src != NULL);
472
473 datlen = 0;
474
475 // verifies encoded data contains only valid characters
476 for(pos = 0; (pos < n); pos++)
477 {
478 // verify that data is valid character
479 if (map[(unsigned char)src[pos]] == -1)
480 {
481 errno = EINVAL;
482 return(-1);
483 };
484 // verify valid use of padding
485 if (src[pos] != '=')
486 continue;
487 if (!(datlen))
488 datlen = pos;
489 if ((pos % 8) < 2)
490 {
491 errno = EINVAL;
492 return(-1);
493 };
494 if ((pos + (8-(pos%8))) != n)
495 {
496 errno = EINVAL;
497 return(-1);
498 };
499 for(; (pos < n); pos++)
500 {
501 if (src[pos] != '=')
502 {
503 errno = EINVAL;
504 return(-1);
505 };
506 };
507 };
508
509 if (!(datlen))
510 datlen = pos;
511
512 switch(datlen % 8)
513 {
514 case 0:
515 case 2:
516 case 4:
517 case 5:
518 case 7:
519 break;
520
521 case 1:
522 case 3:
523 case 6:
524 default:
525 return(-1);
526 };
527
528 return((datlen * 5) / 8);
529}
530
531
532//------------------//
533// base64 functions //
534//------------------//
535#pragma mark base64 functions
536
537ssize_t
538bindle_base64_decode(
539 const int8_t * map,
540 uint8_t * dst,
541 size_t s,
542 const char * src,
543 size_t n )
544{
545 size_t datlen;
546 size_t pos;
547 ssize_t rc;
548
549 assert(dst != NULL);
550 assert(src != NULL);
551 assert(s > 0);
552
553 // verifies encoded data contains only valid characters
554 if ((rc = bindle_base64_verify(map, (const char *)src, n)) == -1)
555 return(-1);
556 if ( (rc > (ssize_t)s) && ((dst)) )
557 {
558 errno = ENOBUFS;
559 return(-1);
560 };
561
562 // decodes base64 encoded data
563 datlen = 0;
564 for(pos = 0; (pos < n); pos++)
565 {
566 // MSB is Most Significant Bits (0x80 == 10000000 ~= MSB)
567 // MB is middle bits (0x7E == 01111110 ~= MB)
568 // LSB is Least Significant Bits (0x01 == 00000001 ~= LSB)
569 switch(pos%4)
570 {
571 // byte 0
572 case 0:
573 dst[datlen++] = (map[(unsigned char)src[pos]] & 0x3f) << 2; // 6 MSB
574 break;
575
576 // byte 1
577 case 1:
578 dst[datlen-1] |= (map[(unsigned char)src[pos]] & 0x30) >> 4; // 2 LSB
579 dst[datlen++] = (map[(unsigned char)src[pos]] & 0x0f) << 4; // 4 MSB
580 break;
581
582 // byte 2
583 case 2:
584 dst[datlen-1] |= (map[(unsigned char)src[pos]] & 0x3c) >> 2; // 4 MSB
585 dst[datlen++] = (map[(unsigned char)src[pos]] & 0x03) << 6; // 2 LSB
586 break;
587
588 // byte 3
589 case 3:
590 dst[datlen-1] |= (map[(unsigned char)src[pos]] & 0x3f); // 1 MSB
591 break;
592 };
593 };
594 return((ssize_t)datlen);
595}
596
597
598ssize_t
599bindle_base64_encode(
600 const char * map,
601 char * dst,
602 size_t s,
603 const int8_t * src,
604 size_t n,
605 int nopad )
606{
607 ssize_t len;
608 size_t dpos;
609 size_t spos;
610 size_t byte;
611
612 assert(dst != NULL);
613 assert(src != NULL);
614 assert(s > 0);
615
616 // calculates each digit's value
617 byte = 0;
618 dpos = 0;
619 for(spos = 0; (spos < n); spos++)
620 {
621 // MSB is Most Significant Bits (0x80 == 10000000 ~= MSB)
622 // MB is middle bits (0x7E == 01111110 ~= MB)
623 // LSB is Least Significant Bits (0x01 == 00000001 ~= LSB)
624 switch(byte)
625 {
626 case 0:
627 dst[dpos++] = (src[spos] & 0xfc) >> 2; // 6 MSB
628 dst[dpos++] = (src[spos] & 0x03) << 4; // 2 LSB
629 byte++;
630 break;
631
632 case 1:
633 dst[dpos-1] |= (src[spos] & 0xf0) >> 4; // 4 MSB
634 dst[dpos++] = (src[spos] & 0x0f) << 2; // 4 LSB
635 byte++;
636 break;
637
638 case 2:
639 dst[dpos-1] |= (src[spos] & 0xc0) >> 6; // 2 MSB
640 dst[dpos++] = src[spos] & 0x3f; // 6 LSB
641 byte = 0;
642 break;
643 };
644 };
645
646 // encodes each value
647 for(len = 0; ((size_t)len) < dpos; len++)
648 dst[len] = map[(unsigned char)dst[len]];
649
650 // add padding
651 if (!(nopad))
652 for(; ((len % 4)); len++)
653 dst[len] = '=';
654
655 dst[len] = '\0';
656
657 return(len);
658}
659
660
661ssize_t
662bindle_base64_verify(
663 const int8_t * map,
664 const char * src,
665 size_t n )
666{
667 size_t pos;
668 size_t datlen;
669
670 assert(map != NULL);
671 assert(src != NULL);
672
673 datlen = 0;
674
675 // verifies encoded data contains only valid characters
676 for(pos = 0; (pos < n); pos++)
677 {
678 // verify that data is valid character
679 if (map[(unsigned char)src[pos]] == -1)
680 return(-1);
681 // verify valid use of padding
682 if (src[pos] != '=')
683 continue;
684 if (!(datlen))
685 datlen = pos;
686 if ((pos % 4) < 2)
687 return(-1);
688 if ((pos + (4-(pos%4))) != n)
689 return(-1);
690 for(; (pos < n); pos++)
691 if (src[pos] != '=')
692 return(-1);
693 };
694
695 if (!(datlen))
696 datlen = pos;
697
698 switch(datlen % 4)
699 {
700 case 0:
701 case 2:
702 case 3:
703 break;
704
705 case 1:
706 default:
707 return(-1);
708 };
709
710 return((datlen * 6) / 8);
711}
712
713
714//---------------//
715// hex functions //
716//---------------//
717#pragma mark hex functions
718
719ssize_t
720bindle_hex_decode(
721 const int8_t * map,
722 uint8_t * dst,
723 size_t s,
724 const char * src,
725 size_t n )
726{
727 size_t datlen;
728 size_t pos;
729 ssize_t rc;
730
731 assert(dst != NULL);
732 assert(src != NULL);
733 assert(s > 0);
734
735 // verifies encoded data contains only valid characters
736 if ((rc = bindle_base64_verify(map, (const char *)src, n)) == -1)
737 return(-1);
738 if ( (rc > (ssize_t)s) && ((dst)) )
739 {
740 errno = ENOBUFS;
741 return(-1);
742 };
743
744 // decodes base64 encoded data
745 datlen = 0;
746 for(pos = 0; (pos < n); pos++)
747 {
748 switch(pos%2)
749 {
750 // byte 0
751 case 0:
752 dst[datlen++] = (map[(unsigned char)src[pos]] & 0x0f) << 4;
753 break;
754
755 // byte 1
756 case 1:
757 dst[datlen-1] |= map[(unsigned char)src[pos]] & 0x0f;
758 break;
759 };
760 };
761
762 return((ssize_t)datlen);
763}
764
765
766ssize_t
767bindle_hex_encode(
768 const char * map,
769 char * dst,
770 size_t s,
771 const int8_t * src,
772 size_t n )
773{
774 ssize_t len;
775 size_t dpos;
776 size_t spos;
777
778 assert(dst != NULL);
779 assert(src != NULL);
780 assert(s > 0);
781
782 // calculates each digit's value
783 dpos = 0;
784 for(spos = 0; (spos < n); spos++)
785 {
786 dst[dpos++] = (src[spos] & 0xf0) >> 4;
787 dst[dpos++] = (src[spos] & 0x0f);
788 };
789
790 // encodes each value
791 for(len = 0; ((size_t)len) < dpos; len++)
792 dst[len] = map[(unsigned char)dst[len]];
793
794 dst[len] = '\0';
795
796 return(len);
797}
798
799
800ssize_t
801bindle_hex_verify(
802 const int8_t * map,
803 const char * src,
804 size_t n )
805{
806 size_t pos;
807
808 assert(map != NULL);
809 assert(src != NULL);
810
811 if ((n%2))
812 return(-1);
813
814 for(pos = 0; (pos < n); pos++)
815 if (map[(unsigned char)src[pos]] == -1)
816 return(-1);
817
818 return(n/2);
819}
820
821
822//----------------//
823// none functions //
824//----------------//
825#pragma mark none functions
826
827ssize_t
828bindle_none_decode(
829 uint8_t * dst,
830 size_t s,
831 const char * src,
832 size_t n )
833{
834 assert(dst != NULL);
835 assert(src != NULL);
836 if (n > s)
837 {
838 errno = ENOBUFS;
839 return(-1);
840 };
841 memcpy(dst, src, n);
842 return((ssize_t)n);
843}
844
845
846ssize_t
847bindle_none_encode(
848 char * dst,
849 size_t s,
850 const int8_t * src,
851 size_t n )
852{
853 assert(dst != NULL);
854 assert(src != NULL);
855
856 if (n > s)
857 {
858 errno = ENOBUFS;
859 return(-1);
860 };
861 memcpy(dst, src, n);
862
863 return((ssize_t)n);
864}
865
866
867//--------------------//
868// frontend functions //
869//--------------------//
870#pragma mark frontend functions
871
872ssize_t
873bindle_decode(
874 int method,
875 void * dst,
876 size_t s,
877 const char * src,
878 size_t n )
879{
880 assert(dst != NULL);
881 assert(src != NULL);
882
883 // validate encoding method
884 if (bindle_encode_method(method) == -1)
885 return(-1);
886
887 switch(method)
888 {
889 case BNDL_BASE32:
890 return(bindle_base32_decode(base32_vals, dst, s, src, n));
891
892 case BNDL_BASE32HEX:
893 return(bindle_base32_decode(base32hex_vals, dst, s, src, n));
894
895 case BNDL_BASE64:
896 return(bindle_base64_decode(base64_vals, dst, s, src, n));
897
898 case BNDL_CROCKFORD:
899 return(bindle_base32_decode(crockford_vals, dst, s, src, n));
900
901 case BNDL_HEX:
902 return(bindle_hex_decode(hex_vals, dst, s, src, n));
903
904 case BNDL_NONE:
905 return(bindle_none_decode(dst, s, src, n));
906
907 default:
908 break;
909 };
910
911 errno = ENOTSUP;
912 return(-1);
913}
914
915
916ssize_t
917bindle_decode_size(
918 int method,
919 size_t n )
920{
921 switch(method)
922 {
923 case BNDL_BASE32:
924 case BNDL_BASE32HEX:
925 case BNDL_CROCKFORD:
926 return( ((n / 8) + (((n % 8)) ? 1 : 0)) * 5 );
927
928 case BNDL_BASE64:
929 return( ((n / 4) + (((n % 4)) ? 1 : 0)) * 3 );
930
931 case BNDL_HEX:
932 return( (n / 2) + (((n % 2)) ? 1 : 0) );
933
934 case BNDL_NONE:
935 return((ssize_t)n);
936
937 default:
938 break;
939 };
940
941 return(-1);
942}
943
944
945ssize_t
946bindle_encode(
947 int method,
948 char * dst,
949 size_t s,
950 const void * src,
951 size_t n,
952 int nopad )
953{
954 assert(dst != NULL);
955 assert(src != NULL);
956
957 // validate encoding method
958 if (bindle_encode_method(method) == -1)
959 return(-1);
960
961 // validates buffer is big enough
962 if (s < (size_t)bindle_encode_size(method, n))
963 {
964 errno = ENOBUFS;
965 return(-1);
966 };
967
968 switch(method)
969 {
970 case BNDL_BASE32:
971 return(bindle_base32_encode(base32_chars, dst, s, src, n, nopad));
972
973 case BNDL_BASE32HEX:
974 return(bindle_base32_encode(base32hex_chars, dst, s, src, n, nopad));
975
976 case BNDL_BASE64:
977 return(bindle_base64_encode(base64_chars, dst, s, src, n, nopad));
978
979 case BNDL_CROCKFORD:
980 return(bindle_base32_encode(crockford_chars, dst, s, src, n, 1));
981
982 case BNDL_HEX:
983 return(bindle_hex_encode(hex_chars, dst, s, src, n));
984
985 case BNDL_NONE:
986 return(bindle_none_encode(dst, s, src, n));
987
988 default:
989 errno = ENOTSUP;
990 break;
991 };
992
993 return(-1);
994}
995
996
997int
998bindle_encode_method(
999 int method )
1000{
1001 switch(method)
1002 {
1003 case BNDL_BASE32:
1004 case BNDL_BASE32HEX:
1005 case BNDL_BASE64:
1006 case BNDL_CROCKFORD:
1007 case BNDL_HEX:
1008 case BNDL_NONE:
1009 return(method);
1010
1011 default:
1012 errno = ENOTSUP;
1013 break;
1014 };
1015 return(-1);
1016}
1017
1018
1019ssize_t
1020bindle_encode_size(
1021 int method,
1022 size_t n )
1023{
1024 switch(method)
1025 {
1026 case BNDL_BASE32:
1027 case BNDL_BASE32HEX:
1028 case BNDL_CROCKFORD:
1029 return( ((n / 5) + (((n % 5)) ? 1 : 0)) * 8 );
1030
1031 case BNDL_BASE64:
1032 return( ((n / 3) + (((n % 3)) ? 1 : 0)) * 4 );
1033
1034 case BNDL_HEX:
1035 return( (ssize_t)(n * 2) );
1036
1037 case BNDL_NONE:
1038 return((ssize_t)n);
1039
1040 default:
1041 errno = ENOTSUP;
1042 break;
1043 };
1044
1045 return(-1);
1046}
1047
1048
1049ssize_t
1050bindle_encoding_verify(
1051 int method,
1052 const char * src,
1053 size_t n )
1054{
1055 switch(method)
1056 {
1057 case BNDL_BASE32:
1058 return(bindle_base32_verify(base32_vals, src, n));
1059
1060 case BNDL_BASE32HEX:
1061 return(bindle_base32_verify(base32hex_vals, src, n));
1062
1063 case BNDL_BASE64:
1064 return(bindle_base64_verify(base64_vals, src, n));
1065
1066 case BNDL_CROCKFORD:
1067 return(bindle_base32_verify(crockford_vals, src, n));
1068
1069 case BNDL_HEX:
1070 return(bindle_hex_verify(hex_vals, src, n));
1071
1072 case BNDL_NONE:
1073 return((ssize_t)n);
1074
1075 default:
1076 errno = ENOTSUP;
1077 break;
1078 };
1079
1080 return(-1);
1081}
1082
1083
1084/* end of source file */
diff --git a/lib/libbindle/lencoding.h b/lib/libbindle/lencoding.h
new file mode 100644
index 0000000..1513903
--- /dev/null
+++ b/lib/libbindle/lencoding.h
@@ -0,0 +1,45 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#ifndef _LIB_LIBBINDLE_LENCODING_H
32#define _LIB_LIBBINDLE_LENCODING_H 1
33
34
35///////////////
36// //
37// Headers //
38// //
39///////////////
40#pragma mark - Headers
41
42#include "libbindle.h"
43
44
45#endif /* end of header file */