digest-stringbuffer 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab35194aaa43618125eb3e59a4e34740704eae68
4
- data.tar.gz: 125bdf9abbb3dfb7c8db23b5acc89ab10c79c8d9
3
+ metadata.gz: 0acbdc54aa9644dc781f96c44f0b1e45c6e6352e
4
+ data.tar.gz: c98fec7c8c084241aa8e59653d98c87d7867917d
5
5
  SHA512:
6
- metadata.gz: 0b20252eb078422ea4914b561590ce99713588817657805c402cd3259e452e360939ce9a1db0194f6a3923ffb0528c86317280ecfec22aa18aaedea9815eaf62
7
- data.tar.gz: d0fe99b0f5f23ccc6f07d9e37046133c3e17cf1f6eb3cf6a421910a0b5b8dc6738823035eb5c9b05d9041b35a9a1b4da912c54d0abd650d34abd9326b5e39692
6
+ metadata.gz: 33ea30e0704ce04b0b51fcc8688abf236d44c3995b5443b53e1c14186c97b8e2977e81433c673780f1d8aa8cfb18190eb86d545a2e38865c04534d5319ca940f
7
+ data.tar.gz: 1dc624b77a02c58006837507fcaee634e911477f96a079303bba6bc522183b62fa6826212ea8e8594d3e8f7ef92c4db7757580a57307a76e6cc9ea7435a951af
data/README.md CHANGED
@@ -14,7 +14,7 @@ Digest::StringBuffer depends only one method `finish`.
14
14
 
15
15
  ```ruby
16
16
  module Digest
17
- class Prime31
17
+ class Prime31 < StringBuffer
18
18
  def initialize
19
19
  @prime = 31
20
20
  end
@@ -29,7 +29,7 @@ module Digest
29
29
  end
30
30
  end
31
31
 
32
- p Digest::Prime.hexdigest("abc" * 1000) #=> "008b1190"
32
+ p Digest::Prime31.hexdigest("abc" * 1000) #=> "008b1190"
33
33
  ```
34
34
 
35
35
  ## APIs
@@ -9,328 +9,331 @@
9
9
  #define BUFFER_INIT 64
10
10
 
11
11
  typedef struct {
12
- char* buffer;
13
- char* p;
14
- size_t memsize;
12
+ char* buffer;
13
+ char* p;
14
+ size_t memsize;
15
15
  } buffer_t;
16
16
 
17
17
  static void
18
18
  buffer_init(buffer_t* ptr)
19
19
  {
20
- ptr->buffer = (char*) xmalloc(sizeof(char) * BUFFER_INIT);
21
- ptr->p = ptr->buffer;
22
- ptr->memsize = BUFFER_INIT;
20
+ ptr->buffer = (char*) xmalloc(sizeof(char) * BUFFER_INIT);
21
+ ptr->p = ptr->buffer;
22
+ ptr->memsize = BUFFER_INIT;
23
23
  }
24
24
 
25
25
  static void
26
26
  buffer_realloc(buffer_t* ptr, size_t size)
27
27
  {
28
- char* buffer;
28
+ char* buffer;
29
29
 
30
- buffer = (char*) xrealloc(ptr->buffer, size);
31
- if (buffer == NULL)
32
- rb_raise(rb_eNoMemError, "failed to realloc");
30
+ buffer = (char*) xrealloc(ptr->buffer, size);
31
+ if (buffer == NULL)
32
+ rb_raise(rb_eNoMemError, "failed to realloc");
33
33
 
34
- ptr->buffer = buffer;
34
+ ptr->buffer = buffer;
35
35
  }
36
36
 
37
37
  static void
38
38
  buffer_free(buffer_t* ptr)
39
39
  {
40
- xfree(ptr->buffer);
40
+ if (ptr->buffer != NULL)
41
+ xfree(ptr->buffer);
42
+ if (ptr != NULL)
43
+ xfree(ptr);
41
44
  }
42
45
 
43
46
  static size_t
44
47
  buffer_buffer_length(buffer_t* ptr)
45
48
  {
46
- return ptr->p - ptr->buffer;
49
+ return ptr->p - ptr->buffer;
47
50
  }
48
51
 
49
52
  static VALUE
50
53
  buffer_alloc(VALUE self)
51
54
  {
52
- buffer_t* ptr = ALLOC(buffer_t);
53
- buffer_init(ptr);
54
- return Data_Wrap_Struct(self, 0, buffer_free, ptr);
55
+ buffer_t* ptr = ALLOC(buffer_t);
56
+ buffer_init(ptr);
57
+ return Data_Wrap_Struct(self, 0, buffer_free, ptr);
55
58
  }
56
59
 
57
60
  static VALUE
58
61
  hexencode_str_new(VALUE str_digest)
59
62
  {
60
- char *digest;
61
- size_t digest_len;
62
- size_t i;
63
- VALUE str;
64
- char *p;
65
- static const char hex[] = {
66
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
67
- 'a', 'b', 'c', 'd', 'e', 'f'
68
- };
69
-
70
- StringValue(str_digest);
71
- digest = RSTRING_PTR(str_digest);
72
- digest_len = RSTRING_LEN(str_digest);
73
-
74
- if (LONG_MAX / 2 < digest_len) {
75
- rb_raise(rb_eRuntimeError, "digest string too long");
76
- }
77
-
78
- str = rb_usascii_str_new(0, digest_len * 2);
79
-
80
- for (i = 0, p = RSTRING_PTR(str); i < digest_len; i++) {
81
- unsigned char byte = digest[i];
82
-
83
- p[i + i] = hex[byte >> 4];
84
- p[i + i + 1] = hex[byte & 0x0f];
85
- }
86
-
87
- return str;
63
+ char *digest;
64
+ size_t digest_len;
65
+ size_t i;
66
+ VALUE str;
67
+ char *p;
68
+ static const char hex[] = {
69
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
70
+ 'a', 'b', 'c', 'd', 'e', 'f'
71
+ };
72
+
73
+ StringValue(str_digest);
74
+ digest = RSTRING_PTR(str_digest);
75
+ digest_len = RSTRING_LEN(str_digest);
76
+
77
+ if (LONG_MAX / 2 < digest_len) {
78
+ rb_raise(rb_eRuntimeError, "digest string too long");
79
+ }
80
+
81
+ str = rb_usascii_str_new(0, digest_len * 2);
82
+
83
+ for (i = 0, p = RSTRING_PTR(str); i < digest_len; i++) {
84
+ unsigned char byte = digest[i];
85
+
86
+ p[i + i] = hex[byte >> 4];
87
+ p[i + i + 1] = hex[byte & 0x0f];
88
+ }
89
+
90
+ return str;
88
91
  }
89
92
 
90
93
  static VALUE
91
94
  buffer_initialize_copy(VALUE copy, VALUE origin)
92
95
  {
93
- buffer_t *ptr_copy, *ptr_origin;
94
- size_t buffer_len;
96
+ buffer_t *ptr_copy, *ptr_origin;
97
+ size_t buffer_len;
95
98
 
96
- if (copy == origin) return copy;
99
+ if (copy == origin) return copy;
97
100
 
98
- rb_check_frozen(copy);
101
+ rb_check_frozen(copy);
99
102
 
100
- Data_Get_Struct(copy, buffer_t, ptr_copy);
101
- Data_Get_Struct(origin, buffer_t, ptr_origin);
103
+ Data_Get_Struct(copy, buffer_t, ptr_copy);
104
+ Data_Get_Struct(origin, buffer_t, ptr_origin);
102
105
 
103
- buffer_len = buffer_buffer_length(ptr_origin);
106
+ buffer_len = buffer_buffer_length(ptr_origin);
104
107
 
105
- if (ptr_copy->memsize < ptr_origin->memsize) {
106
- buffer_realloc(ptr_copy, sizeof(char) * ptr_origin->memsize);
107
- ptr_copy->memsize = ptr_origin->memsize;
108
- }
108
+ if (ptr_copy->memsize < ptr_origin->memsize) {
109
+ buffer_realloc(ptr_copy, sizeof(char) * ptr_origin->memsize);
110
+ }
109
111
 
110
- memcpy(ptr_copy->buffer, ptr_origin->buffer, buffer_len);
111
- ptr_copy->p = ptr_copy->buffer + buffer_len;
112
+ memcpy(ptr_copy->buffer, ptr_origin->buffer, buffer_len);
113
+ ptr_copy->p = ptr_copy->buffer + buffer_len;
114
+ ptr_copy->memsize = ptr_origin->memsize;
112
115
 
113
- return copy;
116
+ return copy;
114
117
  }
115
118
 
116
119
  static VALUE
117
120
  buffer_reset(VALUE self)
118
121
  {
119
- buffer_t *ptr;
120
- Data_Get_Struct(self, buffer_t, ptr);
121
- ptr->p = ptr->buffer;
122
- return self;
122
+ buffer_t *ptr;
123
+ Data_Get_Struct(self, buffer_t, ptr);
124
+ ptr->p = ptr->buffer;
125
+ return self;
123
126
  }
124
127
 
125
128
  static VALUE
126
129
  buffer_update(VALUE self, VALUE str)
127
130
  {
128
- size_t buffer_len, str_len, require, newsize;
129
- const char* str_p;
130
- buffer_t *ptr;
131
- Data_Get_Struct(self, buffer_t, ptr);
132
-
133
- StringValue(str);
134
- str_p = RSTRING_PTR(str);
135
- str_len = RSTRING_LEN(str);
136
- buffer_len = buffer_buffer_length(ptr);
137
- require = buffer_len + str_len;
138
- if (ptr->memsize < require) {
139
- newsize = ptr->memsize;
140
- while (newsize < require) {
141
- newsize *= 2;
142
- }
143
- buffer_realloc(ptr, sizeof(char) * newsize);
144
- ptr->p = ptr->buffer + buffer_len;
145
- ptr->memsize = newsize;
146
- }
147
- memcpy(ptr->p, str_p, str_len);
148
- ptr->p += str_len;
149
-
150
- return self;
131
+ size_t buffer_len, str_len, require, newsize;
132
+ const char* str_p;
133
+ buffer_t *ptr;
134
+ Data_Get_Struct(self, buffer_t, ptr);
135
+
136
+ StringValue(str);
137
+ str_p = RSTRING_PTR(str);
138
+ str_len = RSTRING_LEN(str);
139
+ buffer_len = buffer_buffer_length(ptr);
140
+ require = buffer_len + str_len;
141
+ if (ptr->memsize < require) {
142
+ newsize = ptr->memsize;
143
+ while (newsize < require) {
144
+ newsize *= 2;
145
+ }
146
+ buffer_realloc(ptr, sizeof(char) * newsize);
147
+ ptr->p = ptr->buffer + buffer_len;
148
+ ptr->memsize = newsize;
149
+ }
150
+ memcpy(ptr->p, str_p, str_len);
151
+ ptr->p += str_len;
152
+
153
+ return self;
151
154
  }
152
155
 
153
156
  static VALUE
154
157
  buffer_finish(VALUE self)
155
158
  {
156
- rb_raise(rb_eRuntimeError, "%s does not implement finish()",
157
- rb_obj_classname(self));
159
+ rb_raise(rb_eRuntimeError, "%s does not implement finish()",
160
+ rb_obj_classname(self));
158
161
  }
159
162
 
160
163
  static VALUE
161
164
  buffer_digest(int argc, VALUE *argv, VALUE self)
162
165
  {
163
- VALUE str, value;
164
-
165
- if (0 < rb_scan_args(argc, argv, "01", &str)) {
166
- buffer_reset(self);
167
- buffer_update(self, str);
168
- value = rb_funcall(self, rb_intern("finish"), 0);
169
- buffer_reset(self);
170
- } else {
171
- value = rb_funcall(self, rb_intern("finish"), 0);
172
- }
173
-
174
- return value;
166
+ VALUE str, value;
167
+
168
+ if (0 < rb_scan_args(argc, argv, "01", &str)) {
169
+ buffer_reset(self);
170
+ buffer_update(self, str);
171
+ value = rb_funcall(self, rb_intern("finish"), 0);
172
+ buffer_reset(self);
173
+ } else {
174
+ value = rb_funcall(self, rb_intern("finish"), 0);
175
+ }
176
+
177
+ return value;
175
178
  }
176
179
 
177
180
  static VALUE
178
181
  buffer_digest_bang(VALUE self)
179
182
  {
180
- VALUE value = rb_funcall(self, rb_intern("finish"), 0);
181
- buffer_reset(self);
183
+ VALUE value = rb_funcall(self, rb_intern("finish"), 0);
184
+ buffer_reset(self);
182
185
 
183
- return value;
186
+ return value;
184
187
  }
185
188
 
186
189
  static VALUE
187
190
  buffer_hexdigest(int argc, VALUE *argv, VALUE self)
188
191
  {
189
- return hexencode_str_new(buffer_digest(argc, argv, self));
192
+ return hexencode_str_new(buffer_digest(argc, argv, self));
190
193
  }
191
194
 
192
195
  static VALUE
193
196
  buffer_hexdigest_bang(VALUE self)
194
197
  {
195
- return hexencode_str_new(buffer_digest_bang(self));
198
+ return hexencode_str_new(buffer_digest_bang(self));
196
199
  }
197
200
 
198
201
  static VALUE
199
202
  buffer_to_s(VALUE self)
200
203
  {
201
- return hexencode_str_new(buffer_digest(0, 0, self));
204
+ return hexencode_str_new(buffer_digest(0, 0, self));
202
205
  }
203
206
 
204
207
  static VALUE
205
208
  buffer_digest_length(VALUE self)
206
209
  {
207
- /* subclasses really should redefine this method */
208
- VALUE digest = buffer_digest(0, 0, self);
210
+ /* subclasses really should redefine this method */
211
+ VALUE digest = buffer_digest(0, 0, self);
209
212
 
210
- /* never blindly assume that #digest() returns a string */
211
- StringValue(digest);
212
- return UINT2NUM(RSTRING_LEN(digest));
213
+ /* never blindly assume that #digest() returns a string */
214
+ StringValue(digest);
215
+ return UINT2NUM(RSTRING_LEN(digest));
213
216
  }
214
217
 
215
218
  static VALUE
216
219
  buffer_equal(VALUE self, VALUE other)
217
220
  {
218
- VALUE str1, str2;
219
- str1 = buffer_digest(0, 0, self);
220
- str2 = buffer_digest(0, 0, other);
221
-
222
- StringValue(str1);
223
- StringValue(str2);
224
-
225
- if (RSTRING_LEN(str1) == RSTRING_LEN(str2) &&
226
- rb_str_cmp(str1, str2) == 0) {
227
- return Qtrue;
228
- } else {
229
- return Qfalse;
230
- }
221
+ VALUE str1, str2;
222
+ str1 = buffer_digest(0, 0, self);
223
+ str2 = buffer_digest(0, 0, other);
224
+
225
+ StringValue(str1);
226
+ StringValue(str2);
227
+
228
+ if (RSTRING_LEN(str1) == RSTRING_LEN(str2) &&
229
+ rb_str_cmp(str1, str2) == 0) {
230
+ return Qtrue;
231
+ } else {
232
+ return Qfalse;
233
+ }
231
234
  }
232
235
 
233
236
  static VALUE
234
237
  buffer_inspect(VALUE self)
235
238
  {
236
- VALUE str;
237
- size_t digest_len = 32; /* about this size at least */
238
- const char *cname;
239
-
240
- cname = rb_obj_classname(self);
241
-
242
- /* #<Digest::ClassName: xxxxx...xxxx> */
243
- str = rb_str_buf_new(2 + strlen(cname) + 2 + digest_len * 2 + 1);
244
- rb_str_buf_cat2(str, "#<");
245
- rb_str_buf_cat2(str, cname);
246
- rb_str_buf_cat2(str, ": ");
247
- rb_str_buf_append(str, buffer_hexdigest(0, 0, self));
248
- rb_str_buf_cat2(str, ">");
249
- return str;
239
+ VALUE str;
240
+ size_t digest_len = 32; /* about this size at least */
241
+ const char *cname;
242
+
243
+ cname = rb_obj_classname(self);
244
+
245
+ /* #<Digest::ClassName: xxxxx...xxxx> */
246
+ str = rb_str_buf_new(2 + strlen(cname) + 2 + digest_len * 2 + 1);
247
+ rb_str_buf_cat2(str, "#<");
248
+ rb_str_buf_cat2(str, cname);
249
+ rb_str_buf_cat2(str, ": ");
250
+ rb_str_buf_append(str, buffer_hexdigest(0, 0, self));
251
+ rb_str_buf_cat2(str, ">");
252
+ return str;
250
253
  }
251
254
 
252
255
  static VALUE
253
256
  buffer_get(VALUE self)
254
257
  {
255
- buffer_t *ptr;
256
- Data_Get_Struct(self, buffer_t, ptr);
257
- return rb_str_new(ptr->buffer, buffer_buffer_length(ptr));
258
+ buffer_t *ptr;
259
+ Data_Get_Struct(self, buffer_t, ptr);
260
+ return rb_str_new(ptr->buffer, buffer_buffer_length(ptr));
258
261
  }
259
262
 
260
263
  static VALUE
261
264
  buffer_s_digest(int argc, VALUE *argv, VALUE klass)
262
265
  {
263
- VALUE str;
264
- volatile VALUE obj;
266
+ VALUE str;
267
+ volatile VALUE obj;
265
268
 
266
- if (argc < 1) {
267
- rb_raise(rb_eArgError, "no data given");
268
- }
269
+ if (argc < 1) {
270
+ rb_raise(rb_eArgError, "no data given");
271
+ }
269
272
 
270
- str = *argv++;
271
- argc--;
273
+ str = *argv++;
274
+ argc--;
272
275
 
273
- StringValue(str);
276
+ StringValue(str);
274
277
 
275
- obj = rb_obj_alloc(klass);
276
- rb_obj_call_init(obj, argc, argv);
278
+ obj = rb_obj_alloc(klass);
279
+ rb_obj_call_init(obj, argc, argv);
277
280
 
278
- return buffer_digest(1, &str, obj);
281
+ return buffer_digest(1, &str, obj);
279
282
  }
280
283
 
281
284
  static VALUE
282
285
  buffer_s_hexdigest(int argc, VALUE *argv, VALUE klass)
283
286
  {
284
- VALUE str;
285
- volatile VALUE obj;
287
+ VALUE str;
288
+ volatile VALUE obj;
286
289
 
287
- if (argc < 1) {
288
- rb_raise(rb_eArgError, "no data given");
289
- }
290
+ if (argc < 1) {
291
+ rb_raise(rb_eArgError, "no data given");
292
+ }
290
293
 
291
- str = *argv++;
292
- argc--;
294
+ str = *argv++;
295
+ argc--;
293
296
 
294
- StringValue(str);
297
+ StringValue(str);
295
298
 
296
- obj = rb_obj_alloc(klass);
297
- rb_obj_call_init(obj, argc, argv);
299
+ obj = rb_obj_alloc(klass);
300
+ rb_obj_call_init(obj, argc, argv);
298
301
 
299
- return hexencode_str_new(buffer_digest(1, &str, obj));
302
+ return hexencode_str_new(buffer_digest(1, &str, obj));
300
303
  }
301
304
 
302
305
  void
303
306
  Init_stringbuffer(void)
304
307
  {
305
- VALUE mDigest, cDigest_Class, cDigest_StringBuffer;
308
+ VALUE mDigest, cDigest_Class, cDigest_StringBuffer;
306
309
 
307
- /* Digest::Buffer is require that Digest module and Digest::Class class of CRuby built-in */
308
- rb_require("digest");
309
- mDigest = rb_path2class("Digest");
310
+ /* Digest::Buffer is require that Digest module and Digest::Class class of CRuby built-in */
311
+ rb_require("digest");
312
+ mDigest = rb_path2class("Digest");
310
313
 
311
- /* class Digest::Buffer < Digest::Class */
312
- cDigest_StringBuffer = rb_define_class_under(mDigest, "StringBuffer", rb_cObject);
314
+ /* class Digest::Buffer < Digest::Class */
315
+ cDigest_StringBuffer = rb_define_class_under(mDigest, "StringBuffer", rb_cObject);
313
316
 
314
- rb_define_alloc_func(cDigest_StringBuffer, buffer_alloc);
317
+ rb_define_alloc_func(cDigest_StringBuffer, buffer_alloc);
315
318
 
316
- rb_define_singleton_method(cDigest_StringBuffer, "digest", buffer_s_digest, -1);
317
- rb_define_singleton_method(cDigest_StringBuffer, "hexdigest", buffer_s_hexdigest, -1);
319
+ rb_define_singleton_method(cDigest_StringBuffer, "digest", buffer_s_digest, -1);
320
+ rb_define_singleton_method(cDigest_StringBuffer, "hexdigest", buffer_s_hexdigest, -1);
318
321
 
319
- rb_define_method(cDigest_StringBuffer, "update", buffer_update, 1);
320
- rb_define_alias(cDigest_StringBuffer, "<<", "update");
321
- rb_define_private_method(cDigest_StringBuffer, "finish", buffer_finish, 0);
322
- rb_define_method(cDigest_StringBuffer, "reset", buffer_reset, 0);
323
- rb_define_method(cDigest_StringBuffer, "digest_length", buffer_digest_length, 0);
324
- rb_define_alias(cDigest_StringBuffer, "length", "digest_length");
325
- rb_define_alias(cDigest_StringBuffer, "size", "digest_length");
326
- rb_define_method(cDigest_StringBuffer, "==", buffer_equal, 1);
327
- rb_define_method(cDigest_StringBuffer, "initialize_copy", buffer_initialize_copy, 1);
322
+ rb_define_method(cDigest_StringBuffer, "update", buffer_update, 1);
323
+ rb_define_alias(cDigest_StringBuffer, "<<", "update");
324
+ rb_define_private_method(cDigest_StringBuffer, "finish", buffer_finish, 0);
325
+ rb_define_method(cDigest_StringBuffer, "reset", buffer_reset, 0);
326
+ rb_define_method(cDigest_StringBuffer, "digest_length", buffer_digest_length, 0);
327
+ rb_define_alias(cDigest_StringBuffer, "length", "digest_length");
328
+ rb_define_alias(cDigest_StringBuffer, "size", "digest_length");
329
+ rb_define_method(cDigest_StringBuffer, "==", buffer_equal, 1);
330
+ rb_define_method(cDigest_StringBuffer, "initialize_copy", buffer_initialize_copy, 1);
328
331
 
329
- rb_define_method(cDigest_StringBuffer, "digest", buffer_digest, -1);
330
- rb_define_method(cDigest_StringBuffer, "digest!", buffer_digest_bang, 0);
331
- rb_define_method(cDigest_StringBuffer, "hexdigest", buffer_hexdigest, -1);
332
- rb_define_method(cDigest_StringBuffer, "hexdigest!", buffer_hexdigest_bang, 0);
333
- rb_define_method(cDigest_StringBuffer, "to_s", buffer_to_s, 0);
332
+ rb_define_method(cDigest_StringBuffer, "digest", buffer_digest, -1);
333
+ rb_define_method(cDigest_StringBuffer, "digest!", buffer_digest_bang, 0);
334
+ rb_define_method(cDigest_StringBuffer, "hexdigest", buffer_hexdigest, -1);
335
+ rb_define_method(cDigest_StringBuffer, "hexdigest!", buffer_hexdigest_bang, 0);
336
+ rb_define_method(cDigest_StringBuffer, "to_s", buffer_to_s, 0);
334
337
 
335
- rb_define_method(cDigest_StringBuffer, "buffer", buffer_get, 0);
338
+ rb_define_method(cDigest_StringBuffer, "buffer", buffer_get, 0);
336
339
  }
@@ -1,5 +1,5 @@
1
1
  module Digest
2
2
  class StringBuffer
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -40,7 +40,7 @@ Benchmark.bm do |x|
40
40
  Digest::BenchClass.digest("abc" * 1_000_000)
41
41
  end
42
42
 
43
- x.report("Digest::Buffer long string") do
43
+ x.report("Digest::StringBuffer long string") do
44
44
  Digest::BenchBuffer.digest("abc" * 1_000_000)
45
45
  end
46
46
 
@@ -50,7 +50,7 @@ Benchmark.bm do |x|
50
50
  }
51
51
  end
52
52
 
53
- x.report("Digest::Buffer meny times") do
53
+ x.report("Digest::StringBuffer meny times") do
54
54
  1000_000.times {
55
55
  Digest::BenchBuffer.digest("abc")
56
56
  }
@@ -1,15 +1,18 @@
1
1
  require 'digest/stringbuffer'
2
2
 
3
- class Test < Digest::StringBuffer
4
- def initialize
5
- @prime = 31
6
- end
3
+ module Digest
4
+ class Test < StringBuffer
5
+ def initialize
6
+ @prime = 31
7
+ end
7
8
 
8
- def finish
9
- result = 0
10
- buffer.unpack("C*").each do |c|
11
- result += (c * @prime)
9
+ def finish
10
+ result = 0
11
+ buffer.unpack("C*").each do |c|
12
+ result += (c * @prime)
13
+ end
14
+ [result & 0xffffffff].pack("N")
12
15
  end
13
- [result & 0xffffffff].pack("N")
14
16
  end
15
17
  end
18
+ include Digest
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digest-stringbuffer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-07 00:00:00.000000000 Z
11
+ date: 2014-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2.11'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.11'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake-compiler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: 0.8.3
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.8.3
69
69
  description: Digest::StringBuffer is a class that subset of Digest::Instance.
@@ -73,8 +73,8 @@ extensions:
73
73
  - ext/digest/stringbuffer/extconf.rb
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .gitignore
77
- - .travis.yml
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
78
  - Gemfile
79
79
  - LICENSE.txt
80
80
  - README.md
@@ -99,17 +99,17 @@ require_paths:
99
99
  - lib
100
100
  required_ruby_version: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - '>='
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - '>='
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
111
  rubyforge_project:
112
- rubygems_version: 2.1.11
112
+ rubygems_version: 2.4.1
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Digest::StringBuffer is a class that subset of Digest::Instance.