digest-simple 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c776bdfb959fb77e21a5a173425b6e0c8f6bfda5
4
+ data.tar.gz: 258b469ec8a39bba6856e7bf0f719e321fadbca2
5
+ SHA512:
6
+ metadata.gz: 4c3fbbc7e439772ef78c095364f137a0575005d2697c1f3518db43f04f4a8f95a2f41fa1500e186fd238e4b8e5a18a4785364b192c806379ba204a187cdd2a2d
7
+ data.tar.gz: 120b016886271f9816ef5314ad0bafc073c2991b4e2995df589b1fc0293f3202317b34a858232cf97ae390e8c99e9476a765148f451481693ac7b1e665f8de1e
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ digest-simple (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.3.2)
11
+ rspec (3.1.0)
12
+ rspec-core (~> 3.1.0)
13
+ rspec-expectations (~> 3.1.0)
14
+ rspec-mocks (~> 3.1.0)
15
+ rspec-core (3.1.5)
16
+ rspec-support (~> 3.1.0)
17
+ rspec-expectations (3.1.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.1.0)
20
+ rspec-mocks (3.1.2)
21
+ rspec-support (~> 3.1.0)
22
+ rspec-support (3.1.1)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler
29
+ digest-simple!
30
+ rake
31
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 ksss
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Digest::Simple
2
+
3
+ **Digest::Simple** is a class that minimun implement for non block message digest.
4
+
5
+ ## Usage
6
+
7
+ Digest::Simple depends only one method `finish`.
8
+
9
+ ```ruby
10
+ module Digest
11
+ class Prime31 < Simple
12
+ def initialize
13
+ @prime = 31
14
+ # should be call Digest::Simple#initialize
15
+ super
16
+ end
17
+
18
+ def finish
19
+ result = 0
20
+ # @buffer is a internal variable
21
+ @buffer.unpack("C*").each do |c|
22
+ result += (c * @prime)
23
+ end
24
+ [result & 0xffffffff].pack("N")
25
+ end
26
+ end
27
+ end
28
+
29
+ p Digest::Prime31.hexdigest("abc" * 1000) #=> "008b1190"
30
+ ```
31
+
32
+ ## APIs
33
+
34
+ All methods in **Digest::Class**
35
+
36
+ ## Installation
37
+
38
+ Add this line to your application's Gemfile:
39
+
40
+ gem 'digest-simple'
41
+
42
+ And then execute:
43
+
44
+ $ bundle
45
+
46
+ Or install it yourself as:
47
+
48
+ $ gem install digest-simple
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.rspec_opts = ["-c", "-f progress", "-Ilib"]
8
+ t.pattern = "spec/**/*_spec.rb"
9
+ t.verbose = true
10
+ end
11
+
12
+ task :default => [:spec]
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'digest/simple'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "digest-simple"
9
+ spec.version = Digest::Simple::VERSION
10
+ spec.authors = ["ksss"]
11
+ spec.email = ["co000ri@gmail.com"]
12
+ spec.summary = %q{Digest::Simple is a class that minimun implementation for non block message digest.}
13
+ spec.description = %q{Digest::Simple is a class that minimun implementation for non block message digest.}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,44 @@
1
+ require 'digest'
2
+
3
+ module Digest
4
+ class Simple < Class
5
+ VERSION = "1.0.0"
6
+
7
+ def initialize
8
+ @buffer = ""
9
+ end
10
+
11
+ def reset
12
+ @buffer.clear
13
+ self
14
+ end
15
+
16
+ def update(str)
17
+ @buffer += str
18
+ self
19
+ end
20
+ alias << update
21
+
22
+ def digest(str=nil)
23
+ if str
24
+ reset
25
+ update(str)
26
+ v = finish
27
+ reset
28
+ v
29
+ else
30
+ dup.send :finish
31
+ end
32
+ end
33
+
34
+ def block_length
35
+ 0
36
+ end
37
+
38
+ private
39
+
40
+ def finish
41
+ fail NotImplementedError, "must be defined finish method"
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,41 @@
1
+ require 'digest/simple'
2
+
3
+ module Digest
4
+ class Prime31 < Simple
5
+ def initialize
6
+ @prime = 31
7
+ super
8
+ end
9
+
10
+ def finish
11
+ result = 0
12
+ @buffer.unpack("C*").each do |c|
13
+ result += (c * @prime)
14
+ end
15
+ [result & 0xffffffff].pack("N")
16
+ end
17
+ end
18
+ end
19
+
20
+ describe Digest::Simple do
21
+ it "#initialize" do
22
+ expect(Digest::Simple.new).to be_a_kind_of(Digest::Class)
23
+ end
24
+
25
+ it "#update" do
26
+ s = Digest::Prime31.new
27
+ expect(s.update("abc").object_id).to eq(s.object_id)
28
+ end
29
+
30
+ it "#reset" do
31
+ s = Digest::Prime31.new
32
+ expect(s.hexdigest).to eq("00000000")
33
+ s.update("abc")
34
+ expect(s.hexdigest).to eq("0000239a")
35
+ expect(s.reset.hexdigest).to eq("00000000")
36
+ end
37
+
38
+ it ".hexdigest" do
39
+ expect(Digest::Prime31.hexdigest("abc" * 1000)).to eq("008b1190")
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: digest-simple
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ksss
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Digest::Simple is a class that minimun implementation for non block message
56
+ digest.
57
+ email:
58
+ - co000ri@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - digest-simple.gemspec
69
+ - lib/digest/simple.rb
70
+ - spec/simple_spec.rb
71
+ homepage: ''
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.0
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Digest::Simple is a class that minimun implementation for non block message
95
+ digest.
96
+ test_files:
97
+ - spec/simple_spec.rb