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
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA256#hexdigest!" do
4
+
5
+ it "returns a hexdigest and resets the state" do
6
+ cur_digest = Digest::SHA256.new
7
+
8
+ cur_digest << SHA256Constants::Contents
9
+ cur_digest.hexdigest!.should == SHA256Constants::Hexdigest
10
+ cur_digest.hexdigest.should == SHA256Constants::BlankHexdigest
11
+ end
12
+
13
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA256#hexdigest" do
4
+
5
+ it "returns a hexdigest" do
6
+ cur_digest = Digest::SHA256.new
7
+ cur_digest.hexdigest.should == SHA256Constants::BlankHexdigest
8
+
9
+ # add something to check that the state is reset later
10
+ cur_digest << "test"
11
+
12
+ cur_digest.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest
13
+ # second invocation is intentional, to make sure there are no side-effects
14
+ cur_digest.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest
15
+
16
+ # after all is done, verify that the digest is in the original, blank state
17
+ cur_digest.hexdigest.should == SHA256Constants::BlankHexdigest
18
+ end
19
+
20
+ end
21
+
22
+ describe "Digest::SHA256.hexdigest" do
23
+
24
+ it "returns a hexdigest" do
25
+ Digest::SHA256.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest
26
+ # second invocation is intentional, to make sure there are no side-effects
27
+ Digest::SHA256.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest
28
+ Digest::SHA256.hexdigest("").should == SHA256Constants::BlankHexdigest
29
+ end
30
+
31
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA256#inspect" do
4
+
5
+ it "returns a Ruby object representation" do
6
+ cur_digest = Digest::SHA256.new
7
+ cur_digest.inspect.should == "#<#{SHA256Constants::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::SHA256#length" do
5
+ it_behaves_like :sha256_length, :length
6
+ end
7
+
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA256#reset" do
4
+
5
+ it "returns digest state to initial conditions" do
6
+ cur_digest = Digest::SHA256.new
7
+ cur_digest.update SHA256Constants::Contents
8
+ cur_digest.digest().should_not == SHA256Constants::BlankDigest
9
+ cur_digest.reset
10
+ cur_digest.digest().should == SHA256Constants::BlankDigest
11
+ end
12
+
13
+ end
14
+
@@ -0,0 +1,16 @@
1
+ # -*- encoding: US-ASCII -*-
2
+ require 'digest/sha2'
3
+
4
+ module SHA256Constants
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::SHA256
9
+ BlockLength = 64
10
+ DigestLength = 32
11
+ BlankDigest = "\343\260\304B\230\374\034\024\232\373\364\310\231o\271$'\256A\344d\233\223L\244\225\231\exR\270U"
12
+ Digest = "\230b\265\344_\337\357\337\242\004\314\311A\211jb\350\373\254\370\365M\230B\002\372\020j\as\270\376"
13
+ BlankHexdigest = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
14
+ Hexdigest = "9862b5e45fdfefdfa204ccc941896a62e8fbacf8f54d984202fa106a0773b8fe"
15
+
16
+ end
@@ -0,0 +1,8 @@
1
+ describe :sha256_length, :shared => true do
2
+ it "returns the length of the digest" do
3
+ cur_digest = Digest::SHA256.new
4
+ cur_digest.send(@method).should == SHA256Constants::BlankDigest.size
5
+ cur_digest << SHA256Constants::Contents
6
+ cur_digest.send(@method).should == SHA256Constants::Digest.size
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ describe :sha256_update, :shared => true do
2
+ it "can update" do
3
+ cur_digest = Digest::SHA256.new
4
+ cur_digest.send @method, SHA256Constants::Contents
5
+ cur_digest.digest.should == SHA256Constants::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::SHA256#size" do
5
+ it_behaves_like :sha256_length, :size
6
+ end
7
+
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA256#to_s" do
4
+
5
+ it "returns a hexdigest" do
6
+ cur_digest = Digest::SHA256.new
7
+ cur_digest.to_s.should == SHA256Constants::BlankHexdigest
8
+ end
9
+
10
+ it "does not change the internal state" do
11
+ cur_digest = Digest::SHA256.new
12
+ cur_digest.to_s.should == SHA256Constants::BlankHexdigest
13
+ cur_digest.to_s.should == SHA256Constants::BlankHexdigest
14
+
15
+ cur_digest << SHA256Constants::Contents
16
+ cur_digest.to_s.should == SHA256Constants::Hexdigest
17
+ cur_digest.to_s.should == SHA256Constants::Hexdigest
18
+ end
19
+
20
+ 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#update" do
5
+ it_behaves_like :sha256_update, :update
6
+ 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::SHA384#<<" do
5
+ it_behaves_like(:sha384_update, :<<)
6
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA384#block_length" do
4
+
5
+ it "returns the length of digest block" do
6
+ cur_digest = Digest::SHA384.new
7
+ cur_digest.block_length.should == SHA384Constants::BlockLength
8
+ end
9
+
10
+ end
11
+
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA384#digest!" do
4
+
5
+ it "returns a digest and can digest!" do
6
+ cur_digest = Digest::SHA384.new
7
+ cur_digest << SHA384Constants::Contents
8
+ cur_digest.digest!().should == SHA384Constants::Digest
9
+ cur_digest.digest().should == SHA384Constants::BlankDigest
10
+ end
11
+
12
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA384#digest_length" do
4
+
5
+ it "returns the length of computed digests" do
6
+ cur_digest = Digest::SHA384.new
7
+ cur_digest.digest_length.should == SHA384Constants::DigestLength
8
+ end
9
+
10
+ end
11
+
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA384#digest" do
4
+
5
+ it "returns a digest" do
6
+ cur_digest = Digest::SHA384.new
7
+ cur_digest.digest().should == SHA384Constants::BlankDigest
8
+
9
+ # add something to check that the state is reset later
10
+ cur_digest << "test"
11
+
12
+ cur_digest.digest(SHA384Constants::Contents).should == SHA384Constants::Digest
13
+ # second invocation is intentional, to make sure there are no side-effects
14
+ cur_digest.digest(SHA384Constants::Contents).should == SHA384Constants::Digest
15
+
16
+ # after all is done, verify that the digest is in the original, blank state
17
+ cur_digest.digest.should == SHA384Constants::BlankDigest
18
+ end
19
+
20
+ end
21
+
22
+ describe "Digest::SHA384.digest" do
23
+
24
+ it "returns a digest" do
25
+ Digest::SHA384.digest(SHA384Constants::Contents).should == SHA384Constants::Digest
26
+ # second invocation is intentional, to make sure there are no side-effects
27
+ Digest::SHA384.digest(SHA384Constants::Contents).should == SHA384Constants::Digest
28
+ Digest::SHA384.digest("").should == SHA384Constants::BlankDigest
29
+ end
30
+
31
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA384#==" do
4
+
5
+ it "equals itself" do
6
+ cur_digest = Digest::SHA384.new
7
+ cur_digest.should == cur_digest
8
+ end
9
+
10
+ it "equals the string representing its hexdigest" do
11
+ cur_digest = Digest::SHA384.new
12
+ cur_digest.should == SHA384Constants::BlankHexdigest
13
+ end
14
+
15
+ it "equals the appropriate object that responds to to_str" do
16
+ # blank digest
17
+ cur_digest = Digest::SHA384.new
18
+ (obj = mock(SHA384Constants::BlankHexdigest)).should_receive(:to_str).and_return(SHA384Constants::BlankHexdigest)
19
+ cur_digest.should == obj
20
+
21
+ # non-blank digest
22
+ cur_digest = Digest::SHA384.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::SHA384.new
31
+ cur_digest2 = Digest::SHA384.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::SHA384.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 SHA384Constants::Contents }
10
+ end
11
+
12
+ after :each do
13
+ rm_r @file
14
+ end
15
+
16
+ it "returns a Digest::SHA384 object" do
17
+ Digest::SHA384.file(@file).should be_kind_of(Digest::SHA384)
18
+ end
19
+
20
+ it "returns a Digest::SHA384 object with the correct digest" do
21
+ Digest::SHA384.file(@file).digest.should == SHA384Constants::Digest
22
+ end
23
+
24
+ it "calls #to_str on an object and returns the Digest::SHA384 with the result" do
25
+ obj = mock("to_str")
26
+ obj.should_receive(:to_str).and_return(@file)
27
+ result = Digest::SHA384.file(obj)
28
+ result.should be_kind_of(Digest::SHA384)
29
+ result.digest.should == SHA384Constants::Digest
30
+ end
31
+ end
32
+
33
+ it_behaves_like :file_read_directory, :file, Digest::SHA384
34
+
35
+ it "raises a Errno::ENOENT when passed a path that does not exist" do
36
+ lambda { Digest::SHA384.file("") }.should raise_error(Errno::ENOENT)
37
+ end
38
+
39
+ it "raises a TypeError when passed nil" do
40
+ lambda { Digest::SHA384.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::SHA384#hexdigest!" do
4
+
5
+ it "returns a hexdigest and resets the state" do
6
+ cur_digest = Digest::SHA384.new
7
+
8
+ cur_digest << SHA384Constants::Contents
9
+ cur_digest.hexdigest!.should == SHA384Constants::Hexdigest
10
+ cur_digest.hexdigest.should == SHA384Constants::BlankHexdigest
11
+ end
12
+
13
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA384#hexdigest" do
4
+
5
+ it "returns a hexdigest" do
6
+ cur_digest = Digest::SHA384.new
7
+ cur_digest.hexdigest.should == SHA384Constants::BlankHexdigest
8
+
9
+ # add something to check that the state is reset later
10
+ cur_digest << "test"
11
+
12
+ cur_digest.hexdigest(SHA384Constants::Contents).should == SHA384Constants::Hexdigest
13
+ # second invocation is intentional, to make sure there are no side-effects
14
+ cur_digest.hexdigest(SHA384Constants::Contents).should == SHA384Constants::Hexdigest
15
+
16
+ # after all is done, verify that the digest is in the original, blank state
17
+ cur_digest.hexdigest.should == SHA384Constants::BlankHexdigest
18
+ end
19
+
20
+ end
21
+
22
+ describe "Digest::SHA384.hexdigest" do
23
+
24
+ it "returns a hexdigest" do
25
+ Digest::SHA384.hexdigest(SHA384Constants::Contents).should == SHA384Constants::Hexdigest
26
+ # second invocation is intentional, to make sure there are no side-effects
27
+ Digest::SHA384.hexdigest(SHA384Constants::Contents).should == SHA384Constants::Hexdigest
28
+ Digest::SHA384.hexdigest("").should == SHA384Constants::BlankHexdigest
29
+ end
30
+
31
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA384#inspect" do
4
+
5
+ it "returns a Ruby object representation" do
6
+ cur_digest = Digest::SHA384.new
7
+ cur_digest.inspect.should == "#<#{SHA384Constants::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::SHA384#length" do
5
+ it_behaves_like :sha384_length, :length
6
+ end
7
+
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA384#reset" do
4
+
5
+ it "returns digest state to initial conditions" do
6
+ cur_digest = Digest::SHA384.new
7
+ cur_digest.update SHA384Constants::Contents
8
+ cur_digest.digest().should_not == SHA384Constants::BlankDigest
9
+ cur_digest.reset
10
+ cur_digest.digest().should == SHA384Constants::BlankDigest
11
+ end
12
+
13
+ end
14
+
@@ -0,0 +1,17 @@
1
+ # -*- encoding: US-ASCII -*-
2
+ require 'digest/sha2'
3
+
4
+ module SHA384Constants
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
+
9
+ Klass = ::Digest::SHA384
10
+ BlockLength = 128
11
+ DigestLength = 48
12
+ BlankDigest = "8\260`\247Q\254\2268L\3312~\261\261\343j!\375\267\021\024\276\aCL\f\307\277c\366\341\332'N\336\277\347oe\373\325\032\322\361H\230\271["
13
+ Digest = "B&\266:\314\216z\361!TD\001{`\355\323\320MW%\270\272\0034n\034\026g\a\217\"\333s\202\275\002Y*\217]\207u\f\034\244\231\266f"
14
+ BlankHexdigest = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b"
15
+ Hexdigest = "4226b63acc8e7af1215444017b60edd3d04d5725b8ba03346e1c1667078f22db7382bd02592a8f5d87750c1ca499b666"
16
+
17
+ end
@@ -0,0 +1,8 @@
1
+ describe :sha384_length, :shared => true do
2
+ it "returns the length of the digest" do
3
+ cur_digest = Digest::SHA384.new
4
+ cur_digest.send(@method).should == SHA384Constants::BlankDigest.size
5
+ cur_digest << SHA384Constants::Contents
6
+ cur_digest.send(@method).should == SHA384Constants::Digest.size
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ describe :sha384_update, :shared => true do
2
+ it "can update" do
3
+ cur_digest = Digest::SHA384.new
4
+ cur_digest.send @method, SHA384Constants::Contents
5
+ cur_digest.digest.should == SHA384Constants::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::SHA384#size" do
5
+ it_behaves_like :sha384_length, :size
6
+ end
7
+
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA384#to_s" do
4
+
5
+ it "returns a hexdigest" do
6
+ cur_digest = Digest::SHA384.new
7
+ cur_digest.to_s.should == SHA384Constants::BlankHexdigest
8
+ end
9
+
10
+ it "does not change the internal state" do
11
+ cur_digest = Digest::SHA384.new
12
+ cur_digest.to_s.should == SHA384Constants::BlankHexdigest
13
+ cur_digest.to_s.should == SHA384Constants::BlankHexdigest
14
+
15
+ cur_digest << SHA384Constants::Contents
16
+ cur_digest.to_s.should == SHA384Constants::Hexdigest
17
+ cur_digest.to_s.should == SHA384Constants::Hexdigest
18
+ end
19
+
20
+ 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::SHA384#update" do
5
+ it_behaves_like :sha384_update, :update
6
+ 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::SHA512#<<" do
5
+ it_behaves_like(:sha512_update, :<<)
6
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA512#block_length" do
4
+
5
+ it "returns the length of digest block" do
6
+ cur_digest = Digest::SHA512.new
7
+ cur_digest.block_length.should == SHA512Constants::BlockLength
8
+ end
9
+
10
+ end
11
+
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA512#digest!" do
4
+
5
+ it "returns a digest and can digest!" do
6
+ cur_digest = Digest::SHA512.new
7
+ cur_digest << SHA512Constants::Contents
8
+ cur_digest.digest!().should == SHA512Constants::Digest
9
+ cur_digest.digest().should == SHA512Constants::BlankDigest
10
+ end
11
+
12
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA512#digest_length" do
4
+
5
+ it "returns the length of computed digests" do
6
+ cur_digest = Digest::SHA512.new
7
+ cur_digest.digest_length.should == SHA512Constants::DigestLength
8
+ end
9
+
10
+ end
11
+
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA512#digest" do
4
+
5
+ it "returns a digest" do
6
+ cur_digest = Digest::SHA512.new
7
+ cur_digest.digest().should == SHA512Constants::BlankDigest
8
+
9
+ # add something to check that the state is reset later
10
+ cur_digest << "test"
11
+
12
+ cur_digest.digest(SHA512Constants::Contents).should == SHA512Constants::Digest
13
+ # second invocation is intentional, to make sure there are no side-effects
14
+ cur_digest.digest(SHA512Constants::Contents).should == SHA512Constants::Digest
15
+
16
+ # after all is done, verify that the digest is in the original, blank state
17
+ cur_digest.digest.should == SHA512Constants::BlankDigest
18
+ end
19
+
20
+ end
21
+
22
+ describe "Digest::SHA512.digest" do
23
+
24
+ it "returns a digest" do
25
+ Digest::SHA512.digest(SHA512Constants::Contents).should == SHA512Constants::Digest
26
+ # second invocation is intentional, to make sure there are no side-effects
27
+ Digest::SHA512.digest(SHA512Constants::Contents).should == SHA512Constants::Digest
28
+ Digest::SHA512.digest("").should == SHA512Constants::BlankDigest
29
+ end
30
+
31
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../shared/constants', __FILE__)
2
+
3
+ describe "Digest::SHA512#==" do
4
+
5
+ it "equals itself" do
6
+ cur_digest = Digest::SHA512.new
7
+ cur_digest.should == cur_digest
8
+ end
9
+
10
+ it "equals the string representing its hexdigest" do
11
+ cur_digest = Digest::SHA512.new
12
+ cur_digest.should == SHA512Constants::BlankHexdigest
13
+ end
14
+
15
+ it "equals the appropriate object that responds to to_str" do
16
+ # blank digest
17
+ cur_digest = Digest::SHA512.new
18
+ (obj = mock(SHA512Constants::BlankHexdigest)).should_receive(:to_str).and_return(SHA512Constants::BlankHexdigest)
19
+ cur_digest.should == obj
20
+
21
+ # non-blank digest
22
+ cur_digest = Digest::SHA512.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::SHA512.new
31
+ cur_digest2 = Digest::SHA512.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::SHA512.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 SHA512Constants::Contents }
10
+ end
11
+
12
+ after :each do
13
+ rm_r @file
14
+ end
15
+
16
+ it "returns a Digest::SHA512 object" do
17
+ Digest::SHA512.file(@file).should be_kind_of(Digest::SHA512)
18
+ end
19
+
20
+ it "returns a Digest::SHA512 object with the correct digest" do
21
+ Digest::SHA512.file(@file).digest.should == SHA512Constants::Digest
22
+ end
23
+
24
+ it "calls #to_str on an object and returns the Digest::SHA512 with the result" do
25
+ obj = mock("to_str")
26
+ obj.should_receive(:to_str).and_return(@file)
27
+ result = Digest::SHA512.file(obj)
28
+ result.should be_kind_of(Digest::SHA512)
29
+ result.digest.should == SHA512Constants::Digest
30
+ end
31
+ end
32
+
33
+ it_behaves_like :file_read_directory, :file, Digest::SHA512
34
+
35
+ it "raises a Errno::ENOENT when passed a path that does not exist" do
36
+ lambda { Digest::SHA512.file("") }.should raise_error(Errno::ENOENT)
37
+ end
38
+
39
+ it "raises a TypeError when passed nil" do
40
+ lambda { Digest::SHA512.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::SHA512#hexdigest!" do
4
+
5
+ it "returns a hexdigest and resets the state" do
6
+ cur_digest = Digest::SHA512.new
7
+
8
+ cur_digest << SHA512Constants::Contents
9
+ cur_digest.hexdigest!.should == SHA512Constants::Hexdigest
10
+ cur_digest.hexdigest.should == SHA512Constants::BlankHexdigest
11
+ end
12
+
13
+ end