rubysl-digest 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +7 -0
- data/README.md +2 -2
- data/Rakefile +0 -1
- data/ext/rubysl/digest/bubblebabble/.gitignore +2 -0
- data/ext/rubysl/digest/bubblebabble/bubblebabble.c +147 -0
- data/ext/rubysl/digest/bubblebabble/bubblebabble.h +2 -0
- data/ext/rubysl/digest/bubblebabble/depend +3 -0
- data/ext/rubysl/digest/bubblebabble/extconf.h +4 -0
- data/ext/rubysl/digest/bubblebabble/extconf.rb +6 -0
- data/ext/rubysl/digest/defs.h +19 -0
- data/ext/rubysl/digest/digest.c +660 -0
- data/ext/rubysl/digest/digest.h +32 -0
- data/ext/rubysl/digest/extconf.rb +10 -0
- data/ext/rubysl/digest/md5/.gitignore +2 -0
- data/ext/rubysl/digest/md5/extconf.rb +29 -0
- data/ext/rubysl/digest/md5/md5.c +422 -0
- data/ext/rubysl/digest/md5/md5.h +80 -0
- data/ext/rubysl/digest/md5/md5init.c +40 -0
- data/ext/rubysl/digest/md5/md5ossl.c +9 -0
- data/ext/rubysl/digest/md5/md5ossl.h +13 -0
- data/ext/rubysl/digest/rmd160/.gitignore +2 -0
- data/ext/rubysl/digest/rmd160/extconf.rb +28 -0
- data/ext/rubysl/digest/rmd160/rmd160.c +457 -0
- data/ext/rubysl/digest/rmd160/rmd160.h +56 -0
- data/ext/rubysl/digest/rmd160/rmd160init.c +40 -0
- data/ext/rubysl/digest/rmd160/rmd160ossl.c +8 -0
- data/ext/rubysl/digest/rmd160/rmd160ossl.h +19 -0
- data/ext/rubysl/digest/sha1/.gitignore +2 -0
- data/ext/rubysl/digest/sha1/extconf.rb +28 -0
- data/ext/rubysl/digest/sha1/sha1.c +269 -0
- data/ext/rubysl/digest/sha1/sha1.h +39 -0
- data/ext/rubysl/digest/sha1/sha1init.c +40 -0
- data/ext/rubysl/digest/sha1/sha1ossl.c +10 -0
- data/ext/rubysl/digest/sha1/sha1ossl.h +20 -0
- data/ext/rubysl/digest/sha2/.gitignore +2 -0
- data/ext/rubysl/digest/sha2/extconf.rb +24 -0
- data/ext/rubysl/digest/sha2/sha2.c +919 -0
- data/ext/rubysl/digest/sha2/sha2.h +109 -0
- data/ext/rubysl/digest/sha2/sha2init.c +52 -0
- data/lib/digest/bubblebabble.rb +1 -0
- data/lib/digest/hmac.rb +302 -0
- data/lib/digest/md5.rb +23 -0
- data/lib/digest/rmd160.rb +1 -0
- data/lib/digest/sha1.rb +23 -0
- data/lib/digest/sha2.rb +74 -0
- data/lib/digest.rb +1 -0
- data/lib/rubysl/digest/digest.rb +88 -0
- data/lib/{rubysl-digest → rubysl/digest}/version.rb +1 -1
- data/lib/rubysl/digest.rb +2 -0
- data/rubysl-digest.gemspec +25 -17
- data/spec/hexencode_spec.rb +30 -0
- data/spec/md5/append_spec.rb +6 -0
- data/spec/md5/block_length_spec.rb +11 -0
- data/spec/md5/digest_bang_spec.rb +12 -0
- data/spec/md5/digest_length_spec.rb +11 -0
- data/spec/md5/digest_spec.rb +31 -0
- data/spec/md5/equal_spec.rb +37 -0
- data/spec/md5/file_spec.rb +42 -0
- data/spec/md5/hexdigest_bang_spec.rb +13 -0
- data/spec/md5/hexdigest_spec.rb +31 -0
- data/spec/md5/inspect_spec.rb +11 -0
- data/spec/md5/length_spec.rb +7 -0
- data/spec/md5/reset_spec.rb +14 -0
- data/spec/md5/shared/constants.rb +16 -0
- data/spec/md5/shared/length.rb +8 -0
- data/spec/md5/shared/sample.rb +15 -0
- data/spec/md5/shared/update.rb +7 -0
- data/spec/md5/size_spec.rb +7 -0
- data/spec/md5/to_s_spec.rb +21 -0
- data/spec/md5/update_spec.rb +6 -0
- data/spec/sha1/digest_spec.rb +19 -0
- data/spec/sha1/file_spec.rb +42 -0
- data/spec/sha1/shared/constants.rb +16 -0
- data/spec/sha256/append_spec.rb +6 -0
- data/spec/sha256/block_length_spec.rb +11 -0
- data/spec/sha256/digest_bang_spec.rb +12 -0
- data/spec/sha256/digest_length_spec.rb +11 -0
- data/spec/sha256/digest_spec.rb +31 -0
- data/spec/sha256/equal_spec.rb +36 -0
- data/spec/sha256/file_spec.rb +42 -0
- data/spec/sha256/hexdigest_bang_spec.rb +13 -0
- data/spec/sha256/hexdigest_spec.rb +31 -0
- data/spec/sha256/inspect_spec.rb +11 -0
- data/spec/sha256/length_spec.rb +7 -0
- data/spec/sha256/reset_spec.rb +14 -0
- data/spec/sha256/shared/constants.rb +16 -0
- data/spec/sha256/shared/length.rb +8 -0
- data/spec/sha256/shared/update.rb +7 -0
- data/spec/sha256/size_spec.rb +7 -0
- data/spec/sha256/to_s_spec.rb +20 -0
- data/spec/sha256/update_spec.rb +6 -0
- data/spec/sha384/append_spec.rb +6 -0
- data/spec/sha384/block_length_spec.rb +11 -0
- data/spec/sha384/digest_bang_spec.rb +12 -0
- data/spec/sha384/digest_length_spec.rb +11 -0
- data/spec/sha384/digest_spec.rb +31 -0
- data/spec/sha384/equal_spec.rb +36 -0
- data/spec/sha384/file_spec.rb +42 -0
- data/spec/sha384/hexdigest_bang_spec.rb +13 -0
- data/spec/sha384/hexdigest_spec.rb +31 -0
- data/spec/sha384/inspect_spec.rb +11 -0
- data/spec/sha384/length_spec.rb +7 -0
- data/spec/sha384/reset_spec.rb +14 -0
- data/spec/sha384/shared/constants.rb +17 -0
- data/spec/sha384/shared/length.rb +8 -0
- data/spec/sha384/shared/update.rb +7 -0
- data/spec/sha384/size_spec.rb +7 -0
- data/spec/sha384/to_s_spec.rb +20 -0
- data/spec/sha384/update_spec.rb +6 -0
- data/spec/sha512/append_spec.rb +6 -0
- data/spec/sha512/block_length_spec.rb +11 -0
- data/spec/sha512/digest_bang_spec.rb +12 -0
- data/spec/sha512/digest_length_spec.rb +11 -0
- data/spec/sha512/digest_spec.rb +31 -0
- data/spec/sha512/equal_spec.rb +36 -0
- data/spec/sha512/file_spec.rb +42 -0
- data/spec/sha512/hexdigest_bang_spec.rb +13 -0
- data/spec/sha512/hexdigest_spec.rb +31 -0
- data/spec/sha512/inspect_spec.rb +11 -0
- data/spec/sha512/length_spec.rb +7 -0
- data/spec/sha512/reset_spec.rb +14 -0
- data/spec/sha512/shared/constants.rb +16 -0
- data/spec/sha512/shared/length.rb +8 -0
- data/spec/sha512/shared/update.rb +7 -0
- data/spec/sha512/size_spec.rb +7 -0
- data/spec/sha512/to_s_spec.rb +20 -0
- data/spec/sha512/update_spec.rb +6 -0
- metadata +283 -88
- data/lib/rubysl-digest.rb +0 -7
data/rubysl-digest.gemspec
CHANGED
@@ -1,22 +1,30 @@
|
|
1
|
-
#
|
2
|
-
require
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/digest/version'
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-digest"
|
6
|
+
spec.version = RubySL::Digest::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library digest.}
|
10
|
+
spec.summary = %q{Ruby standard library digest.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-digest"
|
12
|
+
spec.license = "BSD"
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.extensions = ["ext/rubysl/digest/extconf.rb",
|
17
|
+
"ext/rubysl/digest/bubblebabble/extconf.rb",
|
18
|
+
"ext/rubysl/digest/md5/extconf.rb",
|
19
|
+
"ext/rubysl/digest/rmd160/extconf.rb",
|
20
|
+
"ext/rubysl/digest/sha1/extconf.rb",
|
21
|
+
"ext/rubysl/digest/sha2/extconf.rb" ]
|
22
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
|
+
spec.require_paths = ["lib"]
|
17
24
|
|
18
|
-
|
25
|
+
spec.add_runtime_dependency "redcard", "~> 1.0"
|
19
26
|
|
20
|
-
|
21
|
-
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
22
30
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
describe "Digest.hexencode" do
|
4
|
+
before(:each) do
|
5
|
+
@string = 'sample string'
|
6
|
+
@encoded = "73616d706c6520737472696e67"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns '' when passed an empty String" do
|
10
|
+
Digest.hexencode('').should == ''
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns the hex-encoded value of a non-empty String" do
|
14
|
+
Digest.hexencode(@string).should == @encoded
|
15
|
+
end
|
16
|
+
|
17
|
+
it "calls #to_str on an object and returns the hex-encoded value of the result" do
|
18
|
+
obj = mock("to_str")
|
19
|
+
obj.should_receive(:to_str).and_return(@string)
|
20
|
+
Digest.hexencode(obj).should == @encoded
|
21
|
+
end
|
22
|
+
|
23
|
+
it "raises a TypeError when passed nil" do
|
24
|
+
lambda { Digest.hexencode(nil) }.should raise_error(TypeError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "raises a TypeError when passed a Fixnum" do
|
28
|
+
lambda { Digest.hexencode(9001) }.should raise_error(TypeError)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
|
3
|
+
describe "Digest::MD5#digest!" do
|
4
|
+
|
5
|
+
it "returns a digest and can digest!" do
|
6
|
+
cur_digest = Digest::MD5.new
|
7
|
+
cur_digest << MD5Constants::Contents
|
8
|
+
cur_digest.digest!().should == MD5Constants::Digest
|
9
|
+
cur_digest.digest().should == MD5Constants::BlankDigest
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
|
3
|
+
describe "Digest::MD5#digest_length" do
|
4
|
+
|
5
|
+
it "returns the length of computed digests" do
|
6
|
+
cur_digest = Digest::MD5.new
|
7
|
+
cur_digest.digest_length.should == MD5Constants::DigestLength
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
|
3
|
+
describe "Digest::MD5#digest" do
|
4
|
+
|
5
|
+
it "returns a digest" do
|
6
|
+
cur_digest = Digest::MD5.new
|
7
|
+
cur_digest.digest().should == MD5Constants::BlankDigest
|
8
|
+
|
9
|
+
# add something to check that the state is reset later
|
10
|
+
cur_digest << "test"
|
11
|
+
|
12
|
+
cur_digest.digest(MD5Constants::Contents).should == MD5Constants::Digest
|
13
|
+
# second invocation is intentional, to make sure there are no side-effects
|
14
|
+
cur_digest.digest(MD5Constants::Contents).should == MD5Constants::Digest
|
15
|
+
|
16
|
+
# after all is done, verify that the digest is in the original, blank state
|
17
|
+
cur_digest.digest.should == MD5Constants::BlankDigest
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Digest::MD5.digest" do
|
23
|
+
|
24
|
+
it "returns a digest" do
|
25
|
+
Digest::MD5.digest(MD5Constants::Contents).should == MD5Constants::Digest
|
26
|
+
# second invocation is intentional, to make sure there are no side-effects
|
27
|
+
Digest::MD5.digest(MD5Constants::Contents).should == MD5Constants::Digest
|
28
|
+
Digest::MD5.digest("").should == MD5Constants::BlankDigest
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
|
3
|
+
describe "Digest::MD5#==" do
|
4
|
+
|
5
|
+
it "equals itself" do
|
6
|
+
cur_digest = Digest::MD5.new
|
7
|
+
cur_digest.should == cur_digest
|
8
|
+
end
|
9
|
+
|
10
|
+
it "equals the string representing its hexdigest" do
|
11
|
+
cur_digest = Digest::MD5.new
|
12
|
+
cur_digest.should == MD5Constants::BlankHexdigest
|
13
|
+
end
|
14
|
+
|
15
|
+
it "equals the appropriate object that responds to to_str" do
|
16
|
+
# blank digest
|
17
|
+
cur_digest = Digest::MD5.new
|
18
|
+
obj = mock(MD5Constants::BlankHexdigest)
|
19
|
+
obj.should_receive(:to_str).and_return(MD5Constants::BlankHexdigest)
|
20
|
+
cur_digest.should == obj
|
21
|
+
|
22
|
+
# non-blank digest
|
23
|
+
cur_digest = Digest::MD5.new
|
24
|
+
cur_digest << "test"
|
25
|
+
d_value = cur_digest.hexdigest
|
26
|
+
(obj = mock(d_value)).should_receive(:to_str).and_return(d_value)
|
27
|
+
cur_digest.should == obj
|
28
|
+
end
|
29
|
+
|
30
|
+
it "equals the same digest for a different object" do
|
31
|
+
cur_digest = Digest::MD5.new
|
32
|
+
cur_digest2 = Digest::MD5.new
|
33
|
+
cur_digest.should == cur_digest2
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
require File.expand_path('../../../../core/file/shared/read', __FILE__)
|
3
|
+
|
4
|
+
describe "Digest::MD5.file" do
|
5
|
+
|
6
|
+
describe "when passed a path to a file that exists" do
|
7
|
+
before :each do
|
8
|
+
@file = tmp("md5_temp")
|
9
|
+
touch(@file, 'wb') {|f| f.write MD5Constants::Contents }
|
10
|
+
end
|
11
|
+
|
12
|
+
after :each do
|
13
|
+
rm_r @file
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns a Digest::MD5 object" do
|
17
|
+
Digest::MD5.file(@file).should be_kind_of(Digest::MD5)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns a Digest::MD5 object with the correct digest" do
|
21
|
+
Digest::MD5.file(@file).digest.should == MD5Constants::Digest
|
22
|
+
end
|
23
|
+
|
24
|
+
it "calls #to_str on an object and returns the Digest::MD5 with the result" do
|
25
|
+
obj = mock("to_str")
|
26
|
+
obj.should_receive(:to_str).and_return(@file)
|
27
|
+
result = Digest::MD5.file(obj)
|
28
|
+
result.should be_kind_of(Digest::MD5)
|
29
|
+
result.digest.should == MD5Constants::Digest
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it_behaves_like :file_read_directory, :file, Digest::MD5
|
34
|
+
|
35
|
+
it "raises a Errno::ENOENT when passed a path that does not exist" do
|
36
|
+
lambda { Digest::MD5.file("") }.should raise_error(Errno::ENOENT)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "raises a TypeError when passed nil" do
|
40
|
+
lambda { Digest::MD5.file(nil) }.should raise_error(TypeError)
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
|
3
|
+
describe "Digest::MD5#hexdigest!" do
|
4
|
+
|
5
|
+
it "returns a hexdigest and resets the state" do
|
6
|
+
cur_digest = Digest::MD5.new
|
7
|
+
|
8
|
+
cur_digest << MD5Constants::Contents
|
9
|
+
cur_digest.hexdigest!.should == MD5Constants::Hexdigest
|
10
|
+
cur_digest.hexdigest.should == MD5Constants::BlankHexdigest
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
|
3
|
+
describe "Digest::MD5#hexdigest" do
|
4
|
+
|
5
|
+
it "returns a hexdigest" do
|
6
|
+
cur_digest = Digest::MD5.new
|
7
|
+
cur_digest.hexdigest.should == MD5Constants::BlankHexdigest
|
8
|
+
|
9
|
+
# add something to check that the state is reset later
|
10
|
+
cur_digest << "test"
|
11
|
+
|
12
|
+
cur_digest.hexdigest(MD5Constants::Contents).should == MD5Constants::Hexdigest
|
13
|
+
# second invocation is intentional, to make sure there are no side-effects
|
14
|
+
cur_digest.hexdigest(MD5Constants::Contents).should == MD5Constants::Hexdigest
|
15
|
+
|
16
|
+
# after all is done, verify that the digest is in the original, blank state
|
17
|
+
cur_digest.hexdigest.should == MD5Constants::BlankHexdigest
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Digest::MD5.hexdigest" do
|
23
|
+
|
24
|
+
it "returns a hexdigest" do
|
25
|
+
Digest::MD5.hexdigest(MD5Constants::Contents).should == MD5Constants::Hexdigest
|
26
|
+
# second invocation is intentional, to make sure there are no side-effects
|
27
|
+
Digest::MD5.hexdigest(MD5Constants::Contents).should == MD5Constants::Hexdigest
|
28
|
+
Digest::MD5.hexdigest("").should == MD5Constants::BlankHexdigest
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
|
3
|
+
describe "Digest::MD5#inspect" do
|
4
|
+
|
5
|
+
it "returns a Ruby object representation" do
|
6
|
+
cur_digest = Digest::MD5.new
|
7
|
+
cur_digest.inspect.should == "#<#{MD5Constants::Klass}: #{cur_digest.hexdigest()}>"
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
|
3
|
+
describe "Digest::MD5#reset" do
|
4
|
+
|
5
|
+
it "returns digest state to initial conditions" do
|
6
|
+
cur_digest = Digest::MD5.new
|
7
|
+
cur_digest.update MD5Constants::Contents
|
8
|
+
cur_digest.digest().should_not == MD5Constants::BlankDigest
|
9
|
+
cur_digest.reset
|
10
|
+
cur_digest.digest().should == MD5Constants::BlankDigest
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: US-ASCII -*-
|
2
|
+
require 'digest/md5'
|
3
|
+
|
4
|
+
module MD5Constants
|
5
|
+
|
6
|
+
Contents = "Ipsum is simply dummy text of the printing and typesetting industry. \nLorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \nIt has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. \nIt was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
|
7
|
+
|
8
|
+
Klass = ::Digest::MD5
|
9
|
+
BlockLength = 64
|
10
|
+
DigestLength = 16
|
11
|
+
BlankDigest = "\324\035\214\331\217\000\262\004\351\200\t\230\354\370B~"
|
12
|
+
Digest = "\2473\267qw\276\364\343\345\320\304\350\313\314\217n"
|
13
|
+
BlankHexdigest = "d41d8cd98f00b204e9800998ecf8427e"
|
14
|
+
Hexdigest = "a733b77177bef4e3e5d0c4e8cbcc8f6e"
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
describe :md5_length, :shared => true do
|
2
|
+
it "returns the length of the digest" do
|
3
|
+
cur_digest = Digest::MD5.new
|
4
|
+
cur_digest.send(@method).should == MD5Constants::BlankDigest.size
|
5
|
+
cur_digest << MD5Constants::Contents
|
6
|
+
cur_digest.send(@method).should == MD5Constants::Digest.size
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
|
3
|
+
module MD5Constants
|
4
|
+
|
5
|
+
Contents = "Ipsum is simply dummy text of the printing and typesetting industry. \nLorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \nIt has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. \nIt was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
|
6
|
+
|
7
|
+
Klass = ::Digest::MD5
|
8
|
+
BlockLength = 64
|
9
|
+
DigestLength = 16
|
10
|
+
BlankDigest = "\324\035\214\331\217\000\262\004\351\200\t\230\354\370B~"
|
11
|
+
Digest = "\2473\267qw\276\364\343\345\320\304\350\313\314\217n"
|
12
|
+
BlankHexdigest = "d41d8cd98f00b204e9800998ecf8427e"
|
13
|
+
Hexdigest = "a733b77177bef4e3e5d0c4e8cbcc8f6e"
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
require File.expand_path('../shared/constants', __FILE__)
|
3
|
+
|
4
|
+
describe "Digest::MD5#to_s" do
|
5
|
+
|
6
|
+
it "returns a hexdigest" do
|
7
|
+
cur_digest = Digest::MD5.new
|
8
|
+
cur_digest.to_s.should == MD5Constants::BlankHexdigest
|
9
|
+
end
|
10
|
+
|
11
|
+
it "does not change the internal state" do
|
12
|
+
cur_digest = Digest::MD5.new
|
13
|
+
cur_digest.to_s.should == MD5Constants::BlankHexdigest
|
14
|
+
cur_digest.to_s.should == MD5Constants::BlankHexdigest
|
15
|
+
|
16
|
+
cur_digest << MD5Constants::Contents
|
17
|
+
cur_digest.to_s.should == MD5Constants::Hexdigest
|
18
|
+
cur_digest.to_s.should == MD5Constants::Hexdigest
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
|
3
|
+
describe "Digest::SHA1#digest" do
|
4
|
+
|
5
|
+
it "returns a digest" do
|
6
|
+
cur_digest = Digest::SHA1.new
|
7
|
+
cur_digest.digest().should == SHA1Constants::BlankDigest
|
8
|
+
cur_digest.digest(SHA1Constants::Contents).should == SHA1Constants::Digest
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "Digest::SHA1.digest" do
|
14
|
+
|
15
|
+
it "returns a digest" do
|
16
|
+
Digest::SHA1.digest(SHA1Constants::Contents).should == SHA1Constants::Digest
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
require File.expand_path('../../../../core/file/shared/read', __FILE__)
|
3
|
+
|
4
|
+
describe "Digest::SHA1.file" do
|
5
|
+
|
6
|
+
describe "when passed a path to a file that exists" do
|
7
|
+
before :each do
|
8
|
+
@file = tmp("md5_temp")
|
9
|
+
touch(@file, 'wb') {|f| f.write SHA1Constants::Contents }
|
10
|
+
end
|
11
|
+
|
12
|
+
after :each do
|
13
|
+
rm_r @file
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns a Digest::SHA1 object" do
|
17
|
+
Digest::SHA1.file(@file).should be_kind_of(Digest::SHA1)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns a Digest::SHA1 object with the correct digest" do
|
21
|
+
Digest::SHA1.file(@file).digest.should == SHA1Constants::Digest
|
22
|
+
end
|
23
|
+
|
24
|
+
it "calls #to_str on an object and returns the Digest::SHA1 with the result" do
|
25
|
+
obj = mock("to_str")
|
26
|
+
obj.should_receive(:to_str).and_return(@file)
|
27
|
+
result = Digest::SHA1.file(obj)
|
28
|
+
result.should be_kind_of(Digest::SHA1)
|
29
|
+
result.digest.should == SHA1Constants::Digest
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it_behaves_like :file_read_directory, :file, Digest::SHA1
|
34
|
+
|
35
|
+
it "raises a Errno::ENOENT when passed a path that does not exist" do
|
36
|
+
lambda { Digest::SHA1.file("") }.should raise_error(Errno::ENOENT)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "raises a TypeError when passed nil" do
|
40
|
+
lambda { Digest::SHA1.file(nil) }.should raise_error(TypeError)
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: US-ASCII -*-
|
2
|
+
require 'digest/sha1'
|
3
|
+
|
4
|
+
module SHA1Constants
|
5
|
+
|
6
|
+
Contents = "Ipsum is simply dummy text of the printing and typesetting industry. \nLorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \nIt has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. \nIt was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
|
7
|
+
|
8
|
+
Klass = ::Digest::SHA1
|
9
|
+
BlockLength = 64
|
10
|
+
DigestLength = 20
|
11
|
+
BlankDigest = "\3329\243\356^kK\r2U\277\357\225`\030\220\257\330\a\t"
|
12
|
+
Digest = "X!\255b\323\035\352\314a|q\344+\376\317\361V9\324\343"
|
13
|
+
BlankHexdigest = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
14
|
+
Hexdigest = "e907d2ba21c6c74bc0efd76e44d11fb9bbb7a75e"
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
|
3
|
+
describe "Digest::SHA256#block_length" do
|
4
|
+
|
5
|
+
it "returns the length of digest block" do
|
6
|
+
cur_digest = Digest::SHA256.new
|
7
|
+
cur_digest.block_length.should == SHA256Constants::BlockLength
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
|
3
|
+
describe "Digest::SHA256#digest!" do
|
4
|
+
|
5
|
+
it "returns a digest and can digest!" do
|
6
|
+
cur_digest = Digest::SHA256.new
|
7
|
+
cur_digest << SHA256Constants::Contents
|
8
|
+
cur_digest.digest!().should == SHA256Constants::Digest
|
9
|
+
cur_digest.digest().should == SHA256Constants::BlankDigest
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
|
3
|
+
describe "Digest::SHA256#digest_length" do
|
4
|
+
|
5
|
+
it "returns the length of computed digests" do
|
6
|
+
cur_digest = Digest::SHA256.new
|
7
|
+
cur_digest.digest_length.should == SHA256Constants::DigestLength
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
|
3
|
+
describe "Digest::SHA256#digest" do
|
4
|
+
|
5
|
+
it "returns a digest" do
|
6
|
+
cur_digest = Digest::SHA256.new
|
7
|
+
cur_digest.digest().should == SHA256Constants::BlankDigest
|
8
|
+
|
9
|
+
# add something to check that the state is reset later
|
10
|
+
cur_digest << "test"
|
11
|
+
|
12
|
+
cur_digest.digest(SHA256Constants::Contents).should == SHA256Constants::Digest
|
13
|
+
# second invocation is intentional, to make sure there are no side-effects
|
14
|
+
cur_digest.digest(SHA256Constants::Contents).should == SHA256Constants::Digest
|
15
|
+
|
16
|
+
# after all is done, verify that the digest is in the original, blank state
|
17
|
+
cur_digest.digest.should == SHA256Constants::BlankDigest
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Digest::SHA256.digest" do
|
23
|
+
|
24
|
+
it "returns a digest" do
|
25
|
+
Digest::SHA256.digest(SHA256Constants::Contents).should == SHA256Constants::Digest
|
26
|
+
# second invocation is intentional, to make sure there are no side-effects
|
27
|
+
Digest::SHA256.digest(SHA256Constants::Contents).should == SHA256Constants::Digest
|
28
|
+
Digest::SHA256.digest("").should == SHA256Constants::BlankDigest
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
|
3
|
+
describe "Digest::SHA256#==" do
|
4
|
+
|
5
|
+
it "equals itself" do
|
6
|
+
cur_digest = Digest::SHA256.new
|
7
|
+
cur_digest.should == cur_digest
|
8
|
+
end
|
9
|
+
|
10
|
+
it "equals the string representing its hexdigest" do
|
11
|
+
cur_digest = Digest::SHA256.new
|
12
|
+
cur_digest.should == SHA256Constants::BlankHexdigest
|
13
|
+
end
|
14
|
+
|
15
|
+
it "equals the appropriate object that responds to to_str" do
|
16
|
+
# blank digest
|
17
|
+
cur_digest = Digest::SHA256.new
|
18
|
+
(obj = mock(SHA256Constants::BlankHexdigest)).should_receive(:to_str).and_return(SHA256Constants::BlankHexdigest)
|
19
|
+
cur_digest.should == obj
|
20
|
+
|
21
|
+
# non-blank digest
|
22
|
+
cur_digest = Digest::SHA256.new
|
23
|
+
cur_digest << "test"
|
24
|
+
d_value = cur_digest.hexdigest
|
25
|
+
(obj = mock(d_value)).should_receive(:to_str).and_return(d_value)
|
26
|
+
cur_digest.should == obj
|
27
|
+
end
|
28
|
+
|
29
|
+
it "equals the same digest for a different object" do
|
30
|
+
cur_digest = Digest::SHA256.new
|
31
|
+
cur_digest2 = Digest::SHA256.new
|
32
|
+
cur_digest.should == cur_digest2
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path('../shared/constants', __FILE__)
|
2
|
+
require File.expand_path('../../../../core/file/shared/read', __FILE__)
|
3
|
+
|
4
|
+
describe "Digest::SHA256.file" do
|
5
|
+
|
6
|
+
describe "when passed a path to a file that exists" do
|
7
|
+
before :each do
|
8
|
+
@file = tmp("md5_temp")
|
9
|
+
touch(@file, 'wb') {|f| f.write SHA256Constants::Contents }
|
10
|
+
end
|
11
|
+
|
12
|
+
after :each do
|
13
|
+
rm_r @file
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns a Digest::SHA256 object" do
|
17
|
+
Digest::SHA256.file(@file).should be_kind_of(Digest::SHA256)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns a Digest::SHA256 object with the correct digest" do
|
21
|
+
Digest::SHA256.file(@file).digest.should == SHA256Constants::Digest
|
22
|
+
end
|
23
|
+
|
24
|
+
it "calls #to_str on an object and returns the Digest::SHA256 with the result" do
|
25
|
+
obj = mock("to_str")
|
26
|
+
obj.should_receive(:to_str).and_return(@file)
|
27
|
+
result = Digest::SHA256.file(obj)
|
28
|
+
result.should be_kind_of(Digest::SHA256)
|
29
|
+
result.digest.should == SHA256Constants::Digest
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it_behaves_like :file_read_directory, :file, Digest::SHA256
|
34
|
+
|
35
|
+
it "raises a Errno::ENOENT when passed a path that does not exist" do
|
36
|
+
lambda { Digest::SHA256.file("") }.should raise_error(Errno::ENOENT)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "raises a TypeError when passed nil" do
|
40
|
+
lambda { Digest::SHA256.file(nil) }.should raise_error(TypeError)
|
41
|
+
end
|
42
|
+
end
|