ffi-hydrogen 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +30 -0
- data/.travis.yml +10 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +72 -0
- data/Rakefile +46 -0
- data/bench/both.rb +86 -0
- data/bench/encode.rb +57 -0
- data/bench/encrypt.rb +80 -0
- data/bench/init.rb +5 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ffi-hydrogen.gemspec +31 -0
- data/lib/ffi/hydrogen.rb +216 -0
- data/vendor/.clang-format +2 -0
- data/vendor/.gitignore +3 -0
- data/vendor/README.md +2 -0
- data/vendor/libhydrogen/.clang-format +95 -0
- data/vendor/libhydrogen/.gitignore +32 -0
- data/vendor/libhydrogen/.travis.yml +22 -0
- data/vendor/libhydrogen/LICENSE +18 -0
- data/vendor/libhydrogen/Makefile +61 -0
- data/vendor/libhydrogen/Makefile.arduino +51 -0
- data/vendor/libhydrogen/README.md +29 -0
- data/vendor/libhydrogen/hydrogen.c +18 -0
- data/vendor/libhydrogen/hydrogen.h +317 -0
- data/vendor/libhydrogen/impl/common.h +316 -0
- data/vendor/libhydrogen/impl/core.h +220 -0
- data/vendor/libhydrogen/impl/gimli-core/portable.h +39 -0
- data/vendor/libhydrogen/impl/gimli-core/sse2.h +97 -0
- data/vendor/libhydrogen/impl/gimli-core.h +25 -0
- data/vendor/libhydrogen/impl/hash.h +138 -0
- data/vendor/libhydrogen/impl/hydrogen_p.h +83 -0
- data/vendor/libhydrogen/impl/kdf.h +20 -0
- data/vendor/libhydrogen/impl/kx.h +441 -0
- data/vendor/libhydrogen/impl/pwhash.h +281 -0
- data/vendor/libhydrogen/impl/random.h +376 -0
- data/vendor/libhydrogen/impl/secretbox.h +236 -0
- data/vendor/libhydrogen/impl/sign.h +207 -0
- data/vendor/libhydrogen/impl/x25519.h +383 -0
- data/vendor/libhydrogen/library.properties +10 -0
- data/vendor/libhydrogen/logo.png +0 -0
- data/vendor/libhydrogen/tests/tests.c +431 -0
- data/vendor/main.c +140 -0
- data/vendor/stringencoders/.gitignore +25 -0
- data/vendor/stringencoders/.travis.yml +13 -0
- data/vendor/stringencoders/AUTHORS +1 -0
- data/vendor/stringencoders/COPYING +2 -0
- data/vendor/stringencoders/ChangeLog +170 -0
- data/vendor/stringencoders/Doxyfile +276 -0
- data/vendor/stringencoders/INSTALL +119 -0
- data/vendor/stringencoders/LICENSE +22 -0
- data/vendor/stringencoders/Makefile.am +3 -0
- data/vendor/stringencoders/NEWS +3 -0
- data/vendor/stringencoders/README +2 -0
- data/vendor/stringencoders/README.md +32 -0
- data/vendor/stringencoders/bootstrap.sh +3 -0
- data/vendor/stringencoders/configure-gcc-hardened.sh +16 -0
- data/vendor/stringencoders/configure.ac +44 -0
- data/vendor/stringencoders/doxy/footer.html +34 -0
- data/vendor/stringencoders/doxy/header.html +85 -0
- data/vendor/stringencoders/indent.sh +9 -0
- data/vendor/stringencoders/javascript/base64-speed.html +43 -0
- data/vendor/stringencoders/javascript/base64-test.html +209 -0
- data/vendor/stringencoders/javascript/base64.html +18 -0
- data/vendor/stringencoders/javascript/base64.js +176 -0
- data/vendor/stringencoders/javascript/qunit.css +119 -0
- data/vendor/stringencoders/javascript/qunit.js +1062 -0
- data/vendor/stringencoders/javascript/urlparse-test.html +367 -0
- data/vendor/stringencoders/javascript/urlparse.js +328 -0
- data/vendor/stringencoders/make-ci.sh +13 -0
- data/vendor/stringencoders/makerelease.sh +16 -0
- data/vendor/stringencoders/python/b85.py +176 -0
- data/vendor/stringencoders/src/Makefile.am +134 -0
- data/vendor/stringencoders/src/arraytoc.c +85 -0
- data/vendor/stringencoders/src/arraytoc.h +43 -0
- data/vendor/stringencoders/src/extern_c_begin.h +3 -0
- data/vendor/stringencoders/src/extern_c_end.h +3 -0
- data/vendor/stringencoders/src/html_named_entities_generator.py +203 -0
- data/vendor/stringencoders/src/modp_ascii.c +159 -0
- data/vendor/stringencoders/src/modp_ascii.h +162 -0
- data/vendor/stringencoders/src/modp_ascii_data.h +84 -0
- data/vendor/stringencoders/src/modp_ascii_gen.c +55 -0
- data/vendor/stringencoders/src/modp_b16.c +125 -0
- data/vendor/stringencoders/src/modp_b16.h +148 -0
- data/vendor/stringencoders/src/modp_b16_data.h +104 -0
- data/vendor/stringencoders/src/modp_b16_gen.c +65 -0
- data/vendor/stringencoders/src/modp_b2.c +69 -0
- data/vendor/stringencoders/src/modp_b2.h +130 -0
- data/vendor/stringencoders/src/modp_b2_data.h +44 -0
- data/vendor/stringencoders/src/modp_b2_gen.c +36 -0
- data/vendor/stringencoders/src/modp_b36.c +108 -0
- data/vendor/stringencoders/src/modp_b36.h +170 -0
- data/vendor/stringencoders/src/modp_b64.c +254 -0
- data/vendor/stringencoders/src/modp_b64.h +236 -0
- data/vendor/stringencoders/src/modp_b64_data.h +477 -0
- data/vendor/stringencoders/src/modp_b64_gen.c +168 -0
- data/vendor/stringencoders/src/modp_b64r.c +254 -0
- data/vendor/stringencoders/src/modp_b64r.h +242 -0
- data/vendor/stringencoders/src/modp_b64r_data.h +477 -0
- data/vendor/stringencoders/src/modp_b64w.c +254 -0
- data/vendor/stringencoders/src/modp_b64w.h +231 -0
- data/vendor/stringencoders/src/modp_b64w_data.h +477 -0
- data/vendor/stringencoders/src/modp_b85.c +109 -0
- data/vendor/stringencoders/src/modp_b85.h +171 -0
- data/vendor/stringencoders/src/modp_b85_data.h +36 -0
- data/vendor/stringencoders/src/modp_b85_gen.c +65 -0
- data/vendor/stringencoders/src/modp_bjavascript.c +65 -0
- data/vendor/stringencoders/src/modp_bjavascript.h +105 -0
- data/vendor/stringencoders/src/modp_bjavascript_data.h +84 -0
- data/vendor/stringencoders/src/modp_bjavascript_gen.c +58 -0
- data/vendor/stringencoders/src/modp_burl.c +228 -0
- data/vendor/stringencoders/src/modp_burl.h +259 -0
- data/vendor/stringencoders/src/modp_burl_data.h +136 -0
- data/vendor/stringencoders/src/modp_burl_gen.c +121 -0
- data/vendor/stringencoders/src/modp_html.c +128 -0
- data/vendor/stringencoders/src/modp_html.h +53 -0
- data/vendor/stringencoders/src/modp_html_named_entities.h +9910 -0
- data/vendor/stringencoders/src/modp_json.c +315 -0
- data/vendor/stringencoders/src/modp_json.h +103 -0
- data/vendor/stringencoders/src/modp_json_data.h +57 -0
- data/vendor/stringencoders/src/modp_json_gen.py +60 -0
- data/vendor/stringencoders/src/modp_mainpage.h +120 -0
- data/vendor/stringencoders/src/modp_numtoa.c +350 -0
- data/vendor/stringencoders/src/modp_numtoa.h +100 -0
- data/vendor/stringencoders/src/modp_qsiter.c +76 -0
- data/vendor/stringencoders/src/modp_qsiter.h +71 -0
- data/vendor/stringencoders/src/modp_stdint.h +43 -0
- data/vendor/stringencoders/src/modp_utf8.c +88 -0
- data/vendor/stringencoders/src/modp_utf8.h +38 -0
- data/vendor/stringencoders/src/modp_xml.c +311 -0
- data/vendor/stringencoders/src/modp_xml.h +166 -0
- data/vendor/stringencoders/src/stringencoders.pc +10 -0
- data/vendor/stringencoders/src/stringencoders.pc.in +10 -0
- data/vendor/stringencoders/test/Makefile.am +113 -0
- data/vendor/stringencoders/test/apr_base64.c +262 -0
- data/vendor/stringencoders/test/apr_base64.h +120 -0
- data/vendor/stringencoders/test/cxx_test.cc +482 -0
- data/vendor/stringencoders/test/minunit.h +82 -0
- data/vendor/stringencoders/test/modp_ascii_test.c +281 -0
- data/vendor/stringencoders/test/modp_b16_test.c +288 -0
- data/vendor/stringencoders/test/modp_b2_test.c +250 -0
- data/vendor/stringencoders/test/modp_b64_test.c +266 -0
- data/vendor/stringencoders/test/modp_b85_test.c +130 -0
- data/vendor/stringencoders/test/modp_bjavascript_test.c +137 -0
- data/vendor/stringencoders/test/modp_burl_test.c +423 -0
- data/vendor/stringencoders/test/modp_html_test.c +296 -0
- data/vendor/stringencoders/test/modp_json_test.c +336 -0
- data/vendor/stringencoders/test/modp_numtoa_test.c +545 -0
- data/vendor/stringencoders/test/modp_qsiter_test.c +280 -0
- data/vendor/stringencoders/test/modp_utf8_test.c +188 -0
- data/vendor/stringencoders/test/modp_xml_test.c +339 -0
- data/vendor/stringencoders/test/speedtest.c +241 -0
- data/vendor/stringencoders/test/speedtest_ascii.c +345 -0
- data/vendor/stringencoders/test/speedtest_msg.c +78 -0
- data/vendor/stringencoders/test/speedtest_numtoa.c +276 -0
- metadata +314 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
|
2
|
+
STRINGENCODERS_INCLUDE = -I$(top_srcdir)/src
|
3
|
+
STRINGENCODERS_LTLIB = $(top_srcdir)/src/libmodpbase64.la
|
4
|
+
|
5
|
+
check_PROGRAMS = \
|
6
|
+
modp_ascii_test \
|
7
|
+
modp_b2_test \
|
8
|
+
modp_b16_test \
|
9
|
+
modp_b64_test \
|
10
|
+
modp_b64r_test \
|
11
|
+
modp_b64w_test \
|
12
|
+
modp_b85_test \
|
13
|
+
modp_burl_test \
|
14
|
+
modp_bjavascript_test \
|
15
|
+
modp_numtoa_test \
|
16
|
+
modp_utf8_test \
|
17
|
+
modp_xml_test \
|
18
|
+
modp_html_test \
|
19
|
+
modp_json_test \
|
20
|
+
modp_qsiter_test \
|
21
|
+
cxx_test
|
22
|
+
|
23
|
+
TESTS = $(check_PROGRAMS)
|
24
|
+
|
25
|
+
noinst_PROGRAMS = \
|
26
|
+
speedtest \
|
27
|
+
speedtest_numtoa \
|
28
|
+
speedtest_msg
|
29
|
+
|
30
|
+
speedtest_SOURCES = apr_base64.h apr_base64.c speedtest.c
|
31
|
+
speedtest_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
32
|
+
speedtest_LDADD = $(STRINGENCODERS_LTLIB)
|
33
|
+
|
34
|
+
speedtest_numtoa_SOURCES = speedtest_numtoa.c
|
35
|
+
speedtest_numtoa_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
36
|
+
speedtest_numtoa_LDADD = $(STRINGENCODERS_LTLIB)
|
37
|
+
|
38
|
+
speedtest_msg_SOURCES = speedtest_msg.c
|
39
|
+
speedtest_msg_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
40
|
+
speedtest_msg_LDADD = $(STRINGENCODERS_LTLIB)
|
41
|
+
|
42
|
+
modp_b2_test_SOURCES = modp_b2_test.c
|
43
|
+
modp_b2_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
44
|
+
modp_b2_test_LDADD = $(STRINGENCODERS_LTLIB)
|
45
|
+
|
46
|
+
modp_b16_test_SOURCES = modp_b16_test.c
|
47
|
+
modp_b16_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
48
|
+
modp_b16_test_LDADD = $(STRINGENCODERS_LTLIB)
|
49
|
+
|
50
|
+
modp_b64_test_SOURCES = modp_b64_test.c
|
51
|
+
modp_b64_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
52
|
+
modp_b64_test_LDADD = $(STRINGENCODERS_LTLIB)
|
53
|
+
|
54
|
+
modp_b64w_test.c: modp_b64_test.c
|
55
|
+
perl -p -i -e 's/b64/b64w/g' < modp_b64_test.c > modp_b64w_test.c
|
56
|
+
|
57
|
+
modp_b64w_test_SOURCES = modp_b64w_test.c
|
58
|
+
modp_b64w_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
59
|
+
modp_b64w_test_LDADD = $(STRINGENCODERS_LTLIB)
|
60
|
+
|
61
|
+
modp_b64r_test.c: modp_b64_test.c
|
62
|
+
perl -p -i -e 's/b64/b64r/g' < modp_b64_test.c > modp_b64r_test.c
|
63
|
+
|
64
|
+
modp_b64r_test_SOURCES = modp_b64r_test.c
|
65
|
+
modp_b64r_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
66
|
+
modp_b64r_test_LDADD = $(STRINGENCODERS_LTLIB)
|
67
|
+
|
68
|
+
modp_b85_test_SOURCES = modp_b85_test.c
|
69
|
+
modp_b85_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
70
|
+
modp_b85_test_LDADD = $(STRINGENCODERS_LTLIB)
|
71
|
+
|
72
|
+
modp_burl_test_SOURCES = modp_burl_test.c
|
73
|
+
modp_burl_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
74
|
+
modp_burl_test_LDADD = $(STRINGENCODERS_LTLIB)
|
75
|
+
|
76
|
+
modp_bjavascript_test_SOURCES = modp_bjavascript_test.c
|
77
|
+
modp_bjavascript_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
78
|
+
modp_bjavascript_test_LDADD = $(STRINGENCODERS_LTLIB)
|
79
|
+
|
80
|
+
modp_ascii_test_SOURCES = modp_ascii_test.c
|
81
|
+
modp_ascii_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
82
|
+
modp_ascii_test_LDADD = $(STRINGENCODERS_LTLIB)
|
83
|
+
|
84
|
+
modp_xml_test_SOURCES = modp_xml_test.c
|
85
|
+
modp_xml_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
86
|
+
modp_xml_test_LDADD = $(STRINGENCODERS_LTLIB)
|
87
|
+
|
88
|
+
modp_numtoa_test_SOURCES = modp_numtoa_test.c
|
89
|
+
modp_numtoa_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
90
|
+
modp_numtoa_test_LDADD = $(STRINGENCODERS_LTLIB)
|
91
|
+
|
92
|
+
modp_html_test_SOURCES = modp_html_test.c
|
93
|
+
modp_html_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
94
|
+
modp_html_test_LDADD = $(STRINGENCODERS_LTLIB)
|
95
|
+
|
96
|
+
modp_qsiter_test_SOURCES = modp_qsiter_test.c
|
97
|
+
modp_qsiter_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
98
|
+
modp_qsiter_test_LDADD = $(STRINGENCODERS_LTLIB)
|
99
|
+
|
100
|
+
modp_utf8_test_SOURCES = modp_utf8_test.c
|
101
|
+
modp_utf8_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
102
|
+
modp_utf8_test_LDADD = $(STRINGENCODERS_LTLIB)
|
103
|
+
|
104
|
+
modp_json_test_SOURCES = modp_json_test.c
|
105
|
+
modp_json_test_CPPFLAGS = $(STRINGENCODERS_INCLUDE)
|
106
|
+
modp_json_test_LDADD = $(STRINGENCODERS_LTLIB)
|
107
|
+
|
108
|
+
cxx_test_SOURCES = cxx_test.cc
|
109
|
+
cxx_test_CPPFLAGS =$(STRINGENCODERS_INCLUDE)
|
110
|
+
cxx_test_LDADD = $(STRINGENCODERS_LTLIB)
|
111
|
+
|
112
|
+
clean-local:
|
113
|
+
rm -f *~
|
@@ -0,0 +1,262 @@
|
|
1
|
+
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
|
2
|
+
* applicable.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
/* base64 encoder/decoder. Originally part of main/util.c
|
18
|
+
* but moved here so that support/ab and apr_sha1.c could
|
19
|
+
* use it. This meant removing the apr_palloc()s and adding
|
20
|
+
* ugly 'len' functions, which is quite a nasty cost.
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include "apr_base64.h"
|
24
|
+
#define APR_CHARSET_EBCDIC 0
|
25
|
+
#if APR_CHARSET_EBCDIC
|
26
|
+
#include "apr_xlate.h"
|
27
|
+
#endif /* APR_CHARSET_EBCDIC */
|
28
|
+
|
29
|
+
/* aaaack but it's fast and const should make it shared text page. */
|
30
|
+
static const unsigned char pr2six[256] = {
|
31
|
+
#if !APR_CHARSET_EBCDIC
|
32
|
+
/* ASCII table */
|
33
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
34
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
35
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
|
36
|
+
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
|
37
|
+
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
38
|
+
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
|
39
|
+
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
40
|
+
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
|
41
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
42
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
43
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
44
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
45
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
46
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
47
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
48
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
|
49
|
+
#else /*APR_CHARSET_EBCDIC*/
|
50
|
+
/* EBCDIC table */
|
51
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
52
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
53
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
54
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
55
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64,
|
56
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
57
|
+
64, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
58
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
59
|
+
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 64, 64, 64, 64, 64, 64,
|
60
|
+
64, 35, 36, 37, 38, 39, 40, 41, 42, 43, 64, 64, 64, 64, 64, 64,
|
61
|
+
64, 64, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, 64,
|
62
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
63
|
+
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 64, 64, 64, 64, 64, 64,
|
64
|
+
64, 9, 10, 11, 12, 13, 14, 15, 16, 17, 64, 64, 64, 64, 64, 64,
|
65
|
+
64, 64, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, 64,
|
66
|
+
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64
|
67
|
+
#endif /*APR_CHARSET_EBCDIC*/
|
68
|
+
};
|
69
|
+
|
70
|
+
#if APR_CHARSET_EBCDIC
|
71
|
+
static apr_xlate_t* xlate_to_ebcdic;
|
72
|
+
static unsigned char os_toascii[256];
|
73
|
+
|
74
|
+
APU_DECLARE(apr_status_t)
|
75
|
+
apr_base64init_ebcdic(apr_xlate_t* to_ascii,
|
76
|
+
apr_xlate_t* to_ebcdic)
|
77
|
+
{
|
78
|
+
int i;
|
79
|
+
apr_size_t inbytes_left, outbytes_left;
|
80
|
+
apr_status_t rv;
|
81
|
+
int onoff;
|
82
|
+
|
83
|
+
/* Only single-byte conversion is supported.
|
84
|
+
*/
|
85
|
+
rv = apr_xlate_get_sb(to_ascii, &onoff);
|
86
|
+
if (rv) {
|
87
|
+
return rv;
|
88
|
+
}
|
89
|
+
if (!onoff) { /* If conversion is not single-byte-only */
|
90
|
+
return APR_EINVAL;
|
91
|
+
}
|
92
|
+
rv = apr_xlate_get_sb(to_ebcdic, &onoff);
|
93
|
+
if (rv) {
|
94
|
+
return rv;
|
95
|
+
}
|
96
|
+
if (!onoff) { /* If conversion is not single-byte-only */
|
97
|
+
return APR_EINVAL;
|
98
|
+
}
|
99
|
+
xlate_to_ebcdic = to_ebcdic;
|
100
|
+
for (i = 0; i < sizeof(os_toascii); i++) {
|
101
|
+
os_toascii[i] = i;
|
102
|
+
}
|
103
|
+
inbytes_left = outbytes_left = sizeof(os_toascii);
|
104
|
+
apr_xlate_conv_buffer(to_ascii, os_toascii, &inbytes_left,
|
105
|
+
os_toascii, &outbytes_left);
|
106
|
+
|
107
|
+
return APR_SUCCESS;
|
108
|
+
}
|
109
|
+
#endif /*APR_CHARSET_EBCDIC*/
|
110
|
+
|
111
|
+
APU_DECLARE(int)
|
112
|
+
apr_base64_decode_len(const char* bufcoded)
|
113
|
+
{
|
114
|
+
int nbytesdecoded;
|
115
|
+
register const unsigned char* bufin;
|
116
|
+
register int nprbytes;
|
117
|
+
|
118
|
+
bufin = (const unsigned char*)bufcoded;
|
119
|
+
while (pr2six[*(bufin++)] <= 63)
|
120
|
+
;
|
121
|
+
|
122
|
+
nprbytes = (int)((bufin - (const unsigned char*)bufcoded) - 1);
|
123
|
+
nbytesdecoded = ((nprbytes + 3) / 4) * 3;
|
124
|
+
|
125
|
+
return nbytesdecoded + 1;
|
126
|
+
}
|
127
|
+
|
128
|
+
APU_DECLARE(int)
|
129
|
+
apr_base64_decode(char* bufplain, const char* bufcoded)
|
130
|
+
{
|
131
|
+
#if APR_CHARSET_EBCDIC
|
132
|
+
apr_size_t inbytes_left, outbytes_left;
|
133
|
+
#endif /* APR_CHARSET_EBCDIC */
|
134
|
+
int len;
|
135
|
+
|
136
|
+
len = apr_base64_decode_binary((unsigned char*)bufplain, bufcoded);
|
137
|
+
#if APR_CHARSET_EBCDIC
|
138
|
+
inbytes_left = outbytes_left = len;
|
139
|
+
apr_xlate_conv_buffer(xlate_to_ebcdic, bufplain, &inbytes_left,
|
140
|
+
bufplain, &outbytes_left);
|
141
|
+
#endif /* APR_CHARSET_EBCDIC */
|
142
|
+
bufplain[len] = '\0';
|
143
|
+
return len;
|
144
|
+
}
|
145
|
+
|
146
|
+
/* This is the same as apr_base64_decode() except on EBCDIC machines, where
|
147
|
+
* the conversion of the output to ebcdic is left out.
|
148
|
+
*/
|
149
|
+
APU_DECLARE(int)
|
150
|
+
apr_base64_decode_binary(unsigned char* bufplain,
|
151
|
+
const char* bufcoded)
|
152
|
+
{
|
153
|
+
int nbytesdecoded;
|
154
|
+
register const unsigned char* bufin;
|
155
|
+
register unsigned char* bufout;
|
156
|
+
register int nprbytes;
|
157
|
+
|
158
|
+
bufin = (const unsigned char*)bufcoded;
|
159
|
+
while (pr2six[*(bufin++)] <= 63)
|
160
|
+
;
|
161
|
+
nprbytes = (int)((bufin - (const unsigned char*)bufcoded) - 1);
|
162
|
+
nbytesdecoded = ((nprbytes + 3) / 4) * 3;
|
163
|
+
|
164
|
+
bufout = (unsigned char*)bufplain;
|
165
|
+
bufin = (const unsigned char*)bufcoded;
|
166
|
+
|
167
|
+
while (nprbytes > 4) {
|
168
|
+
*(bufout++) = (unsigned char)(pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
|
169
|
+
*(bufout++) = (unsigned char)(pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
|
170
|
+
*(bufout++) = (unsigned char)(pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);
|
171
|
+
bufin += 4;
|
172
|
+
nprbytes -= 4;
|
173
|
+
}
|
174
|
+
|
175
|
+
/* Note: (nprbytes == 1) would be an error, so just ingore that case */
|
176
|
+
if (nprbytes > 1) {
|
177
|
+
*(bufout++) = (unsigned char)(pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
|
178
|
+
}
|
179
|
+
if (nprbytes > 2) {
|
180
|
+
*(bufout++) = (unsigned char)(pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
|
181
|
+
}
|
182
|
+
if (nprbytes > 3) {
|
183
|
+
*(bufout++) = (unsigned char)(pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);
|
184
|
+
}
|
185
|
+
|
186
|
+
nbytesdecoded -= (4 - nprbytes) & 3;
|
187
|
+
return nbytesdecoded;
|
188
|
+
}
|
189
|
+
|
190
|
+
static const char basis_64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
191
|
+
|
192
|
+
APU_DECLARE(int)
|
193
|
+
apr_base64_encode_len(int len)
|
194
|
+
{
|
195
|
+
return ((len + 2) / 3 * 4) + 1;
|
196
|
+
}
|
197
|
+
|
198
|
+
APU_DECLARE(int)
|
199
|
+
apr_base64_encode(char* encoded, const char* string, int len)
|
200
|
+
{
|
201
|
+
#if !APR_CHARSET_EBCDIC
|
202
|
+
return apr_base64_encode_binary(encoded, (const unsigned char*)string, len);
|
203
|
+
#else /* APR_CHARSET_EBCDIC */
|
204
|
+
int i;
|
205
|
+
char* p;
|
206
|
+
|
207
|
+
p = encoded;
|
208
|
+
for (i = 0; i < len - 2; i += 3) {
|
209
|
+
*p++ = basis_64[(os_toascii[string[i]] >> 2) & 0x3F];
|
210
|
+
*p++ = basis_64[((os_toascii[string[i]] & 0x3) << 4) | ((int)(os_toascii[string[i + 1]] & 0xF0) >> 4)];
|
211
|
+
*p++ = basis_64[((os_toascii[string[i + 1]] & 0xF) << 2) | ((int)(os_toascii[string[i + 2]] & 0xC0) >> 6)];
|
212
|
+
*p++ = basis_64[os_toascii[string[i + 2]] & 0x3F];
|
213
|
+
}
|
214
|
+
if (i < len) {
|
215
|
+
*p++ = basis_64[(os_toascii[string[i]] >> 2) & 0x3F];
|
216
|
+
if (i == (len - 1)) {
|
217
|
+
*p++ = basis_64[((os_toascii[string[i]] & 0x3) << 4)];
|
218
|
+
*p++ = '=';
|
219
|
+
} else {
|
220
|
+
*p++ = basis_64[((os_toascii[string[i]] & 0x3) << 4) | ((int)(os_toascii[string[i + 1]] & 0xF0) >> 4)];
|
221
|
+
*p++ = basis_64[((os_toascii[string[i + 1]] & 0xF) << 2)];
|
222
|
+
}
|
223
|
+
*p++ = '=';
|
224
|
+
}
|
225
|
+
|
226
|
+
*p++ = '\0';
|
227
|
+
return p - encoded;
|
228
|
+
#endif /* APR_CHARSET_EBCDIC */
|
229
|
+
}
|
230
|
+
|
231
|
+
/* This is the same as apr_base64_encode() except on EBCDIC machines, where
|
232
|
+
* the conversion of the input to ascii is left out.
|
233
|
+
*/
|
234
|
+
APU_DECLARE(int)
|
235
|
+
apr_base64_encode_binary(char* encoded,
|
236
|
+
const unsigned char* string, int len)
|
237
|
+
{
|
238
|
+
int i;
|
239
|
+
char* p;
|
240
|
+
|
241
|
+
p = encoded;
|
242
|
+
for (i = 0; i < len - 2; i += 3) {
|
243
|
+
*p++ = basis_64[(string[i] >> 2) & 0x3F];
|
244
|
+
*p++ = basis_64[((string[i] & 0x3) << 4) | ((int)(string[i + 1] & 0xF0) >> 4)];
|
245
|
+
*p++ = basis_64[((string[i + 1] & 0xF) << 2) | ((int)(string[i + 2] & 0xC0) >> 6)];
|
246
|
+
*p++ = basis_64[string[i + 2] & 0x3F];
|
247
|
+
}
|
248
|
+
if (i < len) {
|
249
|
+
*p++ = basis_64[(string[i] >> 2) & 0x3F];
|
250
|
+
if (i == (len - 1)) {
|
251
|
+
*p++ = basis_64[((string[i] & 0x3) << 4)];
|
252
|
+
*p++ = '=';
|
253
|
+
} else {
|
254
|
+
*p++ = basis_64[((string[i] & 0x3) << 4) | ((int)(string[i + 1] & 0xF0) >> 4)];
|
255
|
+
*p++ = basis_64[((string[i + 1] & 0xF) << 2)];
|
256
|
+
}
|
257
|
+
*p++ = '=';
|
258
|
+
}
|
259
|
+
|
260
|
+
*p++ = '\0';
|
261
|
+
return (int)(p - encoded);
|
262
|
+
}
|
@@ -0,0 +1,120 @@
|
|
1
|
+
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
|
2
|
+
* applicable.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
* The apr_vsnprintf/apr_snprintf functions are based on, and used with the
|
16
|
+
* permission of, the SIO stdio-replacement strx_* functions by Panos
|
17
|
+
* Tsirigotis <panos@alumni.cs.colorado.edu> for xinetd.
|
18
|
+
*/
|
19
|
+
|
20
|
+
/**
|
21
|
+
* @file apr_base64.h
|
22
|
+
* @brief APR-UTIL Base64 Encoding
|
23
|
+
*/
|
24
|
+
#ifndef APR_BASE64_H
|
25
|
+
#define APR_BASE64_H
|
26
|
+
|
27
|
+
/*
|
28
|
+
//#include "apu.h"
|
29
|
+
//#include "apr_general.h"
|
30
|
+
*/
|
31
|
+
#define APU_DECLARE(x) x
|
32
|
+
|
33
|
+
#ifdef __cplusplus
|
34
|
+
extern "C" {
|
35
|
+
#endif
|
36
|
+
|
37
|
+
/**
|
38
|
+
* @defgroup APR_Util_Base64 Base64 Encoding
|
39
|
+
* @ingroup APR_Util
|
40
|
+
* @{
|
41
|
+
*/
|
42
|
+
|
43
|
+
/* Simple BASE64 encode/decode functions.
|
44
|
+
*
|
45
|
+
* As we might encode binary strings, hence we require the length of
|
46
|
+
* the incoming plain source. And return the length of what we decoded.
|
47
|
+
*
|
48
|
+
* The decoding function takes any non valid char (i.e. whitespace, \0
|
49
|
+
* or anything non A-Z,0-9 etc as terminal.
|
50
|
+
*
|
51
|
+
* plain strings/binary sequences are not assumed '\0' terminated. Encoded
|
52
|
+
* strings are neither. But probably should.
|
53
|
+
*
|
54
|
+
*/
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Given the length of an un-encrypted string, get the length of the
|
58
|
+
* encrypted string.
|
59
|
+
* @param len the length of an unencrypted string.
|
60
|
+
* @return the length of the string after it is encrypted
|
61
|
+
*/
|
62
|
+
APU_DECLARE(int)
|
63
|
+
apr_base64_encode_len(int len);
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Encode a text string using base64encoding.
|
67
|
+
* @param coded_dst The destination string for the encoded string.
|
68
|
+
* @param plain_src The original string in plain text
|
69
|
+
* @param len_plain_src The length of the plain text string
|
70
|
+
* @return the length of the encoded string
|
71
|
+
*/
|
72
|
+
APU_DECLARE(int)
|
73
|
+
apr_base64_encode(char* coded_dst, const char* plain_src,
|
74
|
+
int len_plain_src);
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Encode an EBCDIC string using base64encoding.
|
78
|
+
* @param coded_dst The destination string for the encoded string.
|
79
|
+
* @param plain_src The original string in plain text
|
80
|
+
* @param len_plain_src The length of the plain text string
|
81
|
+
* @return the length of the encoded string
|
82
|
+
*/
|
83
|
+
APU_DECLARE(int)
|
84
|
+
apr_base64_encode_binary(char* coded_dst,
|
85
|
+
const unsigned char* plain_src,
|
86
|
+
int len_plain_src);
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Determine the length of a plain text string given the encoded version
|
90
|
+
* @param coded_src The encoded string
|
91
|
+
* @return the length of the plain text string
|
92
|
+
*/
|
93
|
+
APU_DECLARE(int)
|
94
|
+
apr_base64_decode_len(const char* coded_src);
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Decode a string to plain text
|
98
|
+
* @param plain_dst The destination string for the plain text
|
99
|
+
* @param coded_src The encoded string
|
100
|
+
* @return the length of the plain text string
|
101
|
+
*/
|
102
|
+
APU_DECLARE(int)
|
103
|
+
apr_base64_decode(char* plain_dst, const char* coded_src);
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Decode an EBCDIC string to plain text
|
107
|
+
* @param plain_dst The destination string for the plain text
|
108
|
+
* @param coded_src The encoded string
|
109
|
+
* @return the length of the plain text string
|
110
|
+
*/
|
111
|
+
APU_DECLARE(int)
|
112
|
+
apr_base64_decode_binary(unsigned char* plain_dst,
|
113
|
+
const char* coded_src);
|
114
|
+
|
115
|
+
/** @} */
|
116
|
+
#ifdef __cplusplus
|
117
|
+
}
|
118
|
+
#endif
|
119
|
+
|
120
|
+
#endif /* !APR_BASE64_H */
|