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,16 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
FILE=stringencoders-v3.11.0
|
|
4
|
+
rm -rf ${FILE}
|
|
5
|
+
git clone --depth=1 git@github.com:client9/stringencoders.git ${FILE}
|
|
6
|
+
(cd ${FILE} && ./bootstrap.sh)
|
|
7
|
+
find $FILE -name ".git" | xargs rm -rf
|
|
8
|
+
|
|
9
|
+
rm -f ${FILE}/Doxyfile
|
|
10
|
+
rm -f ${FILE}/makerelease.sh
|
|
11
|
+
rm -rf ${FILE}/doxy
|
|
12
|
+
|
|
13
|
+
tar -czvf ${FILE}.tar.gz ${FILE}
|
|
14
|
+
rm -rf ${FILE}
|
|
15
|
+
echo "DONE"
|
|
16
|
+
ls -lh ${FILE}.tar.gz
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# This is the MIT License
|
|
5
|
+
# http://www.opensource.org/licenses/mit-license.php
|
|
6
|
+
#
|
|
7
|
+
# Copyright (c) 2008 Nick Galbreath
|
|
8
|
+
#
|
|
9
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
# in the Software without restriction, including without limitation the rights
|
|
12
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
# furnished to do so, subject to the following conditions:
|
|
15
|
+
#
|
|
16
|
+
# The above copyright notice and this permission notice shall be included in
|
|
17
|
+
# all copies or substantial portions of the Software.
|
|
18
|
+
#
|
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
# THE SOFTWARE.
|
|
26
|
+
#
|
|
27
|
+
|
|
28
|
+
gsCharToInt = [
|
|
29
|
+
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
|
30
|
+
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
|
31
|
+
256, 256, 256, 256, 256, 256, 256, 256, 256, 0, 256, 1,
|
|
32
|
+
2, 3, 256, 4, 5, 6, 7, 8, 256, 9, 10, 11,
|
|
33
|
+
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 256,
|
|
34
|
+
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
|
|
35
|
+
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
|
|
36
|
+
47, 48, 49, 50, 51, 52, 53, 54, 256, 55, 56, 57,
|
|
37
|
+
58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
|
|
38
|
+
70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
|
|
39
|
+
82, 83, 84, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
|
40
|
+
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
|
41
|
+
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
|
42
|
+
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
|
43
|
+
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
|
44
|
+
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
|
45
|
+
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
|
46
|
+
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
|
47
|
+
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
|
48
|
+
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
|
49
|
+
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
|
|
50
|
+
256, 256, 256, 256]
|
|
51
|
+
|
|
52
|
+
gsIntToChar = [
|
|
53
|
+
'!', '#', '$', '%', '\'', '(', ')', '*', '+', '-',
|
|
54
|
+
'.', '/', '0', '1', '2', '3', '4', '5', '6', '7',
|
|
55
|
+
'8', '9', ':', '<', '=', '>', '?', '@', 'A', 'B',
|
|
56
|
+
'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
|
|
57
|
+
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
|
|
58
|
+
'W', 'X', 'Y', 'Z', '[', ']', '^', '_', '`', 'a',
|
|
59
|
+
'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
|
|
60
|
+
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
|
|
61
|
+
'v', 'w', 'x', 'y', 'z'
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
from struct import unpack, pack
|
|
65
|
+
# covert 4 characters into 5
|
|
66
|
+
def b85_encode(s):
|
|
67
|
+
parts = []
|
|
68
|
+
numchunks = len(s) // 4
|
|
69
|
+
format = '!' + str(numchunks) + 'I'
|
|
70
|
+
for x in unpack(format, s):
|
|
71
|
+
# network order (big endian), 32-bit unsigned integer
|
|
72
|
+
# note: x86 is little endian
|
|
73
|
+
parts.append(gsIntToChar[x // 52200625])
|
|
74
|
+
parts.append(gsIntToChar[(x // 614125) % 85])
|
|
75
|
+
parts.append(gsIntToChar[(x // 7225) % 85])
|
|
76
|
+
parts.append(gsIntToChar[(x // 85) % 85])
|
|
77
|
+
parts.append(gsIntToChar[x % 85])
|
|
78
|
+
return ''.join(parts)
|
|
79
|
+
|
|
80
|
+
#
|
|
81
|
+
# also does not use the 'struct' module which may be desirable
|
|
82
|
+
# to some
|
|
83
|
+
#
|
|
84
|
+
def b85_encode2(s):
|
|
85
|
+
parts = []
|
|
86
|
+
for i in xrange(0,len(s), 4):
|
|
87
|
+
chunk = s[i:i+4]
|
|
88
|
+
x = ord(chunk[3]) + 256*(ord(chunk[2]) + 256*(ord(chunk[1]) + 256*ord(chunk[0])))
|
|
89
|
+
|
|
90
|
+
# network order (big endian), 32-bit unsigned integer
|
|
91
|
+
# note: x86 is little endian
|
|
92
|
+
parts.append(gsIntToChar[x // 52200625])
|
|
93
|
+
parts.append(gsIntToChar[(x // 614125) % 85])
|
|
94
|
+
parts.append(gsIntToChar[(x // 7225) % 85])
|
|
95
|
+
parts.append(gsIntToChar[(x // 85) % 85])
|
|
96
|
+
parts.append(gsIntToChar[x % 85])
|
|
97
|
+
return ''.join(parts)
|
|
98
|
+
|
|
99
|
+
# convert 5 characters to 4
|
|
100
|
+
def b85_decode(s):
|
|
101
|
+
parts = []
|
|
102
|
+
for i in xrange(0, len(s), 5):
|
|
103
|
+
bsum = 0;
|
|
104
|
+
for j in xrange(0,5):
|
|
105
|
+
val = gsCharToInt[ord(s[i+j])]
|
|
106
|
+
bsum = 85*bsum + val
|
|
107
|
+
tmp = pack('!I', bsum)
|
|
108
|
+
parts.append(tmp)
|
|
109
|
+
#parts += tmp
|
|
110
|
+
#parts += unpack('cccc', tmp)
|
|
111
|
+
return ''.join(parts)
|
|
112
|
+
|
|
113
|
+
# convert 5 characters to 4
|
|
114
|
+
def b85_decode2(s):
|
|
115
|
+
parts = []
|
|
116
|
+
for i in xrange(0, len(s), 5):
|
|
117
|
+
bsum = 0;
|
|
118
|
+
for j in xrange(0,5):
|
|
119
|
+
val = gsCharToInt[ord(s[i+j])]
|
|
120
|
+
bsum = 85*bsum + val
|
|
121
|
+
parts.append(chr((bsum >> 24) & 0xff))
|
|
122
|
+
parts.append(chr((bsum >> 16) & 0xff))
|
|
123
|
+
parts.append(chr((bsum >> 8) & 0xff))
|
|
124
|
+
parts.append(chr(bsum & 0xff))
|
|
125
|
+
|
|
126
|
+
return ''.join(parts)
|
|
127
|
+
|
|
128
|
+
import unittest
|
|
129
|
+
class B85Test(unittest.TestCase):
|
|
130
|
+
|
|
131
|
+
def testDecode1(self):
|
|
132
|
+
s = b85_decode('!!!!#')
|
|
133
|
+
self.assertEquals(4, len(s))
|
|
134
|
+
self.assertEquals(0, ord(s[0]))
|
|
135
|
+
self.assertEquals(0, ord(s[1]))
|
|
136
|
+
self.assertEquals(0, ord(s[2]))
|
|
137
|
+
self.assertEquals(1, ord(s[3]))
|
|
138
|
+
|
|
139
|
+
e = b85_encode(s)
|
|
140
|
+
self.assertEquals('!!!!#', e)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
if __name__ == '__main__':
|
|
144
|
+
from time import clock
|
|
145
|
+
#unittest.main()
|
|
146
|
+
|
|
147
|
+
s = '!!!!#' * 10
|
|
148
|
+
|
|
149
|
+
t0 = clock()
|
|
150
|
+
for i in xrange(1000000):
|
|
151
|
+
b85_decode(s)
|
|
152
|
+
t1 = clock()
|
|
153
|
+
print "decode v1", t1-t0
|
|
154
|
+
|
|
155
|
+
t0 = clock()
|
|
156
|
+
for i in xrange(1000000):
|
|
157
|
+
b85_decode2(s)
|
|
158
|
+
t1 = clock()
|
|
159
|
+
print "decode v2", t1-t0
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
s = b85_decode('!!!!#' * 10)
|
|
163
|
+
|
|
164
|
+
t0 = clock()
|
|
165
|
+
for i in xrange(1000000):
|
|
166
|
+
b85_encode(s)
|
|
167
|
+
t1 = clock()
|
|
168
|
+
print "encode v1", t1-t0
|
|
169
|
+
|
|
170
|
+
t0 = clock()
|
|
171
|
+
for i in xrange(1000000):
|
|
172
|
+
b85_encode2(s)
|
|
173
|
+
t1 = clock()
|
|
174
|
+
print "encode v2", t1-t0
|
|
175
|
+
|
|
176
|
+
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
|
|
2
|
+
include_HEADERS = \
|
|
3
|
+
extern_c_begin.h extern_c_end.h \
|
|
4
|
+
modp_b16.h modp_b64.h modp_b64w.h modp_b64r.h \
|
|
5
|
+
modp_b85.h modp_burl.h modp_bjavascript.h \
|
|
6
|
+
modp_numtoa.h modp_ascii.h modp_b2.h \
|
|
7
|
+
modp_qsiter.h modp_xml.h modp_html.h modp_json.h
|
|
8
|
+
|
|
9
|
+
lib_LTLIBRARIES = libmodpbase64.la
|
|
10
|
+
libmodpbase64_la_SOURCES = \
|
|
11
|
+
modp_b2.c modp_b2.h modp_b2_data.h \
|
|
12
|
+
modp_b16.c modp_b16.h modp_b16_data.h \
|
|
13
|
+
modp_b64.c modp_b64.h modp_b64_data.h \
|
|
14
|
+
modp_b64w.c modp_b64w.h modp_b64w_data.h \
|
|
15
|
+
modp_b64r.c modp_b64r.h modp_b64r_data.h \
|
|
16
|
+
modp_b85.h modp_b85.c modp_b85_data.h \
|
|
17
|
+
modp_burl.h modp_burl.c modp_burl_data.h \
|
|
18
|
+
modp_bjavascript.h modp_bjavascript.c modp_bjavascript_data.h \
|
|
19
|
+
modp_numtoa.h modp_numtoa.c \
|
|
20
|
+
modp_qsiter.h modp_qsiter.c \
|
|
21
|
+
modp_xml.h modp_xml.c \
|
|
22
|
+
modp_ascii.h modp_ascii.c modp_ascii_data.h \
|
|
23
|
+
modp_utf8.h modp_utf8.c \
|
|
24
|
+
modp_html.h modp_html.c \
|
|
25
|
+
modp_json.h modp_json.c
|
|
26
|
+
|
|
27
|
+
pkgconfigdir = $(libdir)/pkgconfig
|
|
28
|
+
pkgconfig_DATA = stringencoders.pc
|
|
29
|
+
|
|
30
|
+
#libmodpbase64_la_DEPENDENCIES = \
|
|
31
|
+
# modp_b2_data.h modp_b2_gen \
|
|
32
|
+
# modp_b16_data.h modp_b16_gen \
|
|
33
|
+
# modp_b64_data.h modp_b64w_data.h modp_b64r_data.h modp_b64_gen \
|
|
34
|
+
# modp_b85_data.h modp_b85_gen \
|
|
35
|
+
# modp_ascii_data.h modp_ascii_gen
|
|
36
|
+
|
|
37
|
+
CLEANFILES = *.log \
|
|
38
|
+
*~ src/*~ test/*~ \
|
|
39
|
+
*.tmp src/*.tmp test/*.tmp \
|
|
40
|
+
doxy/html/* \
|
|
41
|
+
doxy/*.tmp \
|
|
42
|
+
m4 \
|
|
43
|
+
*.loT \
|
|
44
|
+
*.ll *.ll.out \
|
|
45
|
+
*.gcda *.gcno *.gcov stringencoders.info \
|
|
46
|
+
modp_b16_data.h modp_b64_data.h modp_b85_data.h \
|
|
47
|
+
modp_b64w_data.h modp_b64w.c test/modp_b64w_test.c \
|
|
48
|
+
modp_b64r_data.h modp_b64r.c test/modp_b64r_test.c \
|
|
49
|
+
modp_ascii_data.h modp_b2_data.h \
|
|
50
|
+
modp_xml_test modp_qsiter_test modp_html_test modp_json_test \
|
|
51
|
+
cxx_test
|
|
52
|
+
|
|
53
|
+
modp_b2.c: modp_b2.h modp_b2_data.h
|
|
54
|
+
|
|
55
|
+
modp_b16.c: modp_b16.h modp_b16_data.h
|
|
56
|
+
|
|
57
|
+
modp_b64.c: modp_b64.h modp_b64_data.h
|
|
58
|
+
|
|
59
|
+
modp_b64r.c: modp_b64.c modp_b64r.h modp_b64r_data.h
|
|
60
|
+
perl -p -i -e 's/b64/b64r/g' < modp_b64.c > modp_b64r.c
|
|
61
|
+
|
|
62
|
+
modp_b64w.c: modp_b64.c modp_b64w.h modp_b64w_data.h
|
|
63
|
+
perl -p -i -e 's/b64/b64w/g' < modp_b64.c > modp_b64w.c
|
|
64
|
+
|
|
65
|
+
modp_b85.c: modp_b85.h modp_b85_data.h
|
|
66
|
+
|
|
67
|
+
modp_burl.c: modp_burl.h modp_burl_data.h
|
|
68
|
+
|
|
69
|
+
modp_bjavascript.c: modp_bjavascript.h modp_bjavascript_data.h
|
|
70
|
+
|
|
71
|
+
modp_json.c: modp_json.h modp_json_data.h
|
|
72
|
+
|
|
73
|
+
modp_ascii.c: modp_ascii.h modp_ascii_data.h
|
|
74
|
+
|
|
75
|
+
modp_qsiter.c: modp_qsiter.h
|
|
76
|
+
|
|
77
|
+
modp_xml.c: modp_xml.h
|
|
78
|
+
|
|
79
|
+
modp_b2_data.h: modp_b2_gen
|
|
80
|
+
./modp_b2_gen > modp_b2_data.h
|
|
81
|
+
|
|
82
|
+
modp_b16_data.h: modp_b16_gen
|
|
83
|
+
./modp_b16_gen > modp_b16_data.h
|
|
84
|
+
|
|
85
|
+
modp_b64_data.h: modp_b64_gen
|
|
86
|
+
./modp_b64_gen > modp_b64_data.h
|
|
87
|
+
|
|
88
|
+
modp_ascii_data.h: modp_ascii_gen
|
|
89
|
+
./modp_ascii_gen > modp_ascii_data.h
|
|
90
|
+
|
|
91
|
+
#
|
|
92
|
+
# Recall B64WCHARS by default is "-_."
|
|
93
|
+
#
|
|
94
|
+
modp_b64w_data.h: modp_b64_gen
|
|
95
|
+
./modp_b64_gen $(B64WCHARS) > modp_b64w_data.h
|
|
96
|
+
|
|
97
|
+
#
|
|
98
|
+
# RFC 4648 alphabet is -_=
|
|
99
|
+
# http://www.ietf.org/rfc/rfc4648.txt
|
|
100
|
+
modp_b64r_data.h: modp_b64_gen
|
|
101
|
+
./modp_b64_gen "-_=" > modp_b64r_data.h
|
|
102
|
+
|
|
103
|
+
modp_b85_data.h: modp_b85_gen
|
|
104
|
+
./modp_b85_gen > modp_b85_data.h
|
|
105
|
+
|
|
106
|
+
modp_burl_data.h: modp_burl_gen
|
|
107
|
+
./modp_burl_gen > modp_burl_data.h
|
|
108
|
+
|
|
109
|
+
modp_bjavascript_data.h: modp_bjavascript_gen
|
|
110
|
+
./modp_bjavascript_gen > modp_bjavascript_data.h
|
|
111
|
+
|
|
112
|
+
modp_json_data.h: modp_json_gen.py
|
|
113
|
+
./modp_json_gen.py
|
|
114
|
+
|
|
115
|
+
noinst_PROGRAMS = \
|
|
116
|
+
modp_b2_gen modp_b16_gen modp_b64_gen modp_b85_gen \
|
|
117
|
+
modp_burl_gen modp_ascii_gen modp_bjavascript_gen
|
|
118
|
+
|
|
119
|
+
modp_b2_gen_SOURCES = arraytoc.c modp_b2_gen.c
|
|
120
|
+
|
|
121
|
+
modp_b16_gen_SOURCES = arraytoc.c modp_b16_gen.c
|
|
122
|
+
|
|
123
|
+
modp_b64_gen_SOURCES = arraytoc.c modp_b64_gen.c
|
|
124
|
+
|
|
125
|
+
modp_b85_gen_SOURCES = arraytoc.c modp_b85_gen.c
|
|
126
|
+
|
|
127
|
+
modp_burl_gen_SOURCES = arraytoc.c modp_burl_gen.c
|
|
128
|
+
|
|
129
|
+
modp_ascii_gen_SOURCES = arraytoc.c modp_ascii_gen.c
|
|
130
|
+
|
|
131
|
+
modp_bjavascript_gen_SOURCES = arraytoc.c modp_bjavascript_gen.c
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#include "arraytoc.h"
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
|
|
4
|
+
/* dump uint32_t as hex digits */
|
|
5
|
+
void uint32_array_to_c_hex(const uint32_t* ary, size_t sz, const char* name)
|
|
6
|
+
{
|
|
7
|
+
size_t i = 0;
|
|
8
|
+
|
|
9
|
+
printf("static const uint32_t %s[%d] = {\n ", name, (int)sz);
|
|
10
|
+
for (;;) {
|
|
11
|
+
printf("0x%08x", ary[i]);
|
|
12
|
+
++i;
|
|
13
|
+
if (i == sz)
|
|
14
|
+
break;
|
|
15
|
+
if (i % 6 == 0) {
|
|
16
|
+
printf(",\n ");
|
|
17
|
+
} else {
|
|
18
|
+
printf(", ");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
printf("\n};\n");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* prints char array as a c program snippet
|
|
26
|
+
*/
|
|
27
|
+
void char_array_to_c(const char* ary, size_t sz, const char* name)
|
|
28
|
+
{
|
|
29
|
+
uint8_t tmp;
|
|
30
|
+
size_t i = 0;
|
|
31
|
+
|
|
32
|
+
printf("static const uint8_t %s[%d] = {\n ", name, (int)sz);
|
|
33
|
+
|
|
34
|
+
for (;;) {
|
|
35
|
+
if (ary[i] == 0) {
|
|
36
|
+
printf("'\\0'");
|
|
37
|
+
} else if (ary[i] == '\n') {
|
|
38
|
+
printf("'\\n'");
|
|
39
|
+
} else if (ary[i] == '\t') {
|
|
40
|
+
printf("'\\t'");
|
|
41
|
+
} else if (ary[i] == '\r') {
|
|
42
|
+
printf("'\\r'");
|
|
43
|
+
} else if (ary[i] == '\'') {
|
|
44
|
+
printf("'\\''");
|
|
45
|
+
} else if (ary[i] == '\\') {
|
|
46
|
+
printf("'\\\\'");
|
|
47
|
+
} else if (ary[i] < 32 || ary[i] > 126) {
|
|
48
|
+
tmp = (uint8_t)ary[i];
|
|
49
|
+
printf("0x%02x", tmp);
|
|
50
|
+
} else {
|
|
51
|
+
printf("'%c'", (char)ary[i]);
|
|
52
|
+
}
|
|
53
|
+
++i;
|
|
54
|
+
if (i == sz)
|
|
55
|
+
break;
|
|
56
|
+
if (i % 10 == 0) {
|
|
57
|
+
printf(",\n ");
|
|
58
|
+
} else {
|
|
59
|
+
printf(", ");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
printf("\n};\n");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* prints an uint array as a c program snippet
|
|
67
|
+
*/
|
|
68
|
+
void uint32_array_to_c(const uint32_t* ary, size_t sz, const char* name)
|
|
69
|
+
{
|
|
70
|
+
size_t i = 0;
|
|
71
|
+
|
|
72
|
+
printf("static const uint32_t %s[%d] = {\n ", name, (int)sz);
|
|
73
|
+
for (;;) {
|
|
74
|
+
printf("%u", ary[i]);
|
|
75
|
+
++i;
|
|
76
|
+
if (i == sz)
|
|
77
|
+
break;
|
|
78
|
+
if (i % 12 == 0) {
|
|
79
|
+
printf(",\n ");
|
|
80
|
+
} else {
|
|
81
|
+
printf(", ");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
printf("\n};\n");
|
|
85
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#ifndef COM_MODP_STRINGENCODERS_ARRAYTOC
|
|
2
|
+
#define COM_MODP_STRINGENCODERS_ARRAYTOC
|
|
3
|
+
|
|
4
|
+
#include "modp_stdint.h"
|
|
5
|
+
|
|
6
|
+
#ifdef __cplusplus
|
|
7
|
+
#define BEGIN_C extern "C" {
|
|
8
|
+
#define END_C }
|
|
9
|
+
#else
|
|
10
|
+
#define BEGIN_C
|
|
11
|
+
#define END_C
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
BEGIN_C
|
|
15
|
+
|
|
16
|
+
/** \brief output a uint32_t array into source code
|
|
17
|
+
*
|
|
18
|
+
*
|
|
19
|
+
* \param[in] ary the input array
|
|
20
|
+
* \param[in] size number of elements in array
|
|
21
|
+
* \param[in] name the name of the struct for the source code
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
void uint32_array_to_c(const uint32_t* ary, size_t size, const char* name);
|
|
25
|
+
|
|
26
|
+
/** \brief output an uint32_t array into source code as hex values
|
|
27
|
+
*
|
|
28
|
+
* \param[in] ary the input array
|
|
29
|
+
* \param[in] size number of elements in array
|
|
30
|
+
* \param[in] name the name of the struct for source code
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
void uint32_array_to_c_hex(const uint32_t* ary, size_t size, const char* name);
|
|
34
|
+
|
|
35
|
+
/** \brief output a char array into source code
|
|
36
|
+
*
|
|
37
|
+
* \param[in] ary the input array
|
|
38
|
+
* \param[in] size number of elements in array
|
|
39
|
+
* \param[in] name the name of the struct for source code
|
|
40
|
+
*/
|
|
41
|
+
void char_array_to_c(const char* ary, size_t size, const char* name);
|
|
42
|
+
|
|
43
|
+
#endif
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Trie(object):
|
|
5
|
+
def __init__(self):
|
|
6
|
+
self.struct = [
|
|
7
|
+
[ ]
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
def dump(self):
|
|
11
|
+
count = 0
|
|
12
|
+
for i in self.struct:
|
|
13
|
+
count += len(i)
|
|
14
|
+
print i
|
|
15
|
+
print len(self.struct)
|
|
16
|
+
print count
|
|
17
|
+
|
|
18
|
+
def longest_match(self, s):
|
|
19
|
+
"""
|
|
20
|
+
sample code
|
|
21
|
+
"""
|
|
22
|
+
leaf = self.struct[0]
|
|
23
|
+
matches = []
|
|
24
|
+
for ch in s:
|
|
25
|
+
newleaf = None
|
|
26
|
+
for node in leaf:
|
|
27
|
+
if ch == node['value']:
|
|
28
|
+
found = True
|
|
29
|
+
if node['userdata'] is not None:
|
|
30
|
+
matches.append(node['userdata'])
|
|
31
|
+
if node['next'] == 0:
|
|
32
|
+
return matches
|
|
33
|
+
newleaf = self.struct[node['next']]
|
|
34
|
+
break
|
|
35
|
+
if newleaf:
|
|
36
|
+
leaf = newleaf
|
|
37
|
+
else:
|
|
38
|
+
break
|
|
39
|
+
return matches
|
|
40
|
+
|
|
41
|
+
def compile(self):
|
|
42
|
+
"""
|
|
43
|
+
The current data struct is a a ragged array
|
|
44
|
+
0 - [ ]
|
|
45
|
+
1 - [ ]
|
|
46
|
+
2 - [ ]
|
|
47
|
+
3 - [ ]
|
|
48
|
+
i.e. an array of vectors which are ugly to
|
|
49
|
+
statically allocate in C
|
|
50
|
+
http://stackoverflow.com/questions/1083658/jagged-array-in-c
|
|
51
|
+
|
|
52
|
+
value, more, next, [userdata or 0]
|
|
53
|
+
"""
|
|
54
|
+
offsets = [ 0 ]
|
|
55
|
+
count = 0
|
|
56
|
+
for leaf in self.struct:
|
|
57
|
+
count += len(leaf)
|
|
58
|
+
offsets.append(count)
|
|
59
|
+
print """
|
|
60
|
+
#ifndef _MODP_HTML_NAMED_ENTITIES_H
|
|
61
|
+
#define _MODP_HTML_NAMED_ENTITIES_H
|
|
62
|
+
#include <string.h>
|
|
63
|
+
|
|
64
|
+
typedef struct trienode {
|
|
65
|
+
char value; /* 1 byte -- char value - we deal only in pure ASCII */
|
|
66
|
+
char more; /* 1 byte -- should be read next value in array (boundary marker) */
|
|
67
|
+
short next; /* 2 byte -- position of next leaf */
|
|
68
|
+
int codepoint; /* 4 byte -- codepoint or 0 if none */
|
|
69
|
+
} trienode_t;
|
|
70
|
+
|
|
71
|
+
static const trienode_t entities[];
|
|
72
|
+
static int html_named_entity_decode(const char* s, size_t len, size_t* consumed);
|
|
73
|
+
|
|
74
|
+
static int html_named_entity_decode(const char* s, size_t len, size_t* consumed)
|
|
75
|
+
{
|
|
76
|
+
int codepoint = 0;
|
|
77
|
+
size_t pos = 0;
|
|
78
|
+
int i = 0;
|
|
79
|
+
|
|
80
|
+
*consumed = 0;
|
|
81
|
+
|
|
82
|
+
while (pos < len) {
|
|
83
|
+
if (s[pos] == entities[i].value) {
|
|
84
|
+
if (entities[i].codepoint) {
|
|
85
|
+
codepoint = entities[i].codepoint;
|
|
86
|
+
*consumed = pos + 1;
|
|
87
|
+
}
|
|
88
|
+
if (entities[i].next != 0) {
|
|
89
|
+
i = entities[i].next;
|
|
90
|
+
pos += 1;
|
|
91
|
+
continue;
|
|
92
|
+
} else {
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (entities[i].more == 0) {
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
++i;
|
|
100
|
+
}
|
|
101
|
+
return codepoint;
|
|
102
|
+
}
|
|
103
|
+
/*
|
|
104
|
+
#include <stdio.h>
|
|
105
|
+
int main(int argc, char* argv[]) {
|
|
106
|
+
size_t consumed;
|
|
107
|
+
int codepoint;
|
|
108
|
+
codepoint = html_named_entity_decode(argv[1], strlen(argv[1]), &consumed);
|
|
109
|
+
printf("cp = %d, consumed = %d\\n", codepoint, consumed);
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
*/
|
|
113
|
+
static const trienode_t entities[] = {
|
|
114
|
+
"""
|
|
115
|
+
for leaf in self.struct:
|
|
116
|
+
nodelen = 0
|
|
117
|
+
for node in leaf:
|
|
118
|
+
nodelen += 1
|
|
119
|
+
if node['full'] != None:
|
|
120
|
+
comment = ' /* &' + node['full'] + ' */'
|
|
121
|
+
else:
|
|
122
|
+
comment = ''
|
|
123
|
+
|
|
124
|
+
print "{{ {0}, {1}, {2}, {3} }},{4}".format(ord(node['value']),
|
|
125
|
+
int(nodelen != len(leaf)),
|
|
126
|
+
offsets[node['next']],
|
|
127
|
+
node['userdata'],
|
|
128
|
+
comment
|
|
129
|
+
)
|
|
130
|
+
print "};"
|
|
131
|
+
print "#endif"
|
|
132
|
+
|
|
133
|
+
def add(self, s, userdata):
|
|
134
|
+
idx = 0
|
|
135
|
+
leaf = self.struct[0]
|
|
136
|
+
count = 0
|
|
137
|
+
for ch in s[0:-1]:
|
|
138
|
+
#print "CHAR " + i
|
|
139
|
+
key = None
|
|
140
|
+
for node in leaf:
|
|
141
|
+
if ch == node['value']:
|
|
142
|
+
key = node
|
|
143
|
+
break
|
|
144
|
+
if key is None:
|
|
145
|
+
#print "key is none"
|
|
146
|
+
newleaf = [ ]
|
|
147
|
+
self.struct.append(newleaf)
|
|
148
|
+
idx = len(self.struct) -1
|
|
149
|
+
leaf.append( {
|
|
150
|
+
"full": None,
|
|
151
|
+
"value": ch,
|
|
152
|
+
"userdata": 0,
|
|
153
|
+
"next": idx
|
|
154
|
+
} )
|
|
155
|
+
leaf = newleaf
|
|
156
|
+
elif key['next'] != 0:
|
|
157
|
+
# just follow
|
|
158
|
+
#print "got key index of " + str(key[1])
|
|
159
|
+
leaf = self.struct[key['next']]
|
|
160
|
+
else:
|
|
161
|
+
newleaf = [ ]
|
|
162
|
+
self.struct.append(newleaf)
|
|
163
|
+
idx = len(self.struct) -1
|
|
164
|
+
key['next'] = idx
|
|
165
|
+
leaf = newleaf
|
|
166
|
+
|
|
167
|
+
key = None
|
|
168
|
+
ch = s[-1]
|
|
169
|
+
for node in leaf:
|
|
170
|
+
if ch == node['value']:
|
|
171
|
+
key = node
|
|
172
|
+
break
|
|
173
|
+
if key is None:
|
|
174
|
+
leaf.append( {
|
|
175
|
+
'full': s,
|
|
176
|
+
'userdata': userdata,
|
|
177
|
+
'next': 0,
|
|
178
|
+
'value': s[-1]
|
|
179
|
+
})
|
|
180
|
+
else:
|
|
181
|
+
key['full'] = s
|
|
182
|
+
key['userdata'] = userdata
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
import json
|
|
187
|
+
with open('entities.json', 'r') as fd:
|
|
188
|
+
obj = json.load(fd)
|
|
189
|
+
|
|
190
|
+
t = Trie()
|
|
191
|
+
total = 0
|
|
192
|
+
for name, data in obj.iteritems():
|
|
193
|
+
total += len(name) -1
|
|
194
|
+
t.add(name[1:], data['codepoints'][0])
|
|
195
|
+
|
|
196
|
+
#for i in ["fo", "fa", "foo"]:
|
|
197
|
+
# t.add(i)
|
|
198
|
+
|
|
199
|
+
#t.dump()
|
|
200
|
+
#print t.longest_match("amp;")
|
|
201
|
+
|
|
202
|
+
t.compile()
|
|
203
|
+
|