ffi-hydrogen 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,339 @@
|
|
1
|
+
/* we compile as C90 but use snprintf */
|
2
|
+
#define _ISOC99_SOURCE
|
3
|
+
#include <stdio.h>
|
4
|
+
#include <stdlib.h>
|
5
|
+
#include <string.h>
|
6
|
+
|
7
|
+
#include "minunit.h"
|
8
|
+
|
9
|
+
#include "modp_xml.h"
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Test empty input to decode
|
13
|
+
*/
|
14
|
+
static char* testXmlDecodeEmpty(void)
|
15
|
+
{
|
16
|
+
size_t d;
|
17
|
+
char buf[1000];
|
18
|
+
|
19
|
+
buf[0] = 1;
|
20
|
+
d = modp_xml_decode(buf, "", (size_t)0);
|
21
|
+
mu_assert_int_equals(d, 0);
|
22
|
+
mu_assert(buf[0] == 0);
|
23
|
+
|
24
|
+
return 0;
|
25
|
+
}
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Test characters that should be unchanged
|
29
|
+
* Mostly a copy from URL encoding
|
30
|
+
*/
|
31
|
+
static char* testXmlDecodeUntouched(void)
|
32
|
+
{
|
33
|
+
const char* lower = "abcdefghijklmnopqrstuvwxyz";
|
34
|
+
const char* upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
35
|
+
const char* digits = "0123456789";
|
36
|
+
const char* special = ".-_~!$()*,;:@/?";
|
37
|
+
char buf[1000];
|
38
|
+
|
39
|
+
size_t d = 0;
|
40
|
+
|
41
|
+
memset(buf, 0, sizeof(buf));
|
42
|
+
d = modp_xml_decode(buf, lower, strlen(lower));
|
43
|
+
mu_assert_int_equals(d, strlen(lower));
|
44
|
+
mu_assert_str_equals(buf, lower);
|
45
|
+
|
46
|
+
memset(buf, 0, sizeof(buf));
|
47
|
+
d = modp_xml_decode(buf, upper, strlen(upper));
|
48
|
+
mu_assert_int_equals(d, strlen(upper));
|
49
|
+
mu_assert_str_equals(buf, upper);
|
50
|
+
|
51
|
+
memset(buf, 0, sizeof(buf));
|
52
|
+
d = modp_xml_decode(buf, digits, strlen(digits));
|
53
|
+
mu_assert_int_equals(d, strlen(digits));
|
54
|
+
mu_assert_str_equals(buf, digits);
|
55
|
+
|
56
|
+
memset(buf, 0, sizeof(buf));
|
57
|
+
d = modp_xml_decode(buf, special, strlen(special));
|
58
|
+
mu_assert_int_equals(d, strlen(special));
|
59
|
+
mu_assert_str_equals(buf, special);
|
60
|
+
|
61
|
+
return 0;
|
62
|
+
}
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Test characters that should be unchanged
|
66
|
+
* Mostly a copy from URL encoding
|
67
|
+
*/
|
68
|
+
static char* testXmlDecodeNames(void)
|
69
|
+
{
|
70
|
+
const char* strin = "X"X'X&X>X<X";
|
71
|
+
const char* strout = "X\"X'X&X>X<X";
|
72
|
+
|
73
|
+
char buf[1000];
|
74
|
+
size_t d = 0;
|
75
|
+
|
76
|
+
memset(buf, 0, sizeof(buf));
|
77
|
+
d = modp_xml_decode(buf, strin, strlen(strin));
|
78
|
+
mu_assert_int_equals(d, strlen(strout));
|
79
|
+
|
80
|
+
mu_assert_str_equals(strout, buf);
|
81
|
+
|
82
|
+
return 0;
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Bad entity name.. not existent
|
87
|
+
*/
|
88
|
+
static char* testXmlDecodeBadNames1(void)
|
89
|
+
{
|
90
|
+
const char* strin = "X&quo;X";
|
91
|
+
const char* strout = "X&quo;X";
|
92
|
+
|
93
|
+
char buf[1000];
|
94
|
+
size_t d = 0;
|
95
|
+
|
96
|
+
memset(buf, 0, sizeof(buf));
|
97
|
+
d = modp_xml_decode(buf, strin, strlen(strin));
|
98
|
+
mu_assert_int_equals(d, strlen(strout));
|
99
|
+
mu_assert_str_equals(strout, buf);
|
100
|
+
|
101
|
+
return 0;
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Bad entity name -- no semi-colon
|
106
|
+
*/
|
107
|
+
static char* testXmlDecodeBadNames2(void)
|
108
|
+
{
|
109
|
+
const char* strin = "X"X";
|
110
|
+
const char* strout = "X"X";
|
111
|
+
|
112
|
+
char buf[1000];
|
113
|
+
size_t d = 0;
|
114
|
+
|
115
|
+
memset(buf, 0, sizeof(buf));
|
116
|
+
d = modp_xml_decode(buf, strin, strlen(strin));
|
117
|
+
mu_assert_int_equals(d, strlen(strout));
|
118
|
+
mu_assert_str_equals(strout, buf);
|
119
|
+
|
120
|
+
return 0;
|
121
|
+
}
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Bad entity name -- no name!
|
125
|
+
*/
|
126
|
+
static char* testXmlDecodeBadNames3(void)
|
127
|
+
{
|
128
|
+
const char* strin = "X&;X";
|
129
|
+
const char* strout = "X&;X";
|
130
|
+
|
131
|
+
char buf[1000];
|
132
|
+
size_t d = 0;
|
133
|
+
|
134
|
+
memset(buf, 0, sizeof(buf));
|
135
|
+
d = modp_xml_decode(buf, strin, strlen(strin));
|
136
|
+
mu_assert_int_equals(d, strlen(strout));
|
137
|
+
mu_assert_str_equals(strout, buf);
|
138
|
+
|
139
|
+
return 0;
|
140
|
+
}
|
141
|
+
|
142
|
+
/**
|
143
|
+
* Bad entity name -- boundary!
|
144
|
+
*/
|
145
|
+
static char* testXmlDecodeBadNames4(void)
|
146
|
+
{
|
147
|
+
const char* strin = "X&;";
|
148
|
+
const char* strout = "X&;";
|
149
|
+
|
150
|
+
char buf[1000];
|
151
|
+
size_t d = 0;
|
152
|
+
|
153
|
+
memset(buf, 0, sizeof(buf));
|
154
|
+
d = modp_xml_decode(buf, strin, strlen(strin));
|
155
|
+
mu_assert_int_equals(d, strlen(strout));
|
156
|
+
mu_assert_str_equals(strout, buf);
|
157
|
+
|
158
|
+
return 0;
|
159
|
+
}
|
160
|
+
|
161
|
+
/**
|
162
|
+
* Bad entity name -- boundary!
|
163
|
+
*/
|
164
|
+
static char* testXmlDecodeBadNames5(void)
|
165
|
+
{
|
166
|
+
const char* strin = "X&";
|
167
|
+
const char* strout = "X&";
|
168
|
+
|
169
|
+
char buf[1000];
|
170
|
+
size_t d = 0;
|
171
|
+
|
172
|
+
memset(buf, 0, sizeof(buf));
|
173
|
+
d = modp_xml_decode(buf, strin, strlen(strin));
|
174
|
+
mu_assert_int_equals(d, strlen(strout));
|
175
|
+
mu_assert_str_equals(strout, buf);
|
176
|
+
|
177
|
+
return 0;
|
178
|
+
}
|
179
|
+
|
180
|
+
/**
|
181
|
+
* Bad entity name.. case sensitive
|
182
|
+
*/
|
183
|
+
static char* testXmlDecodeBadNames6(void)
|
184
|
+
{
|
185
|
+
const char* strin = "X"X";
|
186
|
+
const char* strout = "X"X";
|
187
|
+
|
188
|
+
char buf[1000];
|
189
|
+
size_t d = 0;
|
190
|
+
|
191
|
+
memset(buf, 0, sizeof(buf));
|
192
|
+
d = modp_xml_decode(buf, strin, strlen(strin));
|
193
|
+
mu_assert_int_equals(d, strlen(strout));
|
194
|
+
mu_assert_str_equals(strout, buf);
|
195
|
+
|
196
|
+
return 0;
|
197
|
+
}
|
198
|
+
|
199
|
+
static char* testXmlUnicodeCodePoints(void)
|
200
|
+
{
|
201
|
+
static const int ranges[] = {
|
202
|
+
0x0000, 0x0008, /* control characters */
|
203
|
+
0x000B, 0x000B, /* Vertical Tab is forbidden, ?? */
|
204
|
+
0x000E, 0x001F, /* control characters */
|
205
|
+
0x0080, 0x009F, /* control characters */
|
206
|
+
0x0750, 0x077D, /* the rest are undefined */
|
207
|
+
0x07C0, 0x08FF,
|
208
|
+
0x1380, 0x139F,
|
209
|
+
0x18B0, 0x18FF,
|
210
|
+
0x1980, 0x19DF,
|
211
|
+
0x1A00, 0x1CFF,
|
212
|
+
0x1D80, 0x1DFF,
|
213
|
+
0x2C00, 0x2E7F,
|
214
|
+
0x2FE0, 0x2FEF,
|
215
|
+
0x31C0, 0x31EF,
|
216
|
+
0x9FB0, 0x9FFF,
|
217
|
+
0xA4D0, 0xABFF,
|
218
|
+
0xD7B0, 0xD7FF,
|
219
|
+
0xFE10, 0xFE1F,
|
220
|
+
0x10140, 0x102FF,
|
221
|
+
0x104B0, 0x107FF,
|
222
|
+
0x1D200, 0x1D2FF,
|
223
|
+
0x1D360, 0x1D3FF,
|
224
|
+
0x1D800, 0x1FFFF,
|
225
|
+
0x2A6E0, 0x2F7FF,
|
226
|
+
0x2FAB0, 0xDFFFF,
|
227
|
+
0xE0080, 0xE00FF,
|
228
|
+
0xE01F0, 0xEFFFF,
|
229
|
+
0xFFFFE, 0xFFFFF
|
230
|
+
};
|
231
|
+
static const int imax = sizeof(ranges) / sizeof(uint32_t);
|
232
|
+
int i;
|
233
|
+
for (i = 0; i < imax; ++i) {
|
234
|
+
mu_assert_int_equals(-1, modp_xml_validate_unicode(ranges[i]));
|
235
|
+
}
|
236
|
+
|
237
|
+
/* too big */
|
238
|
+
mu_assert_int_equals(-1, modp_xml_validate_unicode(0xFFFFFF));
|
239
|
+
|
240
|
+
/* ok */
|
241
|
+
mu_assert_int_equals(0x41, modp_xml_validate_unicode(0x41));
|
242
|
+
return 0;
|
243
|
+
}
|
244
|
+
|
245
|
+
static char* testXmlUnicodeCharToUTF8(void)
|
246
|
+
{
|
247
|
+
char buf[1000];
|
248
|
+
size_t d = 0;
|
249
|
+
int val = 0;
|
250
|
+
|
251
|
+
d = modp_xml_unicode_char_to_utf8(buf, 0x41);
|
252
|
+
mu_assert_int_equals(1, d);
|
253
|
+
buf[d] = '\0';
|
254
|
+
mu_assert_str_equals(buf, "A");
|
255
|
+
|
256
|
+
/* Cent symbol */
|
257
|
+
d = modp_xml_unicode_char_to_utf8(buf, 0x00A2);
|
258
|
+
mu_assert_int_equals(2, d);
|
259
|
+
val = (unsigned char)buf[0];
|
260
|
+
mu_assert_int_equals(val, 0xC2);
|
261
|
+
val = (unsigned char)buf[1];
|
262
|
+
mu_assert_int_equals(val, 0xA2);
|
263
|
+
|
264
|
+
/* Euro symbol */
|
265
|
+
d = modp_xml_unicode_char_to_utf8(buf, 0x20AC);
|
266
|
+
mu_assert_int_equals(3, d);
|
267
|
+
val = (unsigned char)buf[0];
|
268
|
+
mu_assert_int_equals(val, 0xE2);
|
269
|
+
val = (unsigned char)buf[1];
|
270
|
+
mu_assert_int_equals(val, 0x82);
|
271
|
+
val = (unsigned char)buf[2];
|
272
|
+
mu_assert_int_equals(val, 0xAC);
|
273
|
+
|
274
|
+
/* Chinese Character */
|
275
|
+
d = modp_xml_unicode_char_to_utf8(buf, 0x24B62);
|
276
|
+
mu_assert_int_equals(4, d);
|
277
|
+
val = (unsigned char)buf[0];
|
278
|
+
mu_assert_int_equals(val, 0xF0);
|
279
|
+
val = (unsigned char)buf[1];
|
280
|
+
mu_assert_int_equals(val, 0xA4);
|
281
|
+
val = (unsigned char)buf[2];
|
282
|
+
mu_assert_int_equals(val, 0xAD);
|
283
|
+
val = (unsigned char)buf[3];
|
284
|
+
mu_assert_int_equals(val, 0xA2);
|
285
|
+
|
286
|
+
return 0;
|
287
|
+
}
|
288
|
+
|
289
|
+
static char* testXmlDecodeDecimalEntities(void)
|
290
|
+
{
|
291
|
+
const char* strin = "XAX";
|
292
|
+
const char* strout = "XAX";
|
293
|
+
|
294
|
+
char buf[1000];
|
295
|
+
size_t d = 0;
|
296
|
+
|
297
|
+
memset(buf, 0, sizeof(buf));
|
298
|
+
d = modp_xml_decode(buf, strin, strlen(strin));
|
299
|
+
mu_assert_int_equals(d, strlen(strout));
|
300
|
+
mu_assert_str_equals(strout, buf);
|
301
|
+
|
302
|
+
return 0;
|
303
|
+
}
|
304
|
+
|
305
|
+
static char* testXmlDecodeHexEntities(void)
|
306
|
+
{
|
307
|
+
const char* strin = "XAX";
|
308
|
+
const char* strout = "XAX";
|
309
|
+
|
310
|
+
char buf[1000];
|
311
|
+
size_t d = 0;
|
312
|
+
|
313
|
+
memset(buf, 0, sizeof(buf));
|
314
|
+
d = modp_xml_decode(buf, strin, strlen(strin));
|
315
|
+
mu_assert_int_equals(d, strlen(strout));
|
316
|
+
mu_assert_str_equals(strout, buf);
|
317
|
+
|
318
|
+
return 0;
|
319
|
+
}
|
320
|
+
|
321
|
+
static char* all_tests(void)
|
322
|
+
{
|
323
|
+
mu_run_test(testXmlDecodeEmpty);
|
324
|
+
mu_run_test(testXmlDecodeUntouched);
|
325
|
+
mu_run_test(testXmlDecodeNames);
|
326
|
+
mu_run_test(testXmlDecodeBadNames1);
|
327
|
+
mu_run_test(testXmlDecodeBadNames2);
|
328
|
+
mu_run_test(testXmlDecodeBadNames3);
|
329
|
+
mu_run_test(testXmlDecodeBadNames4);
|
330
|
+
mu_run_test(testXmlDecodeBadNames5);
|
331
|
+
mu_run_test(testXmlDecodeBadNames6);
|
332
|
+
mu_run_test(testXmlUnicodeCodePoints);
|
333
|
+
mu_run_test(testXmlUnicodeCharToUTF8);
|
334
|
+
mu_run_test(testXmlDecodeDecimalEntities);
|
335
|
+
mu_run_test(testXmlDecodeHexEntities);
|
336
|
+
return 0;
|
337
|
+
}
|
338
|
+
|
339
|
+
UNITTESTS
|
@@ -0,0 +1,241 @@
|
|
1
|
+
/** \file speedtest.c
|
2
|
+
*
|
3
|
+
* Copyright 2005-2016 Nick Galbreath -- nickg [at] client9 [dot] com
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* https://github.com/client9/stringencoders/
|
7
|
+
*
|
8
|
+
* Released under MIT license. See LICENSE for details.
|
9
|
+
*
|
10
|
+
* Quickie performance tester. This does NOT test correctness.
|
11
|
+
*
|
12
|
+
*/
|
13
|
+
|
14
|
+
#include "apr_base64.h"
|
15
|
+
#include "modp_b16.h"
|
16
|
+
#include "modp_b2.h"
|
17
|
+
#include "modp_b64.h"
|
18
|
+
#include "modp_b85.h"
|
19
|
+
#include "modp_bjavascript.h"
|
20
|
+
#include "modp_burl.h"
|
21
|
+
|
22
|
+
#include <time.h>
|
23
|
+
#ifndef CLOCKS_PER_SEC
|
24
|
+
#ifdef CLK_TCK
|
25
|
+
#define CLOCKS_PER_SEC (CLK_TCK)
|
26
|
+
#endif
|
27
|
+
#endif
|
28
|
+
#include <stdio.h>
|
29
|
+
#include <string.h>
|
30
|
+
|
31
|
+
#define SZ 4096
|
32
|
+
int main(void)
|
33
|
+
{
|
34
|
+
double s1, s2;
|
35
|
+
int i, j;
|
36
|
+
clock_t c0, c1;
|
37
|
+
char teststr1[SZ];
|
38
|
+
|
39
|
+
/*
|
40
|
+
this contains the message sizes we'll test on
|
41
|
+
add, subtract, change as desired.
|
42
|
+
*/
|
43
|
+
size_t sizes[] = { 20, 200, 2000 };
|
44
|
+
|
45
|
+
for (i = 0; i < (int)sizeof(teststr1); ++i) {
|
46
|
+
teststr1[i] = (char)('A' + i % 26);
|
47
|
+
}
|
48
|
+
|
49
|
+
/* over allocate result buffers */
|
50
|
+
char result[SZ * 8];
|
51
|
+
char result2[SZ * 8];
|
52
|
+
|
53
|
+
const int MAX = 1000000;
|
54
|
+
|
55
|
+
for (j = 0; j < (int)(sizeof(sizes) / sizeof(size_t)); ++j) {
|
56
|
+
printf("\nMessage size = %d\n", (int)sizes[j]);
|
57
|
+
|
58
|
+
printf("\tmodpb64\tapache\timprovement\tmodpb85\tmodpurl\tmodpb16\tmodpb2\tmodpjs\n");
|
59
|
+
printf("Encode\t");
|
60
|
+
fflush(stdout);
|
61
|
+
|
62
|
+
/* MODP_B64 ENCODE */
|
63
|
+
c0 = clock();
|
64
|
+
for (i = 0; i < MAX; ++i) {
|
65
|
+
modp_b64_encode(result, teststr1, sizes[j]);
|
66
|
+
}
|
67
|
+
c1 = clock();
|
68
|
+
s1 = (double)(c1 - c0) * (1.0 / (double)CLOCKS_PER_SEC);
|
69
|
+
printf("%6.2f\t", s1);
|
70
|
+
fflush(stdout);
|
71
|
+
|
72
|
+
/* APACHE ENCODE */
|
73
|
+
c0 = clock();
|
74
|
+
for (i = 0; i < MAX; ++i) {
|
75
|
+
apr_base64_encode_binary(result,
|
76
|
+
(const unsigned char*)teststr1,
|
77
|
+
(int)sizes[j]);
|
78
|
+
}
|
79
|
+
c1 = clock();
|
80
|
+
s2 = (double)(c1 - c0) * (1.0 / (double)CLOCKS_PER_SEC);
|
81
|
+
printf("%6.2f\t", s2);
|
82
|
+
printf("%6.2fx\t\t", s2 / s1);
|
83
|
+
fflush(stdout);
|
84
|
+
|
85
|
+
/*
|
86
|
+
* base85 encode, let's see what is faster
|
87
|
+
*/
|
88
|
+
c0 = clock();
|
89
|
+
for (i = 0; i < MAX; ++i) {
|
90
|
+
modp_b85_encode(result, teststr1, sizes[j]);
|
91
|
+
}
|
92
|
+
c1 = clock();
|
93
|
+
s1 = (double)(c1 - c0) * (1.0 / (double)CLOCKS_PER_SEC);
|
94
|
+
printf("%6.2f\t", s1);
|
95
|
+
fflush(stdout);
|
96
|
+
|
97
|
+
/*
|
98
|
+
* url encode
|
99
|
+
*/
|
100
|
+
c0 = clock();
|
101
|
+
for (i = 0; i < MAX; ++i) {
|
102
|
+
modp_burl_encode(result, teststr1, sizes[j]);
|
103
|
+
}
|
104
|
+
c1 = clock();
|
105
|
+
s1 = (double)(c1 - c0) * (1.0 / (double)CLOCKS_PER_SEC);
|
106
|
+
printf("%6.2f\t", s1);
|
107
|
+
fflush(stdout);
|
108
|
+
|
109
|
+
/**
|
110
|
+
* B16
|
111
|
+
*/
|
112
|
+
c0 = clock();
|
113
|
+
for (i = 0; i < MAX; ++i) {
|
114
|
+
modp_b16_encode(result, teststr1, sizes[j]);
|
115
|
+
}
|
116
|
+
c1 = clock();
|
117
|
+
s1 = (double)(c1 - c0) * (1.0 / (double)CLOCKS_PER_SEC);
|
118
|
+
printf("%6.2f\t", s1);
|
119
|
+
fflush(stdout);
|
120
|
+
|
121
|
+
/**
|
122
|
+
* B2 BINARY
|
123
|
+
*/
|
124
|
+
c0 = clock();
|
125
|
+
for (i = 0; i < MAX; ++i) {
|
126
|
+
modp_b2_encode(result, teststr1, sizes[j]);
|
127
|
+
}
|
128
|
+
c1 = clock();
|
129
|
+
s1 = (double)(c1 - c0) * (1.0 / (double)CLOCKS_PER_SEC);
|
130
|
+
printf("%6.2f\t", s1);
|
131
|
+
fflush(stdout);
|
132
|
+
|
133
|
+
/**
|
134
|
+
* javascript
|
135
|
+
*/
|
136
|
+
c0 = clock();
|
137
|
+
for (i = 0; i < MAX; ++i) {
|
138
|
+
modp_bjavascript_encode(result, teststr1, sizes[j]);
|
139
|
+
}
|
140
|
+
c1 = clock();
|
141
|
+
s1 = (double)(c1 - c0) * (1.0 / (double)CLOCKS_PER_SEC);
|
142
|
+
printf("%6.2f\t", s1);
|
143
|
+
fflush(stdout);
|
144
|
+
|
145
|
+
printf("\n");
|
146
|
+
fflush(stdout);
|
147
|
+
|
148
|
+
/***
|
149
|
+
* DECODE
|
150
|
+
*/
|
151
|
+
/* reset result to have b64 chars */
|
152
|
+
modp_b64_encode(result, teststr1, sizes[j]);
|
153
|
+
size_t len = strlen(result);
|
154
|
+
|
155
|
+
printf("Decode\t");
|
156
|
+
fflush(stdout);
|
157
|
+
|
158
|
+
/* MODP_B64 */
|
159
|
+
c0 = clock();
|
160
|
+
for (i = 0; i < MAX; ++i) {
|
161
|
+
modp_b64_decode(result2, result, len);
|
162
|
+
}
|
163
|
+
c1 = clock();
|
164
|
+
s1 = (double)(c1 - c0) * (1.0 / (double)CLOCKS_PER_SEC);
|
165
|
+
printf("%6.2f\t", s1);
|
166
|
+
fflush(stdout);
|
167
|
+
|
168
|
+
/* APACHE */
|
169
|
+
c0 = clock();
|
170
|
+
for (i = 0; i < MAX; ++i) {
|
171
|
+
apr_base64_decode_binary((unsigned char*)result2, result);
|
172
|
+
}
|
173
|
+
c1 = clock();
|
174
|
+
s2 = (double)(c1 - c0) * (1.0 / (double)CLOCKS_PER_SEC);
|
175
|
+
printf("%6.2f\t", s2);
|
176
|
+
printf("%6.2fx\t\t", s2 / s1);
|
177
|
+
fflush(stdout);
|
178
|
+
|
179
|
+
/*
|
180
|
+
* modp_b85 decode
|
181
|
+
*/
|
182
|
+
/* re-encode to get b85 chars, not b64 */
|
183
|
+
len = modp_b85_encode(result, teststr1, sizes[j]);
|
184
|
+
|
185
|
+
c0 = clock();
|
186
|
+
for (i = 0; i < MAX; ++i) {
|
187
|
+
modp_b85_decode(result2, result, len);
|
188
|
+
}
|
189
|
+
c1 = clock();
|
190
|
+
s1 = (double)(c1 - c0) * (1.0 / (double)CLOCKS_PER_SEC);
|
191
|
+
printf("%6.2f\t", s1);
|
192
|
+
fflush(stdout);
|
193
|
+
|
194
|
+
/* re-encode to get urlencoded chars, not b64 */
|
195
|
+
len = modp_burl_encode(result, teststr1, sizes[j]);
|
196
|
+
|
197
|
+
c0 = clock();
|
198
|
+
for (i = 0; i < MAX; ++i) {
|
199
|
+
modp_burl_decode(result2, result, len);
|
200
|
+
}
|
201
|
+
c1 = clock();
|
202
|
+
s1 = (double)(c1 - c0) * (1.0 / (double)CLOCKS_PER_SEC);
|
203
|
+
printf("%6.2f\t", s1);
|
204
|
+
fflush(stdout);
|
205
|
+
|
206
|
+
/**
|
207
|
+
** B16 DECODE
|
208
|
+
**/
|
209
|
+
/* re-encode to get urlencoded chars, not b64 */
|
210
|
+
len = modp_b16_encode(result, teststr1, sizes[j]);
|
211
|
+
|
212
|
+
c0 = clock();
|
213
|
+
for (i = 0; i < MAX; ++i) {
|
214
|
+
modp_b16_decode(result2, result, len);
|
215
|
+
}
|
216
|
+
c1 = clock();
|
217
|
+
s1 = (double)(c1 - c0) * (1.0 / (double)CLOCKS_PER_SEC);
|
218
|
+
printf("%6.2f\t", s1);
|
219
|
+
fflush(stdout);
|
220
|
+
|
221
|
+
/**
|
222
|
+
** B16 DECODE
|
223
|
+
**/
|
224
|
+
/* re-encode to get urlencoded chars, not b64 */
|
225
|
+
len = modp_b2_encode(result, teststr1, sizes[j]);
|
226
|
+
|
227
|
+
c0 = clock();
|
228
|
+
for (i = 0; i < MAX; ++i) {
|
229
|
+
modp_b2_decode(result2, result, len);
|
230
|
+
}
|
231
|
+
c1 = clock();
|
232
|
+
s1 = (double)(c1 - c0) * (1.0 / (double)CLOCKS_PER_SEC);
|
233
|
+
printf("%6.2f\t", s1);
|
234
|
+
fflush(stdout);
|
235
|
+
|
236
|
+
printf("\n");
|
237
|
+
fflush(stdout);
|
238
|
+
}
|
239
|
+
|
240
|
+
return 0;
|
241
|
+
}
|