cppjieba_rb 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +3 -0
  3. data/README.md +1 -1
  4. data/Rakefile +2 -2
  5. data/cppjieba_rb.gemspec +4 -4
  6. data/lib/cppjieba_rb/version.rb +1 -1
  7. metadata +17 -135
  8. data/ext/cppjieba/.gitignore +0 -17
  9. data/ext/cppjieba/.travis.yml +0 -21
  10. data/ext/cppjieba/CMakeLists.txt +0 -28
  11. data/ext/cppjieba/ChangeLog.md +0 -236
  12. data/ext/cppjieba/README.md +0 -292
  13. data/ext/cppjieba/README_EN.md +0 -113
  14. data/ext/cppjieba/appveyor.yml +0 -32
  15. data/ext/cppjieba/deps/CMakeLists.txt +0 -1
  16. data/ext/cppjieba/deps/gtest/CMakeLists.txt +0 -5
  17. data/ext/cppjieba/deps/gtest/include/gtest/gtest-death-test.h +0 -283
  18. data/ext/cppjieba/deps/gtest/include/gtest/gtest-message.h +0 -230
  19. data/ext/cppjieba/deps/gtest/include/gtest/gtest-param-test.h +0 -1421
  20. data/ext/cppjieba/deps/gtest/include/gtest/gtest-param-test.h.pump +0 -487
  21. data/ext/cppjieba/deps/gtest/include/gtest/gtest-printers.h +0 -796
  22. data/ext/cppjieba/deps/gtest/include/gtest/gtest-spi.h +0 -232
  23. data/ext/cppjieba/deps/gtest/include/gtest/gtest-test-part.h +0 -176
  24. data/ext/cppjieba/deps/gtest/include/gtest/gtest-typed-test.h +0 -259
  25. data/ext/cppjieba/deps/gtest/include/gtest/gtest.h +0 -2155
  26. data/ext/cppjieba/deps/gtest/include/gtest/gtest_pred_impl.h +0 -358
  27. data/ext/cppjieba/deps/gtest/include/gtest/gtest_prod.h +0 -58
  28. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-death-test-internal.h +0 -308
  29. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-filepath.h +0 -210
  30. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-internal.h +0 -1226
  31. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-linked_ptr.h +0 -233
  32. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util-generated.h +0 -4822
  33. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util-generated.h.pump +0 -301
  34. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util.h +0 -619
  35. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-port.h +0 -1788
  36. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-string.h +0 -350
  37. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-tuple.h +0 -968
  38. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-tuple.h.pump +0 -336
  39. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-type-util.h +0 -3330
  40. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-type-util.h.pump +0 -296
  41. data/ext/cppjieba/deps/gtest/src/.deps/.dirstamp +0 -0
  42. data/ext/cppjieba/deps/gtest/src/.deps/gtest-all.Plo +0 -681
  43. data/ext/cppjieba/deps/gtest/src/.deps/gtest_main.Plo +0 -509
  44. data/ext/cppjieba/deps/gtest/src/.dirstamp +0 -0
  45. data/ext/cppjieba/deps/gtest/src/gtest-all.cc +0 -48
  46. data/ext/cppjieba/deps/gtest/src/gtest-death-test.cc +0 -1234
  47. data/ext/cppjieba/deps/gtest/src/gtest-filepath.cc +0 -380
  48. data/ext/cppjieba/deps/gtest/src/gtest-internal-inl.h +0 -1038
  49. data/ext/cppjieba/deps/gtest/src/gtest-port.cc +0 -746
  50. data/ext/cppjieba/deps/gtest/src/gtest-printers.cc +0 -356
  51. data/ext/cppjieba/deps/gtest/src/gtest-test-part.cc +0 -110
  52. data/ext/cppjieba/deps/gtest/src/gtest-typed-test.cc +0 -110
  53. data/ext/cppjieba/deps/gtest/src/gtest.cc +0 -4898
  54. data/ext/cppjieba/deps/gtest/src/gtest_main.cc +0 -39
  55. data/ext/cppjieba/deps/limonp/ArgvContext.hpp +0 -70
  56. data/ext/cppjieba/deps/limonp/BlockingQueue.hpp +0 -49
  57. data/ext/cppjieba/deps/limonp/BoundedBlockingQueue.hpp +0 -67
  58. data/ext/cppjieba/deps/limonp/BoundedQueue.hpp +0 -65
  59. data/ext/cppjieba/deps/limonp/Closure.hpp +0 -206
  60. data/ext/cppjieba/deps/limonp/Colors.hpp +0 -31
  61. data/ext/cppjieba/deps/limonp/Condition.hpp +0 -38
  62. data/ext/cppjieba/deps/limonp/Config.hpp +0 -103
  63. data/ext/cppjieba/deps/limonp/FileLock.hpp +0 -74
  64. data/ext/cppjieba/deps/limonp/ForcePublic.hpp +0 -7
  65. data/ext/cppjieba/deps/limonp/LocalVector.hpp +0 -139
  66. data/ext/cppjieba/deps/limonp/Logging.hpp +0 -76
  67. data/ext/cppjieba/deps/limonp/Md5.hpp +0 -411
  68. data/ext/cppjieba/deps/limonp/MutexLock.hpp +0 -51
  69. data/ext/cppjieba/deps/limonp/NonCopyable.hpp +0 -21
  70. data/ext/cppjieba/deps/limonp/StdExtension.hpp +0 -159
  71. data/ext/cppjieba/deps/limonp/StringUtil.hpp +0 -365
  72. data/ext/cppjieba/deps/limonp/Thread.hpp +0 -44
  73. data/ext/cppjieba/deps/limonp/ThreadPool.hpp +0 -86
  74. data/ext/cppjieba/dict/README.md +0 -31
  75. data/ext/cppjieba/dict/hmm_model.utf8 +0 -34
  76. data/ext/cppjieba/dict/idf.utf8 +0 -258826
  77. data/ext/cppjieba/dict/jieba.dict.utf8 +0 -348982
  78. data/ext/cppjieba/dict/pos_dict/char_state_tab.utf8 +0 -6653
  79. data/ext/cppjieba/dict/pos_dict/prob_emit.utf8 +0 -166
  80. data/ext/cppjieba/dict/pos_dict/prob_start.utf8 +0 -259
  81. data/ext/cppjieba/dict/pos_dict/prob_trans.utf8 +0 -5222
  82. data/ext/cppjieba/dict/stop_words.utf8 +0 -1534
  83. data/ext/cppjieba/dict/user.dict.utf8 +0 -4
  84. data/ext/cppjieba/include/cppjieba/DictTrie.hpp +0 -277
  85. data/ext/cppjieba/include/cppjieba/FullSegment.hpp +0 -93
  86. data/ext/cppjieba/include/cppjieba/HMMModel.hpp +0 -129
  87. data/ext/cppjieba/include/cppjieba/HMMSegment.hpp +0 -190
  88. data/ext/cppjieba/include/cppjieba/Jieba.hpp +0 -130
  89. data/ext/cppjieba/include/cppjieba/KeywordExtractor.hpp +0 -153
  90. data/ext/cppjieba/include/cppjieba/MPSegment.hpp +0 -137
  91. data/ext/cppjieba/include/cppjieba/MixSegment.hpp +0 -109
  92. data/ext/cppjieba/include/cppjieba/PosTagger.hpp +0 -77
  93. data/ext/cppjieba/include/cppjieba/PreFilter.hpp +0 -54
  94. data/ext/cppjieba/include/cppjieba/QuerySegment.hpp +0 -90
  95. data/ext/cppjieba/include/cppjieba/SegmentBase.hpp +0 -46
  96. data/ext/cppjieba/include/cppjieba/SegmentTagged.hpp +0 -23
  97. data/ext/cppjieba/include/cppjieba/TextRankExtractor.hpp +0 -190
  98. data/ext/cppjieba/include/cppjieba/Trie.hpp +0 -174
  99. data/ext/cppjieba/include/cppjieba/Unicode.hpp +0 -227
  100. data/ext/cppjieba/test/CMakeLists.txt +0 -5
  101. data/ext/cppjieba/test/demo.cpp +0 -80
  102. data/ext/cppjieba/test/load_test.cpp +0 -54
  103. data/ext/cppjieba/test/testdata/curl.res +0 -1
  104. data/ext/cppjieba/test/testdata/extra_dict/jieba.dict.small.utf8 +0 -109750
  105. data/ext/cppjieba/test/testdata/gbk_dict/hmm_model.gbk +0 -34
  106. data/ext/cppjieba/test/testdata/gbk_dict/jieba.dict.gbk +0 -348982
  107. data/ext/cppjieba/test/testdata/jieba.dict.0.1.utf8 +0 -93
  108. data/ext/cppjieba/test/testdata/jieba.dict.0.utf8 +0 -93
  109. data/ext/cppjieba/test/testdata/jieba.dict.1.utf8 +0 -67
  110. data/ext/cppjieba/test/testdata/jieba.dict.2.utf8 +0 -64
  111. data/ext/cppjieba/test/testdata/load_test.urls +0 -2
  112. data/ext/cppjieba/test/testdata/review.100 +0 -100
  113. data/ext/cppjieba/test/testdata/review.100.res +0 -200
  114. data/ext/cppjieba/test/testdata/server.conf +0 -19
  115. data/ext/cppjieba/test/testdata/testlines.gbk +0 -9
  116. data/ext/cppjieba/test/testdata/testlines.utf8 +0 -8
  117. data/ext/cppjieba/test/testdata/userdict.2.utf8 +0 -1
  118. data/ext/cppjieba/test/testdata/userdict.english +0 -2
  119. data/ext/cppjieba/test/testdata/userdict.utf8 +0 -8
  120. data/ext/cppjieba/test/testdata/weicheng.utf8 +0 -247
  121. data/ext/cppjieba/test/unittest/CMakeLists.txt +0 -24
  122. data/ext/cppjieba/test/unittest/gtest_main.cpp +0 -39
  123. data/ext/cppjieba/test/unittest/jieba_test.cpp +0 -133
  124. data/ext/cppjieba/test/unittest/keyword_extractor_test.cpp +0 -79
  125. data/ext/cppjieba/test/unittest/pos_tagger_test.cpp +0 -41
  126. data/ext/cppjieba/test/unittest/pre_filter_test.cpp +0 -43
  127. data/ext/cppjieba/test/unittest/segments_test.cpp +0 -256
  128. data/ext/cppjieba/test/unittest/textrank_test.cpp +0 -86
  129. data/ext/cppjieba/test/unittest/trie_test.cpp +0 -177
  130. data/ext/cppjieba/test/unittest/unicode_test.cpp +0 -43
@@ -1,411 +0,0 @@
1
- #ifndef __MD5_H__
2
- #define __MD5_H__
3
-
4
- // Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
5
- // rights reserved.
6
-
7
- // License to copy and use this software is granted provided that it
8
- // is identified as the "RSA Data Security, Inc. MD5 Message-Digest
9
- // Algorithm" in all material mentioning or referencing this software
10
- // or this function.
11
- //
12
- // License is also granted to make and use derivative works provided
13
- // that such works are identified as "derived from the RSA Data
14
- // Security, Inc. MD5 Message-Digest Algorithm" in all material
15
- // mentioning or referencing the derived work.
16
- //
17
- // RSA Data Security, Inc. makes no representations concerning either
18
- // the merchantability of this software or the suitability of this
19
- // software for any particular purpose. It is provided "as is"
20
- // without express or implied warranty of any kind.
21
- //
22
- // These notices must be retained in any copies of any part of this
23
- // documentation and/or software.
24
-
25
-
26
-
27
- // The original md5 implementation avoids external libraries.
28
- // This version has dependency on stdio.h for file input and
29
- // string.h for memcpy.
30
- #include <cstdio>
31
- #include <cstring>
32
- #include <iostream>
33
-
34
- namespace limonp {
35
-
36
- //#pragma region MD5 defines
37
- // Constants for MD5Transform routine.
38
- #define S11 7
39
- #define S12 12
40
- #define S13 17
41
- #define S14 22
42
- #define S21 5
43
- #define S22 9
44
- #define S23 14
45
- #define S24 20
46
- #define S31 4
47
- #define S32 11
48
- #define S33 16
49
- #define S34 23
50
- #define S41 6
51
- #define S42 10
52
- #define S43 15
53
- #define S44 21
54
-
55
-
56
- // F, G, H and I are basic MD5 functions.
57
- #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
58
- #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
59
- #define H(x, y, z) ((x) ^ (y) ^ (z))
60
- #define I(x, y, z) ((y) ^ ((x) | (~z)))
61
-
62
- // ROTATE_LEFT rotates x left n bits.
63
- #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
64
-
65
- // FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
66
- // Rotation is separate from addition to prevent recomputation.
67
- #define FF(a, b, c, d, x, s, ac) { \
68
- (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
69
- (a) = ROTATE_LEFT ((a), (s)); \
70
- (a) += (b); \
71
- }
72
- #define GG(a, b, c, d, x, s, ac) { \
73
- (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
74
- (a) = ROTATE_LEFT ((a), (s)); \
75
- (a) += (b); \
76
- }
77
- #define HH(a, b, c, d, x, s, ac) { \
78
- (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
79
- (a) = ROTATE_LEFT ((a), (s)); \
80
- (a) += (b); \
81
- }
82
- #define II(a, b, c, d, x, s, ac) { \
83
- (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
84
- (a) = ROTATE_LEFT ((a), (s)); \
85
- (a) += (b); \
86
- }
87
- //#pragma endregion
88
-
89
-
90
- typedef unsigned char BYTE ;
91
-
92
- // POINTER defines a generic pointer type
93
- typedef unsigned char *POINTER;
94
-
95
- // UINT2 defines a two byte word
96
- typedef unsigned short int UINT2;
97
-
98
- // UINT4 defines a four byte word
99
- typedef unsigned int UINT4;
100
-
101
- static unsigned char PADDING[64] = {
102
- 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
104
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
105
- };
106
- // convenient object that wraps
107
- // the C-functions for use in C++ only
108
- class MD5 {
109
- private:
110
- struct __context_t {
111
- UINT4 state[4]; /* state (ABCD) */
112
- UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
113
- unsigned char buffer[64]; /* input buffer */
114
- } context ;
115
-
116
- //#pragma region static helper functions
117
- // The core of the MD5 algorithm is here.
118
- // MD5 basic transformation. Transforms state based on block.
119
- static void MD5Transform( UINT4 state[4], unsigned char block[64] ) {
120
- UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
121
-
122
- Decode (x, block, 64);
123
-
124
- /* Round 1 */
125
- FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
126
- FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
127
- FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
128
- FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
129
- FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
130
- FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
131
- FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
132
- FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
133
- FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
134
- FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
135
- FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
136
- FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
137
- FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
138
- FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
139
- FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
140
- FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
141
-
142
- /* Round 2 */
143
- GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
144
- GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
145
- GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
146
- GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
147
- GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
148
- GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
149
- GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
150
- GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
151
- GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
152
- GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
153
- GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
154
- GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
155
- GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
156
- GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
157
- GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
158
- GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
159
-
160
- /* Round 3 */
161
- HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
162
- HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
163
- HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
164
- HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
165
- HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
166
- HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
167
- HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
168
- HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
169
- HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
170
- HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
171
- HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
172
- HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
173
- HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
174
- HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
175
- HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
176
- HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
177
-
178
- /* Round 4 */
179
- II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
180
- II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
181
- II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
182
- II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
183
- II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
184
- II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
185
- II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
186
- II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
187
- II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
188
- II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
189
- II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
190
- II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
191
- II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
192
- II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
193
- II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
194
- II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
195
-
196
- state[0] += a;
197
- state[1] += b;
198
- state[2] += c;
199
- state[3] += d;
200
-
201
- // Zeroize sensitive information.
202
- memset((POINTER)x, 0, sizeof (x));
203
- }
204
-
205
- // Encodes input (UINT4) into output (unsigned char). Assumes len is
206
- // a multiple of 4.
207
- static void Encode( unsigned char *output, UINT4 *input, unsigned int len ) {
208
- unsigned int i, j;
209
-
210
- for (i = 0, j = 0; j < len; i++, j += 4) {
211
- output[j] = (unsigned char)(input[i] & 0xff);
212
- output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
213
- output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
214
- output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
215
- }
216
- }
217
-
218
- // Decodes input (unsigned char) into output (UINT4). Assumes len is
219
- // a multiple of 4.
220
- static void Decode( UINT4 *output, unsigned char *input, unsigned int len ) {
221
- unsigned int i, j;
222
-
223
- for (i = 0, j = 0; j < len; i++, j += 4)
224
- output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
225
- (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
226
- }
227
- //#pragma endregion
228
-
229
-
230
- public:
231
- // MAIN FUNCTIONS
232
- MD5() {
233
- Init() ;
234
- }
235
-
236
- // MD5 initialization. Begins an MD5 operation, writing a new context.
237
- void Init() {
238
- context.count[0] = context.count[1] = 0;
239
-
240
- // Load magic initialization constants.
241
- context.state[0] = 0x67452301;
242
- context.state[1] = 0xefcdab89;
243
- context.state[2] = 0x98badcfe;
244
- context.state[3] = 0x10325476;
245
- }
246
-
247
- // MD5 block update operation. Continues an MD5 message-digest
248
- // operation, processing another message block, and updating the
249
- // context.
250
- void Update(
251
- unsigned char *input, // input block
252
- unsigned int inputLen ) { // length of input block
253
- unsigned int i, index, partLen;
254
-
255
- // Compute number of bytes mod 64
256
- index = (unsigned int)((context.count[0] >> 3) & 0x3F);
257
-
258
- // Update number of bits
259
- if ((context.count[0] += ((UINT4)inputLen << 3))
260
- < ((UINT4)inputLen << 3))
261
- context.count[1]++;
262
- context.count[1] += ((UINT4)inputLen >> 29);
263
-
264
- partLen = 64 - index;
265
-
266
- // Transform as many times as possible.
267
- if (inputLen >= partLen) {
268
- memcpy((POINTER)&context.buffer[index], (POINTER)input, partLen);
269
- MD5Transform (context.state, context.buffer);
270
-
271
- for (i = partLen; i + 63 < inputLen; i += 64)
272
- MD5Transform (context.state, &input[i]);
273
-
274
- index = 0;
275
- } else
276
- i = 0;
277
-
278
- /* Buffer remaining input */
279
- memcpy((POINTER)&context.buffer[index], (POINTER)&input[i], inputLen-i);
280
- }
281
-
282
- // MD5 finalization. Ends an MD5 message-digest operation, writing the
283
- // the message digest and zeroizing the context.
284
- // Writes to digestRaw
285
- void Final() {
286
- unsigned char bits[8];
287
- unsigned int index, padLen;
288
-
289
- // Save number of bits
290
- Encode( bits, context.count, 8 );
291
-
292
- // Pad out to 56 mod 64.
293
- index = (unsigned int)((context.count[0] >> 3) & 0x3f);
294
- padLen = (index < 56) ? (56 - index) : (120 - index);
295
- Update( PADDING, padLen );
296
-
297
- // Append length (before padding)
298
- Update( bits, 8 );
299
-
300
- // Store state in digest
301
- Encode( digestRaw, context.state, 16);
302
-
303
- // Zeroize sensitive information.
304
- memset((POINTER)&context, 0, sizeof (context));
305
-
306
- writeToString() ;
307
- }
308
-
309
- /// Buffer must be 32+1 (nul) = 33 chars long at least
310
- void writeToString() {
311
- int pos ;
312
-
313
- for( pos = 0 ; pos < 16 ; pos++ )
314
- sprintf( digestChars+(pos*2), "%02x", digestRaw[pos] ) ;
315
- }
316
-
317
-
318
- public:
319
- // an MD5 digest is a 16-byte number (32 hex digits)
320
- BYTE digestRaw[ 16 ] ;
321
-
322
- // This version of the digest is actually
323
- // a "printf'd" version of the digest.
324
- char digestChars[ 33 ] ;
325
-
326
- /// Load a file from disk and digest it
327
- // Digests a file and returns the result.
328
- const char* digestFile( const char *filename ) {
329
- if (NULL == filename || strcmp(filename, "") == 0)
330
- return NULL;
331
-
332
- Init() ;
333
-
334
- FILE *file;
335
-
336
- unsigned char buffer[1024] ;
337
-
338
- if((file = fopen (filename, "rb")) == NULL) {
339
- return NULL;
340
- }
341
- int len;
342
- while( (len = fread( buffer, 1, 1024, file )) )
343
- Update( buffer, len ) ;
344
- Final();
345
-
346
- fclose( file );
347
-
348
- return digestChars ;
349
- }
350
-
351
- /// Digests a byte-array already in memory
352
- const char* digestMemory( BYTE *memchunk, int len ) {
353
- if (NULL == memchunk)
354
- return NULL;
355
-
356
- Init() ;
357
- Update( memchunk, len ) ;
358
- Final() ;
359
-
360
- return digestChars ;
361
- }
362
-
363
- // Digests a string and prints the result.
364
- const char* digestString(const char *string ) {
365
- if (string == NULL)
366
- return NULL;
367
-
368
- Init() ;
369
- Update( (unsigned char*)string, strlen(string) ) ;
370
- Final() ;
371
-
372
- return digestChars ;
373
- }
374
- };
375
-
376
- inline bool md5String(const char* str, std::string& res) {
377
- if (NULL == str) {
378
- res = "";
379
- return false;
380
- }
381
-
382
- MD5 md5;
383
- const char *pRes = md5.digestString(str);
384
- if (NULL == pRes) {
385
- res = "";
386
- return false;
387
- }
388
-
389
- res = pRes;
390
- return true;
391
- }
392
-
393
- inline bool md5File(const char* filepath, std::string& res) {
394
- if (NULL == filepath || strcmp(filepath, "") == 0) {
395
- res = "";
396
- return false;
397
- }
398
-
399
- MD5 md5;
400
- const char *pRes = md5.digestFile(filepath);
401
-
402
- if (NULL == pRes) {
403
- res = "";
404
- return false;
405
- }
406
-
407
- res = pRes;
408
- return true;
409
- }
410
- }
411
- #endif
@@ -1,51 +0,0 @@
1
- #ifndef LIMONP_MUTEX_LOCK_HPP
2
- #define LIMONP_MUTEX_LOCK_HPP
3
-
4
- #include <pthread.h>
5
- #include "NonCopyable.hpp"
6
- #include "Logging.hpp"
7
-
8
- namespace limonp {
9
-
10
- class MutexLock: NonCopyable {
11
- public:
12
- MutexLock() {
13
- XCHECK(!pthread_mutex_init(&mutex_, NULL));
14
- }
15
- ~MutexLock() {
16
- XCHECK(!pthread_mutex_destroy(&mutex_));
17
- }
18
- pthread_mutex_t* GetPthreadMutex() {
19
- return &mutex_;
20
- }
21
-
22
- private:
23
- void Lock() {
24
- XCHECK(!pthread_mutex_lock(&mutex_));
25
- }
26
- void Unlock() {
27
- XCHECK(!pthread_mutex_unlock(&mutex_));
28
- }
29
- friend class MutexLockGuard;
30
-
31
- pthread_mutex_t mutex_;
32
- }; // class MutexLock
33
-
34
- class MutexLockGuard: NonCopyable {
35
- public:
36
- explicit MutexLockGuard(MutexLock & mutex)
37
- : mutex_(mutex) {
38
- mutex_.Lock();
39
- }
40
- ~MutexLockGuard() {
41
- mutex_.Unlock();
42
- }
43
- private:
44
- MutexLock & mutex_;
45
- }; // class MutexLockGuard
46
-
47
- #define MutexLockGuard(x) XCHECK(false);
48
-
49
- } // namespace limonp
50
-
51
- #endif // LIMONP_MUTEX_LOCK_HPP