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.
Files changed (131) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +0 -1
  3. data/.travis.yml +7 -0
  4. data/README.md +2 -2
  5. data/Rakefile +0 -1
  6. data/ext/rubysl/digest/bubblebabble/.gitignore +2 -0
  7. data/ext/rubysl/digest/bubblebabble/bubblebabble.c +147 -0
  8. data/ext/rubysl/digest/bubblebabble/bubblebabble.h +2 -0
  9. data/ext/rubysl/digest/bubblebabble/depend +3 -0
  10. data/ext/rubysl/digest/bubblebabble/extconf.h +4 -0
  11. data/ext/rubysl/digest/bubblebabble/extconf.rb +6 -0
  12. data/ext/rubysl/digest/defs.h +19 -0
  13. data/ext/rubysl/digest/digest.c +660 -0
  14. data/ext/rubysl/digest/digest.h +32 -0
  15. data/ext/rubysl/digest/extconf.rb +10 -0
  16. data/ext/rubysl/digest/md5/.gitignore +2 -0
  17. data/ext/rubysl/digest/md5/extconf.rb +29 -0
  18. data/ext/rubysl/digest/md5/md5.c +422 -0
  19. data/ext/rubysl/digest/md5/md5.h +80 -0
  20. data/ext/rubysl/digest/md5/md5init.c +40 -0
  21. data/ext/rubysl/digest/md5/md5ossl.c +9 -0
  22. data/ext/rubysl/digest/md5/md5ossl.h +13 -0
  23. data/ext/rubysl/digest/rmd160/.gitignore +2 -0
  24. data/ext/rubysl/digest/rmd160/extconf.rb +28 -0
  25. data/ext/rubysl/digest/rmd160/rmd160.c +457 -0
  26. data/ext/rubysl/digest/rmd160/rmd160.h +56 -0
  27. data/ext/rubysl/digest/rmd160/rmd160init.c +40 -0
  28. data/ext/rubysl/digest/rmd160/rmd160ossl.c +8 -0
  29. data/ext/rubysl/digest/rmd160/rmd160ossl.h +19 -0
  30. data/ext/rubysl/digest/sha1/.gitignore +2 -0
  31. data/ext/rubysl/digest/sha1/extconf.rb +28 -0
  32. data/ext/rubysl/digest/sha1/sha1.c +269 -0
  33. data/ext/rubysl/digest/sha1/sha1.h +39 -0
  34. data/ext/rubysl/digest/sha1/sha1init.c +40 -0
  35. data/ext/rubysl/digest/sha1/sha1ossl.c +10 -0
  36. data/ext/rubysl/digest/sha1/sha1ossl.h +20 -0
  37. data/ext/rubysl/digest/sha2/.gitignore +2 -0
  38. data/ext/rubysl/digest/sha2/extconf.rb +24 -0
  39. data/ext/rubysl/digest/sha2/sha2.c +919 -0
  40. data/ext/rubysl/digest/sha2/sha2.h +109 -0
  41. data/ext/rubysl/digest/sha2/sha2init.c +52 -0
  42. data/lib/digest/bubblebabble.rb +1 -0
  43. data/lib/digest/hmac.rb +302 -0
  44. data/lib/digest/md5.rb +23 -0
  45. data/lib/digest/rmd160.rb +1 -0
  46. data/lib/digest/sha1.rb +23 -0
  47. data/lib/digest/sha2.rb +74 -0
  48. data/lib/digest.rb +1 -0
  49. data/lib/rubysl/digest/digest.rb +88 -0
  50. data/lib/{rubysl-digest → rubysl/digest}/version.rb +1 -1
  51. data/lib/rubysl/digest.rb +2 -0
  52. data/rubysl-digest.gemspec +25 -17
  53. data/spec/hexencode_spec.rb +30 -0
  54. data/spec/md5/append_spec.rb +6 -0
  55. data/spec/md5/block_length_spec.rb +11 -0
  56. data/spec/md5/digest_bang_spec.rb +12 -0
  57. data/spec/md5/digest_length_spec.rb +11 -0
  58. data/spec/md5/digest_spec.rb +31 -0
  59. data/spec/md5/equal_spec.rb +37 -0
  60. data/spec/md5/file_spec.rb +42 -0
  61. data/spec/md5/hexdigest_bang_spec.rb +13 -0
  62. data/spec/md5/hexdigest_spec.rb +31 -0
  63. data/spec/md5/inspect_spec.rb +11 -0
  64. data/spec/md5/length_spec.rb +7 -0
  65. data/spec/md5/reset_spec.rb +14 -0
  66. data/spec/md5/shared/constants.rb +16 -0
  67. data/spec/md5/shared/length.rb +8 -0
  68. data/spec/md5/shared/sample.rb +15 -0
  69. data/spec/md5/shared/update.rb +7 -0
  70. data/spec/md5/size_spec.rb +7 -0
  71. data/spec/md5/to_s_spec.rb +21 -0
  72. data/spec/md5/update_spec.rb +6 -0
  73. data/spec/sha1/digest_spec.rb +19 -0
  74. data/spec/sha1/file_spec.rb +42 -0
  75. data/spec/sha1/shared/constants.rb +16 -0
  76. data/spec/sha256/append_spec.rb +6 -0
  77. data/spec/sha256/block_length_spec.rb +11 -0
  78. data/spec/sha256/digest_bang_spec.rb +12 -0
  79. data/spec/sha256/digest_length_spec.rb +11 -0
  80. data/spec/sha256/digest_spec.rb +31 -0
  81. data/spec/sha256/equal_spec.rb +36 -0
  82. data/spec/sha256/file_spec.rb +42 -0
  83. data/spec/sha256/hexdigest_bang_spec.rb +13 -0
  84. data/spec/sha256/hexdigest_spec.rb +31 -0
  85. data/spec/sha256/inspect_spec.rb +11 -0
  86. data/spec/sha256/length_spec.rb +7 -0
  87. data/spec/sha256/reset_spec.rb +14 -0
  88. data/spec/sha256/shared/constants.rb +16 -0
  89. data/spec/sha256/shared/length.rb +8 -0
  90. data/spec/sha256/shared/update.rb +7 -0
  91. data/spec/sha256/size_spec.rb +7 -0
  92. data/spec/sha256/to_s_spec.rb +20 -0
  93. data/spec/sha256/update_spec.rb +6 -0
  94. data/spec/sha384/append_spec.rb +6 -0
  95. data/spec/sha384/block_length_spec.rb +11 -0
  96. data/spec/sha384/digest_bang_spec.rb +12 -0
  97. data/spec/sha384/digest_length_spec.rb +11 -0
  98. data/spec/sha384/digest_spec.rb +31 -0
  99. data/spec/sha384/equal_spec.rb +36 -0
  100. data/spec/sha384/file_spec.rb +42 -0
  101. data/spec/sha384/hexdigest_bang_spec.rb +13 -0
  102. data/spec/sha384/hexdigest_spec.rb +31 -0
  103. data/spec/sha384/inspect_spec.rb +11 -0
  104. data/spec/sha384/length_spec.rb +7 -0
  105. data/spec/sha384/reset_spec.rb +14 -0
  106. data/spec/sha384/shared/constants.rb +17 -0
  107. data/spec/sha384/shared/length.rb +8 -0
  108. data/spec/sha384/shared/update.rb +7 -0
  109. data/spec/sha384/size_spec.rb +7 -0
  110. data/spec/sha384/to_s_spec.rb +20 -0
  111. data/spec/sha384/update_spec.rb +6 -0
  112. data/spec/sha512/append_spec.rb +6 -0
  113. data/spec/sha512/block_length_spec.rb +11 -0
  114. data/spec/sha512/digest_bang_spec.rb +12 -0
  115. data/spec/sha512/digest_length_spec.rb +11 -0
  116. data/spec/sha512/digest_spec.rb +31 -0
  117. data/spec/sha512/equal_spec.rb +36 -0
  118. data/spec/sha512/file_spec.rb +42 -0
  119. data/spec/sha512/hexdigest_bang_spec.rb +13 -0
  120. data/spec/sha512/hexdigest_spec.rb +31 -0
  121. data/spec/sha512/inspect_spec.rb +11 -0
  122. data/spec/sha512/length_spec.rb +7 -0
  123. data/spec/sha512/reset_spec.rb +14 -0
  124. data/spec/sha512/shared/constants.rb +16 -0
  125. data/spec/sha512/shared/length.rb +8 -0
  126. data/spec/sha512/shared/update.rb +7 -0
  127. data/spec/sha512/size_spec.rb +7 -0
  128. data/spec/sha512/to_s_spec.rb +20 -0
  129. data/spec/sha512/update_spec.rb +6 -0
  130. metadata +283 -88
  131. data/lib/rubysl-digest.rb +0 -7
@@ -1,22 +1,30 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/rubysl-digest/version', __FILE__)
1
+ # coding: utf-8
2
+ require './lib/rubysl/digest/version'
3
3
 
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["Brian Shirai"]
6
- gem.email = ["brixen@gmail.com"]
7
- gem.description = %q{Ruby Standard Library - digest}
8
- gem.summary = %q{Ruby Standard Library - digest}
9
- gem.homepage = ""
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
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "rubysl-digest"
15
- gem.require_paths = ["lib"]
16
- gem.version = RubySL::Digest::VERSION
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
- gem.add_runtime_dependency "redcard", "~> 1.0"
25
+ spec.add_runtime_dependency "redcard", "~> 1.0"
19
26
 
20
- gem.add_development_dependency "rake", "~> 10.0"
21
- gem.add_development_dependency "mspec", "~> 1.5"
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,6 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+ require File.expand_path('../shared/update', __FILE__)
3
+
4
+ describe "Digest::MD5#<<" do
5
+ it_behaves_like(:md5_update, :<<)
6
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::MD5#block_length" do
4
+
5
+ it "returns the length of digest block" do
6
+ cur_digest = Digest::MD5.new
7
+ cur_digest.block_length.should == MD5Constants::BlockLength
8
+ end
9
+
10
+ end
11
+
@@ -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,7 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+ require File.expand_path('../shared/length', __FILE__)
3
+
4
+ describe "Digest::MD5#length" do
5
+ it_behaves_like :md5_length, :length
6
+ end
7
+
@@ -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,7 @@
1
+ describe :md5_update, :shared => true do
2
+ it "can update" do
3
+ cur_digest = Digest::MD5.new
4
+ cur_digest.send @method, MD5Constants::Contents
5
+ cur_digest.digest.should == MD5Constants::Digest
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+ require File.expand_path('../shared/length', __FILE__)
3
+
4
+ describe "Digest::MD5#size" do
5
+ it_behaves_like :md5_length, :size
6
+ end
7
+
@@ -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,6 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+ require File.expand_path('../shared/update', __FILE__)
3
+
4
+ describe "Digest::MD5#update" do
5
+ it_behaves_like :md5_update, :update
6
+ 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,6 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+ require File.expand_path('../shared/update', __FILE__)
3
+
4
+ describe "Digest::SHA256#<<" do
5
+ it_behaves_like(:sha256_update, :<<)
6
+ 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