ffi-hydrogen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +30 -0
  5. data/.travis.yml +10 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +72 -0
  9. data/Rakefile +46 -0
  10. data/bench/both.rb +86 -0
  11. data/bench/encode.rb +57 -0
  12. data/bench/encrypt.rb +80 -0
  13. data/bench/init.rb +5 -0
  14. data/bin/console +14 -0
  15. data/bin/setup +8 -0
  16. data/ffi-hydrogen.gemspec +31 -0
  17. data/lib/ffi/hydrogen.rb +216 -0
  18. data/vendor/.clang-format +2 -0
  19. data/vendor/.gitignore +3 -0
  20. data/vendor/README.md +2 -0
  21. data/vendor/libhydrogen/.clang-format +95 -0
  22. data/vendor/libhydrogen/.gitignore +32 -0
  23. data/vendor/libhydrogen/.travis.yml +22 -0
  24. data/vendor/libhydrogen/LICENSE +18 -0
  25. data/vendor/libhydrogen/Makefile +61 -0
  26. data/vendor/libhydrogen/Makefile.arduino +51 -0
  27. data/vendor/libhydrogen/README.md +29 -0
  28. data/vendor/libhydrogen/hydrogen.c +18 -0
  29. data/vendor/libhydrogen/hydrogen.h +317 -0
  30. data/vendor/libhydrogen/impl/common.h +316 -0
  31. data/vendor/libhydrogen/impl/core.h +220 -0
  32. data/vendor/libhydrogen/impl/gimli-core/portable.h +39 -0
  33. data/vendor/libhydrogen/impl/gimli-core/sse2.h +97 -0
  34. data/vendor/libhydrogen/impl/gimli-core.h +25 -0
  35. data/vendor/libhydrogen/impl/hash.h +138 -0
  36. data/vendor/libhydrogen/impl/hydrogen_p.h +83 -0
  37. data/vendor/libhydrogen/impl/kdf.h +20 -0
  38. data/vendor/libhydrogen/impl/kx.h +441 -0
  39. data/vendor/libhydrogen/impl/pwhash.h +281 -0
  40. data/vendor/libhydrogen/impl/random.h +376 -0
  41. data/vendor/libhydrogen/impl/secretbox.h +236 -0
  42. data/vendor/libhydrogen/impl/sign.h +207 -0
  43. data/vendor/libhydrogen/impl/x25519.h +383 -0
  44. data/vendor/libhydrogen/library.properties +10 -0
  45. data/vendor/libhydrogen/logo.png +0 -0
  46. data/vendor/libhydrogen/tests/tests.c +431 -0
  47. data/vendor/main.c +140 -0
  48. data/vendor/stringencoders/.gitignore +25 -0
  49. data/vendor/stringencoders/.travis.yml +13 -0
  50. data/vendor/stringencoders/AUTHORS +1 -0
  51. data/vendor/stringencoders/COPYING +2 -0
  52. data/vendor/stringencoders/ChangeLog +170 -0
  53. data/vendor/stringencoders/Doxyfile +276 -0
  54. data/vendor/stringencoders/INSTALL +119 -0
  55. data/vendor/stringencoders/LICENSE +22 -0
  56. data/vendor/stringencoders/Makefile.am +3 -0
  57. data/vendor/stringencoders/NEWS +3 -0
  58. data/vendor/stringencoders/README +2 -0
  59. data/vendor/stringencoders/README.md +32 -0
  60. data/vendor/stringencoders/bootstrap.sh +3 -0
  61. data/vendor/stringencoders/configure-gcc-hardened.sh +16 -0
  62. data/vendor/stringencoders/configure.ac +44 -0
  63. data/vendor/stringencoders/doxy/footer.html +34 -0
  64. data/vendor/stringencoders/doxy/header.html +85 -0
  65. data/vendor/stringencoders/indent.sh +9 -0
  66. data/vendor/stringencoders/javascript/base64-speed.html +43 -0
  67. data/vendor/stringencoders/javascript/base64-test.html +209 -0
  68. data/vendor/stringencoders/javascript/base64.html +18 -0
  69. data/vendor/stringencoders/javascript/base64.js +176 -0
  70. data/vendor/stringencoders/javascript/qunit.css +119 -0
  71. data/vendor/stringencoders/javascript/qunit.js +1062 -0
  72. data/vendor/stringencoders/javascript/urlparse-test.html +367 -0
  73. data/vendor/stringencoders/javascript/urlparse.js +328 -0
  74. data/vendor/stringencoders/make-ci.sh +13 -0
  75. data/vendor/stringencoders/makerelease.sh +16 -0
  76. data/vendor/stringencoders/python/b85.py +176 -0
  77. data/vendor/stringencoders/src/Makefile.am +134 -0
  78. data/vendor/stringencoders/src/arraytoc.c +85 -0
  79. data/vendor/stringencoders/src/arraytoc.h +43 -0
  80. data/vendor/stringencoders/src/extern_c_begin.h +3 -0
  81. data/vendor/stringencoders/src/extern_c_end.h +3 -0
  82. data/vendor/stringencoders/src/html_named_entities_generator.py +203 -0
  83. data/vendor/stringencoders/src/modp_ascii.c +159 -0
  84. data/vendor/stringencoders/src/modp_ascii.h +162 -0
  85. data/vendor/stringencoders/src/modp_ascii_data.h +84 -0
  86. data/vendor/stringencoders/src/modp_ascii_gen.c +55 -0
  87. data/vendor/stringencoders/src/modp_b16.c +125 -0
  88. data/vendor/stringencoders/src/modp_b16.h +148 -0
  89. data/vendor/stringencoders/src/modp_b16_data.h +104 -0
  90. data/vendor/stringencoders/src/modp_b16_gen.c +65 -0
  91. data/vendor/stringencoders/src/modp_b2.c +69 -0
  92. data/vendor/stringencoders/src/modp_b2.h +130 -0
  93. data/vendor/stringencoders/src/modp_b2_data.h +44 -0
  94. data/vendor/stringencoders/src/modp_b2_gen.c +36 -0
  95. data/vendor/stringencoders/src/modp_b36.c +108 -0
  96. data/vendor/stringencoders/src/modp_b36.h +170 -0
  97. data/vendor/stringencoders/src/modp_b64.c +254 -0
  98. data/vendor/stringencoders/src/modp_b64.h +236 -0
  99. data/vendor/stringencoders/src/modp_b64_data.h +477 -0
  100. data/vendor/stringencoders/src/modp_b64_gen.c +168 -0
  101. data/vendor/stringencoders/src/modp_b64r.c +254 -0
  102. data/vendor/stringencoders/src/modp_b64r.h +242 -0
  103. data/vendor/stringencoders/src/modp_b64r_data.h +477 -0
  104. data/vendor/stringencoders/src/modp_b64w.c +254 -0
  105. data/vendor/stringencoders/src/modp_b64w.h +231 -0
  106. data/vendor/stringencoders/src/modp_b64w_data.h +477 -0
  107. data/vendor/stringencoders/src/modp_b85.c +109 -0
  108. data/vendor/stringencoders/src/modp_b85.h +171 -0
  109. data/vendor/stringencoders/src/modp_b85_data.h +36 -0
  110. data/vendor/stringencoders/src/modp_b85_gen.c +65 -0
  111. data/vendor/stringencoders/src/modp_bjavascript.c +65 -0
  112. data/vendor/stringencoders/src/modp_bjavascript.h +105 -0
  113. data/vendor/stringencoders/src/modp_bjavascript_data.h +84 -0
  114. data/vendor/stringencoders/src/modp_bjavascript_gen.c +58 -0
  115. data/vendor/stringencoders/src/modp_burl.c +228 -0
  116. data/vendor/stringencoders/src/modp_burl.h +259 -0
  117. data/vendor/stringencoders/src/modp_burl_data.h +136 -0
  118. data/vendor/stringencoders/src/modp_burl_gen.c +121 -0
  119. data/vendor/stringencoders/src/modp_html.c +128 -0
  120. data/vendor/stringencoders/src/modp_html.h +53 -0
  121. data/vendor/stringencoders/src/modp_html_named_entities.h +9910 -0
  122. data/vendor/stringencoders/src/modp_json.c +315 -0
  123. data/vendor/stringencoders/src/modp_json.h +103 -0
  124. data/vendor/stringencoders/src/modp_json_data.h +57 -0
  125. data/vendor/stringencoders/src/modp_json_gen.py +60 -0
  126. data/vendor/stringencoders/src/modp_mainpage.h +120 -0
  127. data/vendor/stringencoders/src/modp_numtoa.c +350 -0
  128. data/vendor/stringencoders/src/modp_numtoa.h +100 -0
  129. data/vendor/stringencoders/src/modp_qsiter.c +76 -0
  130. data/vendor/stringencoders/src/modp_qsiter.h +71 -0
  131. data/vendor/stringencoders/src/modp_stdint.h +43 -0
  132. data/vendor/stringencoders/src/modp_utf8.c +88 -0
  133. data/vendor/stringencoders/src/modp_utf8.h +38 -0
  134. data/vendor/stringencoders/src/modp_xml.c +311 -0
  135. data/vendor/stringencoders/src/modp_xml.h +166 -0
  136. data/vendor/stringencoders/src/stringencoders.pc +10 -0
  137. data/vendor/stringencoders/src/stringencoders.pc.in +10 -0
  138. data/vendor/stringencoders/test/Makefile.am +113 -0
  139. data/vendor/stringencoders/test/apr_base64.c +262 -0
  140. data/vendor/stringencoders/test/apr_base64.h +120 -0
  141. data/vendor/stringencoders/test/cxx_test.cc +482 -0
  142. data/vendor/stringencoders/test/minunit.h +82 -0
  143. data/vendor/stringencoders/test/modp_ascii_test.c +281 -0
  144. data/vendor/stringencoders/test/modp_b16_test.c +288 -0
  145. data/vendor/stringencoders/test/modp_b2_test.c +250 -0
  146. data/vendor/stringencoders/test/modp_b64_test.c +266 -0
  147. data/vendor/stringencoders/test/modp_b85_test.c +130 -0
  148. data/vendor/stringencoders/test/modp_bjavascript_test.c +137 -0
  149. data/vendor/stringencoders/test/modp_burl_test.c +423 -0
  150. data/vendor/stringencoders/test/modp_html_test.c +296 -0
  151. data/vendor/stringencoders/test/modp_json_test.c +336 -0
  152. data/vendor/stringencoders/test/modp_numtoa_test.c +545 -0
  153. data/vendor/stringencoders/test/modp_qsiter_test.c +280 -0
  154. data/vendor/stringencoders/test/modp_utf8_test.c +188 -0
  155. data/vendor/stringencoders/test/modp_xml_test.c +339 -0
  156. data/vendor/stringencoders/test/speedtest.c +241 -0
  157. data/vendor/stringencoders/test/speedtest_ascii.c +345 -0
  158. data/vendor/stringencoders/test/speedtest_msg.c +78 -0
  159. data/vendor/stringencoders/test/speedtest_numtoa.c +276 -0
  160. metadata +314 -0
@@ -0,0 +1,121 @@
1
+ #include "arraytoc.h"
2
+
3
+ static void hexencodemap(void)
4
+ {
5
+ static const char sHexChars[] = "0123456789ABCDEF";
6
+ int i;
7
+ char hexEncode1[256];
8
+ char hexEncode2[256];
9
+ for (i = 0; i < 256; ++i) {
10
+ hexEncode1[i] = sHexChars[i >> 4];
11
+ hexEncode2[i] = sHexChars[i & 0x0f];
12
+ }
13
+
14
+ char_array_to_c(hexEncode1, sizeof(hexEncode1), "gsHexEncodeMap1");
15
+ char_array_to_c(hexEncode2, sizeof(hexEncode2), "gsHexEncodeMap2");
16
+ }
17
+
18
+ static void urlencodemap(void)
19
+ {
20
+ uint32_t i;
21
+ char urlEncodeMap[256];
22
+
23
+ /* 0 means unsafe */
24
+ for (i = 0; i < 256; ++i) {
25
+ urlEncodeMap[i] = 0;
26
+ }
27
+
28
+ /* upper case */
29
+ for (i = 'A'; i <= 'Z'; ++i) {
30
+ urlEncodeMap[i] = (char)i;
31
+ }
32
+ /* lower case */
33
+ for (i = 'a'; i <= 'z'; ++i) {
34
+ urlEncodeMap[i] = (char)i;
35
+ }
36
+ /* numbers */
37
+ for (i = '0'; i <= '9'; ++i) {
38
+ urlEncodeMap[i] = (char)i;
39
+ }
40
+ /* safe chars */
41
+ urlEncodeMap[(int)'.'] = '.';
42
+ urlEncodeMap[(int)'-'] = '-';
43
+ urlEncodeMap[(int)'_'] = '_';
44
+ /* space is special */
45
+ urlEncodeMap[(int)' '] = '+';
46
+
47
+ char_array_to_c(urlEncodeMap, sizeof(urlEncodeMap), "gsUrlEncodeMap");
48
+ }
49
+
50
+ static void urlencodeminmap(void)
51
+ {
52
+ int i;
53
+ char urlEncodeMap[256];
54
+ const char safechar[] = { '_', '.', '-', '~',
55
+ '!', '$', '(', ')', '*', ',', ';',
56
+ ':', '@', '/', '?' };
57
+
58
+ int imax = sizeof(safechar);
59
+
60
+ /* 0 means unsafe */
61
+ for (i = 0; i < 256; ++i) {
62
+ urlEncodeMap[i] = 0;
63
+ }
64
+
65
+ /* upper case */
66
+ for (i = 'A'; i <= 'Z'; ++i) {
67
+ urlEncodeMap[i] = (char)i;
68
+ }
69
+ /* lower case */
70
+ for (i = 'a'; i <= 'z'; ++i) {
71
+ urlEncodeMap[i] = (char)i;
72
+ }
73
+ /* numbers */
74
+ for (i = '0'; i <= '9'; ++i) {
75
+ urlEncodeMap[i] = (char)i;
76
+ }
77
+
78
+ /* space */
79
+ urlEncodeMap[(int)' '] = '+';
80
+
81
+ for (i = 0; i < imax; ++i) {
82
+ urlEncodeMap[(int)(safechar[i])] = safechar[i];
83
+ }
84
+
85
+ char_array_to_c(urlEncodeMap, sizeof(urlEncodeMap), "gsUrlEncodeMinMap");
86
+ }
87
+
88
+ static void hexdecodemap(void)
89
+ {
90
+ uint32_t i;
91
+ uint32_t map[256];
92
+ for (i = 0; i <= 255; ++i) {
93
+ map[i] = 256;
94
+ }
95
+
96
+ /* digits */
97
+ for (i = '0'; i <= '9'; ++i) {
98
+ map[i] = i - '0';
99
+ }
100
+
101
+ /* upper */
102
+ for (i = 'A'; i <= 'F'; ++i) {
103
+ map[i] = i - 'A' + 10;
104
+ }
105
+
106
+ /* lower */
107
+ for (i = 'a'; i <= 'f'; ++i) {
108
+ map[i] = i - 'a' + 10;
109
+ }
110
+
111
+ uint32_array_to_c(map, sizeof(map) / sizeof(uint32_t), "gsHexDecodeMap");
112
+ }
113
+
114
+ int main(void)
115
+ {
116
+ urlencodemap();
117
+ urlencodeminmap();
118
+ hexdecodemap();
119
+ hexencodemap();
120
+ return 0;
121
+ }
@@ -0,0 +1,128 @@
1
+ /*
2
+ * <pre>
3
+ * modp_html xml decoders
4
+ * https://github.com/client9/stringencoders
5
+ *
6
+ * Copyright &copy; 2013-2016 Nick Galbreath
7
+ * All rights reserved.
8
+ * Released under MIT license. See LICENSE for details.
9
+ * </PRE>
10
+ */
11
+ #include "modp_html.h"
12
+ #include "modp_html_named_entities.h"
13
+
14
+ static const int gsHexDecodeMap[256] = {
15
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
16
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
17
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
18
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
19
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 256, 256,
20
+ 256, 256, 256, 256, 256, 10, 11, 12, 13, 14, 15, 256,
21
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
22
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
23
+ 256, 10, 11, 12, 13, 14, 15, 256, 256, 256, 256, 256,
24
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
25
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
26
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
27
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
28
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
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, 256, 256, 256,
32
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
33
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
34
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
35
+ 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
36
+ 256, 256, 256, 256
37
+ };
38
+
39
+ int modp_html_decode_char_at(const char* src, size_t len, size_t* consumed)
40
+ {
41
+ if (len == 0 || src == NULL) {
42
+ *consumed = 0;
43
+ return -1;
44
+ }
45
+
46
+ *consumed = 1;
47
+ if (*src != '&' || len < 2) {
48
+ return (uint8_t)(*src);
49
+ }
50
+
51
+ int val = 0;
52
+ size_t i;
53
+ int ch;
54
+ if (*(src + 1) == '#') {
55
+ val = 0;
56
+ if (*(src + 2) == 'x' || *(src + 2) == 'X') {
57
+ i = 3;
58
+ ch = (uint8_t)(*(src + 3));
59
+ ch = gsHexDecodeMap[ch];
60
+ if (ch == 256) {
61
+ /* degenerate case '&#[?]' */
62
+ return '&';
63
+ }
64
+ val = ch;
65
+ i = 4;
66
+ while (i < len) {
67
+ ch = (uint8_t)src[i];
68
+ if (ch == ';') {
69
+ *consumed = i + 1;
70
+ return val;
71
+ }
72
+ ch = gsHexDecodeMap[ch];
73
+ if (ch == 256) {
74
+ *consumed = i;
75
+ return val;
76
+ }
77
+ val = (val * 16) + ch;
78
+ if (val > 0x1000FF) {
79
+ return '&';
80
+ }
81
+ ++i;
82
+ }
83
+ *consumed = i;
84
+ return val;
85
+ } else {
86
+ i = 2;
87
+ ch = (uint8_t)src[i];
88
+ if (ch < '0' || ch > '9') {
89
+ return '&';
90
+ }
91
+ val = ch - '0';
92
+ i += 1;
93
+ while (i < len) {
94
+ ch = (uint8_t)src[i];
95
+ if (ch == ';') {
96
+ *consumed = i + 1;
97
+ return val;
98
+ }
99
+ if (ch < '0' || ch > '9') {
100
+ *consumed = i;
101
+ return val;
102
+ }
103
+ val = (val * 10) + (ch - '0');
104
+ if (val > 0x1000FF) {
105
+ return '&';
106
+ }
107
+ ++i;
108
+ }
109
+ *consumed = i;
110
+ return val;
111
+ }
112
+ } else {
113
+ /* case &[^#] -- check for named entity */
114
+ /* named entities are surprisingly complicated
115
+ * * case sensitive
116
+ * * may or maybe end in ";"
117
+ * * longest match
118
+ */
119
+ int codepoint = html_named_entity_decode(src + 1, len - 1, consumed);
120
+ if (codepoint == 0) {
121
+ *consumed = 1;
122
+ return '&';
123
+ } else {
124
+ *consumed += 1;
125
+ return codepoint;
126
+ }
127
+ }
128
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * \file modp_html.h
3
+ * \brief Experimental HTML decoder
4
+ *
5
+ * This is mostly experimental.
6
+ */
7
+
8
+ /*
9
+ * <PRE>
10
+ * High Performance HTML Decoder (for now)
11
+ *
12
+ * Copyright &copy; 2013-2016 Nick Galbreath
13
+ * All rights reserved.
14
+ *
15
+ * https://github.com/client9/stringencoders
16
+ *
17
+ * Released under MIT license. See LICENSE for details.
18
+ * </PRE>
19
+ */
20
+
21
+ #ifndef COM_MODP_STRINGENCODERS_HTML
22
+ #define COM_MODP_STRINGENCODERS_HTML
23
+
24
+ #include "modp_stdint.h"
25
+
26
+ #ifdef __cplusplus
27
+ #define BEGIN_C extern "C" {
28
+ #define END_C }
29
+ #else
30
+ #define BEGIN_C
31
+ #define END_C
32
+ #endif
33
+
34
+ BEGIN_C
35
+
36
+ /**
37
+ * \brief HTML decode a single character
38
+ *
39
+ * \param[in] str The input string
40
+ * \param[in] len The length of the input string, excluding any
41
+ * final null byte.
42
+ * \param[out] Number of characters consumed
43
+ * \return unicode character value or -1 if error
44
+ *
45
+ * Decode numerical entities (decimal or hexadecimal),
46
+ * and all named characters
47
+ *
48
+ */
49
+ int modp_html_decode_char_at(const char* str, size_t len, size_t* consumed);
50
+
51
+ END_C
52
+
53
+ #endif