mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
75bfc6440d
commit
1d15d5f080
4370 changed files with 0 additions and 0 deletions
29
spec/ruby/library/digest/bubblebabble_spec.rb
Normal file
29
spec/ruby/library/digest/bubblebabble_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'digest/bubblebabble'
|
||||
|
||||
describe "Digest.bubblebabble" do
|
||||
it "returns a String" do
|
||||
Digest.bubblebabble('').should be_an_instance_of(String)
|
||||
end
|
||||
|
||||
it "returns a String in the The Bubble Babble Binary Data Encoding format" do
|
||||
Digest.bubblebabble('').should == 'xexax'
|
||||
Digest.bubblebabble('foo').should == 'xinik-zorox'
|
||||
Digest.bubblebabble('bar').should == 'ximik-cosex'
|
||||
Digest.bubblebabble('1234567890').should == 'xesef-disof-gytuf-katof-movif-baxux'
|
||||
end
|
||||
|
||||
it "calls #to_str on an object and returns the bubble babble value of the result" do
|
||||
obj = mock("to_str")
|
||||
obj.should_receive(:to_str).and_return('foo')
|
||||
Digest.bubblebabble(obj).should == 'xinik-zorox'
|
||||
end
|
||||
|
||||
it "raises a TypeError when passed nil" do
|
||||
lambda { Digest.bubblebabble(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "raises a TypeError when passed a Fixnum" do
|
||||
lambda { Digest.bubblebabble(9001) }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
31
spec/ruby/library/digest/hexencode_spec.rb
Normal file
31
spec/ruby/library/digest/hexencode_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'digest'
|
||||
|
||||
describe "Digest.hexencode" do
|
||||
before :each do
|
||||
@string = 'sample string'
|
||||
@encoded = "73616d706c6520737472696e67"
|
||||
end
|
||||
|
||||
it "returns '' when passed an empty String" do
|
||||
Digest.hexencode('').should == ''
|
||||
end
|
||||
|
||||
it "returns the hex-encoded value of a non-empty String" do
|
||||
Digest.hexencode(@string).should == @encoded
|
||||
end
|
||||
|
||||
it "calls #to_str on an object and returns the hex-encoded value of the result" do
|
||||
obj = mock("to_str")
|
||||
obj.should_receive(:to_str).and_return(@string)
|
||||
Digest.hexencode(obj).should == @encoded
|
||||
end
|
||||
|
||||
it "raises a TypeError when passed nil" do
|
||||
lambda { Digest.hexencode(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "raises a TypeError when passed a Fixnum" do
|
||||
lambda { Digest.hexencode(9001) }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
7
spec/ruby/library/digest/md5/append_spec.rb
Normal file
7
spec/ruby/library/digest/md5/append_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/update', __FILE__)
|
||||
|
||||
describe "Digest::MD5#<<" do
|
||||
it_behaves_like(:md5_update, :<<)
|
||||
end
|
12
spec/ruby/library/digest/md5/block_length_spec.rb
Normal file
12
spec/ruby/library/digest/md5/block_length_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::MD5#block_length" do
|
||||
|
||||
it "returns the length of digest block" do
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest.block_length.should == MD5Constants::BlockLength
|
||||
end
|
||||
|
||||
end
|
||||
|
13
spec/ruby/library/digest/md5/digest_bang_spec.rb
Normal file
13
spec/ruby/library/digest/md5/digest_bang_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::MD5#digest!" do
|
||||
|
||||
it "returns a digest and can digest!" do
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest << MD5Constants::Contents
|
||||
cur_digest.digest!().should == MD5Constants::Digest
|
||||
cur_digest.digest().should == MD5Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
12
spec/ruby/library/digest/md5/digest_length_spec.rb
Normal file
12
spec/ruby/library/digest/md5/digest_length_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::MD5#digest_length" do
|
||||
|
||||
it "returns the length of computed digests" do
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest.digest_length.should == MD5Constants::DigestLength
|
||||
end
|
||||
|
||||
end
|
||||
|
32
spec/ruby/library/digest/md5/digest_spec.rb
Normal file
32
spec/ruby/library/digest/md5/digest_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::MD5#digest" do
|
||||
|
||||
it "returns a digest" do
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest.digest().should == MD5Constants::BlankDigest
|
||||
|
||||
# add something to check that the state is reset later
|
||||
cur_digest << "test"
|
||||
|
||||
cur_digest.digest(MD5Constants::Contents).should == MD5Constants::Digest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
cur_digest.digest(MD5Constants::Contents).should == MD5Constants::Digest
|
||||
|
||||
# after all is done, verify that the digest is in the original, blank state
|
||||
cur_digest.digest.should == MD5Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "Digest::MD5.digest" do
|
||||
|
||||
it "returns a digest" do
|
||||
Digest::MD5.digest(MD5Constants::Contents).should == MD5Constants::Digest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
Digest::MD5.digest(MD5Constants::Contents).should == MD5Constants::Digest
|
||||
Digest::MD5.digest("").should == MD5Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
38
spec/ruby/library/digest/md5/equal_spec.rb
Normal file
38
spec/ruby/library/digest/md5/equal_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::MD5#==" do
|
||||
|
||||
it "equals itself" do
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest.should == cur_digest
|
||||
end
|
||||
|
||||
it "equals the string representing its hexdigest" do
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest.should == MD5Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
it "equals the appropriate object that responds to to_str" do
|
||||
# blank digest
|
||||
cur_digest = Digest::MD5.new
|
||||
obj = mock(MD5Constants::BlankHexdigest)
|
||||
obj.should_receive(:to_str).and_return(MD5Constants::BlankHexdigest)
|
||||
cur_digest.should == obj
|
||||
|
||||
# non-blank digest
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest << "test"
|
||||
d_value = cur_digest.hexdigest
|
||||
(obj = mock(d_value)).should_receive(:to_str).and_return(d_value)
|
||||
cur_digest.should == obj
|
||||
end
|
||||
|
||||
it "equals the same digest for a different object" do
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest2 = Digest::MD5.new
|
||||
cur_digest.should == cur_digest2
|
||||
end
|
||||
|
||||
end
|
||||
|
43
spec/ruby/library/digest/md5/file_spec.rb
Normal file
43
spec/ruby/library/digest/md5/file_spec.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../../../../core/file/shared/read', __FILE__)
|
||||
|
||||
describe "Digest::MD5.file" do
|
||||
|
||||
describe "when passed a path to a file that exists" do
|
||||
before :each do
|
||||
@file = tmp("md5_temp")
|
||||
touch(@file, 'wb') {|f| f.write MD5Constants::Contents }
|
||||
end
|
||||
|
||||
after :each do
|
||||
rm_r @file
|
||||
end
|
||||
|
||||
it "returns a Digest::MD5 object" do
|
||||
Digest::MD5.file(@file).should be_kind_of(Digest::MD5)
|
||||
end
|
||||
|
||||
it "returns a Digest::MD5 object with the correct digest" do
|
||||
Digest::MD5.file(@file).digest.should == MD5Constants::Digest
|
||||
end
|
||||
|
||||
it "calls #to_str on an object and returns the Digest::MD5 with the result" do
|
||||
obj = mock("to_str")
|
||||
obj.should_receive(:to_str).and_return(@file)
|
||||
result = Digest::MD5.file(obj)
|
||||
result.should be_kind_of(Digest::MD5)
|
||||
result.digest.should == MD5Constants::Digest
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like :file_read_directory, :file, Digest::MD5
|
||||
|
||||
it "raises a Errno::ENOENT when passed a path that does not exist" do
|
||||
lambda { Digest::MD5.file("") }.should raise_error(Errno::ENOENT)
|
||||
end
|
||||
|
||||
it "raises a TypeError when passed nil" do
|
||||
lambda { Digest::MD5.file(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
14
spec/ruby/library/digest/md5/hexdigest_bang_spec.rb
Normal file
14
spec/ruby/library/digest/md5/hexdigest_bang_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::MD5#hexdigest!" do
|
||||
|
||||
it "returns a hexdigest and resets the state" do
|
||||
cur_digest = Digest::MD5.new
|
||||
|
||||
cur_digest << MD5Constants::Contents
|
||||
cur_digest.hexdigest!.should == MD5Constants::Hexdigest
|
||||
cur_digest.hexdigest.should == MD5Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
end
|
32
spec/ruby/library/digest/md5/hexdigest_spec.rb
Normal file
32
spec/ruby/library/digest/md5/hexdigest_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::MD5#hexdigest" do
|
||||
|
||||
it "returns a hexdigest" do
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest.hexdigest.should == MD5Constants::BlankHexdigest
|
||||
|
||||
# add something to check that the state is reset later
|
||||
cur_digest << "test"
|
||||
|
||||
cur_digest.hexdigest(MD5Constants::Contents).should == MD5Constants::Hexdigest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
cur_digest.hexdigest(MD5Constants::Contents).should == MD5Constants::Hexdigest
|
||||
|
||||
# after all is done, verify that the digest is in the original, blank state
|
||||
cur_digest.hexdigest.should == MD5Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "Digest::MD5.hexdigest" do
|
||||
|
||||
it "returns a hexdigest" do
|
||||
Digest::MD5.hexdigest(MD5Constants::Contents).should == MD5Constants::Hexdigest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
Digest::MD5.hexdigest(MD5Constants::Contents).should == MD5Constants::Hexdigest
|
||||
Digest::MD5.hexdigest("").should == MD5Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
end
|
12
spec/ruby/library/digest/md5/inspect_spec.rb
Normal file
12
spec/ruby/library/digest/md5/inspect_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::MD5#inspect" do
|
||||
|
||||
it "returns a Ruby object representation" do
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest.inspect.should == "#<#{MD5Constants::Klass}: #{cur_digest.hexdigest()}>"
|
||||
end
|
||||
|
||||
end
|
||||
|
8
spec/ruby/library/digest/md5/length_spec.rb
Normal file
8
spec/ruby/library/digest/md5/length_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/length', __FILE__)
|
||||
|
||||
describe "Digest::MD5#length" do
|
||||
it_behaves_like :md5_length, :length
|
||||
end
|
||||
|
15
spec/ruby/library/digest/md5/reset_spec.rb
Normal file
15
spec/ruby/library/digest/md5/reset_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::MD5#reset" do
|
||||
|
||||
it "returns digest state to initial conditions" do
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest.update MD5Constants::Contents
|
||||
cur_digest.digest().should_not == MD5Constants::BlankDigest
|
||||
cur_digest.reset
|
||||
cur_digest.digest().should == MD5Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
||||
|
16
spec/ruby/library/digest/md5/shared/constants.rb
Normal file
16
spec/ruby/library/digest/md5/shared/constants.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# -*- encoding: binary -*-
|
||||
require 'digest/md5'
|
||||
|
||||
module MD5Constants
|
||||
|
||||
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."
|
||||
|
||||
Klass = ::Digest::MD5
|
||||
BlockLength = 64
|
||||
DigestLength = 16
|
||||
BlankDigest = "\324\035\214\331\217\000\262\004\351\200\t\230\354\370B~"
|
||||
Digest = "\2473\267qw\276\364\343\345\320\304\350\313\314\217n"
|
||||
BlankHexdigest = "d41d8cd98f00b204e9800998ecf8427e"
|
||||
Hexdigest = "a733b77177bef4e3e5d0c4e8cbcc8f6e"
|
||||
|
||||
end
|
8
spec/ruby/library/digest/md5/shared/length.rb
Normal file
8
spec/ruby/library/digest/md5/shared/length.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
describe :md5_length, shared: true do
|
||||
it "returns the length of the digest" do
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest.send(@method).should == MD5Constants::BlankDigest.size
|
||||
cur_digest << MD5Constants::Contents
|
||||
cur_digest.send(@method).should == MD5Constants::Digest.size
|
||||
end
|
||||
end
|
17
spec/ruby/library/digest/md5/shared/sample.rb
Normal file
17
spec/ruby/library/digest/md5/shared/sample.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# -*- encoding: binary -*-
|
||||
|
||||
require 'digest/md5'
|
||||
|
||||
module MD5Constants
|
||||
|
||||
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."
|
||||
|
||||
Klass = ::Digest::MD5
|
||||
BlockLength = 64
|
||||
DigestLength = 16
|
||||
BlankDigest = "\324\035\214\331\217\000\262\004\351\200\t\230\354\370B~"
|
||||
Digest = "\2473\267qw\276\364\343\345\320\304\350\313\314\217n"
|
||||
BlankHexdigest = "d41d8cd98f00b204e9800998ecf8427e"
|
||||
Hexdigest = "a733b77177bef4e3e5d0c4e8cbcc8f6e"
|
||||
|
||||
end
|
7
spec/ruby/library/digest/md5/shared/update.rb
Normal file
7
spec/ruby/library/digest/md5/shared/update.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
describe :md5_update, shared: true do
|
||||
it "can update" do
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest.send @method, MD5Constants::Contents
|
||||
cur_digest.digest.should == MD5Constants::Digest
|
||||
end
|
||||
end
|
8
spec/ruby/library/digest/md5/size_spec.rb
Normal file
8
spec/ruby/library/digest/md5/size_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/length', __FILE__)
|
||||
|
||||
describe "Digest::MD5#size" do
|
||||
it_behaves_like :md5_length, :size
|
||||
end
|
||||
|
24
spec/ruby/library/digest/md5/to_s_spec.rb
Normal file
24
spec/ruby/library/digest/md5/to_s_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
|
||||
require 'digest/md5'
|
||||
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::MD5#to_s" do
|
||||
|
||||
it "returns a hexdigest" do
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest.to_s.should == MD5Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
it "does not change the internal state" do
|
||||
cur_digest = Digest::MD5.new
|
||||
cur_digest.to_s.should == MD5Constants::BlankHexdigest
|
||||
cur_digest.to_s.should == MD5Constants::BlankHexdigest
|
||||
|
||||
cur_digest << MD5Constants::Contents
|
||||
cur_digest.to_s.should == MD5Constants::Hexdigest
|
||||
cur_digest.to_s.should == MD5Constants::Hexdigest
|
||||
end
|
||||
|
||||
end
|
7
spec/ruby/library/digest/md5/update_spec.rb
Normal file
7
spec/ruby/library/digest/md5/update_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/update', __FILE__)
|
||||
|
||||
describe "Digest::MD5#update" do
|
||||
it_behaves_like :md5_update, :update
|
||||
end
|
20
spec/ruby/library/digest/sha1/digest_spec.rb
Normal file
20
spec/ruby/library/digest/sha1/digest_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA1#digest" do
|
||||
|
||||
it "returns a digest" do
|
||||
cur_digest = Digest::SHA1.new
|
||||
cur_digest.digest().should == SHA1Constants::BlankDigest
|
||||
cur_digest.digest(SHA1Constants::Contents).should == SHA1Constants::Digest
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "Digest::SHA1.digest" do
|
||||
|
||||
it "returns a digest" do
|
||||
Digest::SHA1.digest(SHA1Constants::Contents).should == SHA1Constants::Digest
|
||||
end
|
||||
|
||||
end
|
43
spec/ruby/library/digest/sha1/file_spec.rb
Normal file
43
spec/ruby/library/digest/sha1/file_spec.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../../../../core/file/shared/read', __FILE__)
|
||||
|
||||
describe "Digest::SHA1.file" do
|
||||
|
||||
describe "when passed a path to a file that exists" do
|
||||
before :each do
|
||||
@file = tmp("md5_temp")
|
||||
touch(@file, 'wb') {|f| f.write SHA1Constants::Contents }
|
||||
end
|
||||
|
||||
after :each do
|
||||
rm_r @file
|
||||
end
|
||||
|
||||
it "returns a Digest::SHA1 object" do
|
||||
Digest::SHA1.file(@file).should be_kind_of(Digest::SHA1)
|
||||
end
|
||||
|
||||
it "returns a Digest::SHA1 object with the correct digest" do
|
||||
Digest::SHA1.file(@file).digest.should == SHA1Constants::Digest
|
||||
end
|
||||
|
||||
it "calls #to_str on an object and returns the Digest::SHA1 with the result" do
|
||||
obj = mock("to_str")
|
||||
obj.should_receive(:to_str).and_return(@file)
|
||||
result = Digest::SHA1.file(obj)
|
||||
result.should be_kind_of(Digest::SHA1)
|
||||
result.digest.should == SHA1Constants::Digest
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like :file_read_directory, :file, Digest::SHA1
|
||||
|
||||
it "raises a Errno::ENOENT when passed a path that does not exist" do
|
||||
lambda { Digest::SHA1.file("") }.should raise_error(Errno::ENOENT)
|
||||
end
|
||||
|
||||
it "raises a TypeError when passed nil" do
|
||||
lambda { Digest::SHA1.file(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
17
spec/ruby/library/digest/sha1/shared/constants.rb
Normal file
17
spec/ruby/library/digest/sha1/shared/constants.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# -*- encoding: binary -*-
|
||||
|
||||
require 'digest/sha1'
|
||||
|
||||
module SHA1Constants
|
||||
|
||||
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."
|
||||
|
||||
Klass = ::Digest::SHA1
|
||||
BlockLength = 64
|
||||
DigestLength = 20
|
||||
BlankDigest = "\3329\243\356^kK\r2U\277\357\225`\030\220\257\330\a\t"
|
||||
Digest = "X!\255b\323\035\352\314a|q\344+\376\317\361V9\324\343"
|
||||
BlankHexdigest = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
||||
Hexdigest = "e907d2ba21c6c74bc0efd76e44d11fb9bbb7a75e"
|
||||
|
||||
end
|
7
spec/ruby/library/digest/sha256/append_spec.rb
Normal file
7
spec/ruby/library/digest/sha256/append_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/update', __FILE__)
|
||||
|
||||
describe "Digest::SHA256#<<" do
|
||||
it_behaves_like(:sha256_update, :<<)
|
||||
end
|
12
spec/ruby/library/digest/sha256/block_length_spec.rb
Normal file
12
spec/ruby/library/digest/sha256/block_length_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA256#block_length" do
|
||||
|
||||
it "returns the length of digest block" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest.block_length.should == SHA256Constants::BlockLength
|
||||
end
|
||||
|
||||
end
|
||||
|
13
spec/ruby/library/digest/sha256/digest_bang_spec.rb
Normal file
13
spec/ruby/library/digest/sha256/digest_bang_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA256#digest!" do
|
||||
|
||||
it "returns a digest and can digest!" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest << SHA256Constants::Contents
|
||||
cur_digest.digest!().should == SHA256Constants::Digest
|
||||
cur_digest.digest().should == SHA256Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
12
spec/ruby/library/digest/sha256/digest_length_spec.rb
Normal file
12
spec/ruby/library/digest/sha256/digest_length_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA256#digest_length" do
|
||||
|
||||
it "returns the length of computed digests" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest.digest_length.should == SHA256Constants::DigestLength
|
||||
end
|
||||
|
||||
end
|
||||
|
32
spec/ruby/library/digest/sha256/digest_spec.rb
Normal file
32
spec/ruby/library/digest/sha256/digest_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA256#digest" do
|
||||
|
||||
it "returns a digest" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest.digest().should == SHA256Constants::BlankDigest
|
||||
|
||||
# add something to check that the state is reset later
|
||||
cur_digest << "test"
|
||||
|
||||
cur_digest.digest(SHA256Constants::Contents).should == SHA256Constants::Digest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
cur_digest.digest(SHA256Constants::Contents).should == SHA256Constants::Digest
|
||||
|
||||
# after all is done, verify that the digest is in the original, blank state
|
||||
cur_digest.digest.should == SHA256Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "Digest::SHA256.digest" do
|
||||
|
||||
it "returns a digest" do
|
||||
Digest::SHA256.digest(SHA256Constants::Contents).should == SHA256Constants::Digest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
Digest::SHA256.digest(SHA256Constants::Contents).should == SHA256Constants::Digest
|
||||
Digest::SHA256.digest("").should == SHA256Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
37
spec/ruby/library/digest/sha256/equal_spec.rb
Normal file
37
spec/ruby/library/digest/sha256/equal_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA256#==" do
|
||||
|
||||
it "equals itself" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest.should == cur_digest
|
||||
end
|
||||
|
||||
it "equals the string representing its hexdigest" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest.should == SHA256Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
it "equals the appropriate object that responds to to_str" do
|
||||
# blank digest
|
||||
cur_digest = Digest::SHA256.new
|
||||
(obj = mock(SHA256Constants::BlankHexdigest)).should_receive(:to_str).and_return(SHA256Constants::BlankHexdigest)
|
||||
cur_digest.should == obj
|
||||
|
||||
# non-blank digest
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest << "test"
|
||||
d_value = cur_digest.hexdigest
|
||||
(obj = mock(d_value)).should_receive(:to_str).and_return(d_value)
|
||||
cur_digest.should == obj
|
||||
end
|
||||
|
||||
it "equals the same digest for a different object" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest2 = Digest::SHA256.new
|
||||
cur_digest.should == cur_digest2
|
||||
end
|
||||
|
||||
end
|
||||
|
43
spec/ruby/library/digest/sha256/file_spec.rb
Normal file
43
spec/ruby/library/digest/sha256/file_spec.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../../../../core/file/shared/read', __FILE__)
|
||||
|
||||
describe "Digest::SHA256.file" do
|
||||
|
||||
describe "when passed a path to a file that exists" do
|
||||
before :each do
|
||||
@file = tmp("md5_temp")
|
||||
touch(@file, 'wb') {|f| f.write SHA256Constants::Contents }
|
||||
end
|
||||
|
||||
after :each do
|
||||
rm_r @file
|
||||
end
|
||||
|
||||
it "returns a Digest::SHA256 object" do
|
||||
Digest::SHA256.file(@file).should be_kind_of(Digest::SHA256)
|
||||
end
|
||||
|
||||
it "returns a Digest::SHA256 object with the correct digest" do
|
||||
Digest::SHA256.file(@file).digest.should == SHA256Constants::Digest
|
||||
end
|
||||
|
||||
it "calls #to_str on an object and returns the Digest::SHA256 with the result" do
|
||||
obj = mock("to_str")
|
||||
obj.should_receive(:to_str).and_return(@file)
|
||||
result = Digest::SHA256.file(obj)
|
||||
result.should be_kind_of(Digest::SHA256)
|
||||
result.digest.should == SHA256Constants::Digest
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like :file_read_directory, :file, Digest::SHA256
|
||||
|
||||
it "raises a Errno::ENOENT when passed a path that does not exist" do
|
||||
lambda { Digest::SHA256.file("") }.should raise_error(Errno::ENOENT)
|
||||
end
|
||||
|
||||
it "raises a TypeError when passed nil" do
|
||||
lambda { Digest::SHA256.file(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
14
spec/ruby/library/digest/sha256/hexdigest_bang_spec.rb
Normal file
14
spec/ruby/library/digest/sha256/hexdigest_bang_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA256#hexdigest!" do
|
||||
|
||||
it "returns a hexdigest and resets the state" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
|
||||
cur_digest << SHA256Constants::Contents
|
||||
cur_digest.hexdigest!.should == SHA256Constants::Hexdigest
|
||||
cur_digest.hexdigest.should == SHA256Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
end
|
32
spec/ruby/library/digest/sha256/hexdigest_spec.rb
Normal file
32
spec/ruby/library/digest/sha256/hexdigest_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA256#hexdigest" do
|
||||
|
||||
it "returns a hexdigest" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest.hexdigest.should == SHA256Constants::BlankHexdigest
|
||||
|
||||
# add something to check that the state is reset later
|
||||
cur_digest << "test"
|
||||
|
||||
cur_digest.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
cur_digest.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest
|
||||
|
||||
# after all is done, verify that the digest is in the original, blank state
|
||||
cur_digest.hexdigest.should == SHA256Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "Digest::SHA256.hexdigest" do
|
||||
|
||||
it "returns a hexdigest" do
|
||||
Digest::SHA256.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
Digest::SHA256.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest
|
||||
Digest::SHA256.hexdigest("").should == SHA256Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
end
|
12
spec/ruby/library/digest/sha256/inspect_spec.rb
Normal file
12
spec/ruby/library/digest/sha256/inspect_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA256#inspect" do
|
||||
|
||||
it "returns a Ruby object representation" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest.inspect.should == "#<#{SHA256Constants::Klass}: #{cur_digest.hexdigest()}>"
|
||||
end
|
||||
|
||||
end
|
||||
|
8
spec/ruby/library/digest/sha256/length_spec.rb
Normal file
8
spec/ruby/library/digest/sha256/length_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/length', __FILE__)
|
||||
|
||||
describe "Digest::SHA256#length" do
|
||||
it_behaves_like :sha256_length, :length
|
||||
end
|
||||
|
15
spec/ruby/library/digest/sha256/reset_spec.rb
Normal file
15
spec/ruby/library/digest/sha256/reset_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA256#reset" do
|
||||
|
||||
it "returns digest state to initial conditions" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest.update SHA256Constants::Contents
|
||||
cur_digest.digest().should_not == SHA256Constants::BlankDigest
|
||||
cur_digest.reset
|
||||
cur_digest.digest().should == SHA256Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
||||
|
17
spec/ruby/library/digest/sha256/shared/constants.rb
Normal file
17
spec/ruby/library/digest/sha256/shared/constants.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# -*- encoding: binary -*-
|
||||
|
||||
require 'digest/sha2'
|
||||
|
||||
module SHA256Constants
|
||||
|
||||
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."
|
||||
|
||||
Klass = ::Digest::SHA256
|
||||
BlockLength = 64
|
||||
DigestLength = 32
|
||||
BlankDigest = "\343\260\304B\230\374\034\024\232\373\364\310\231o\271$'\256A\344d\233\223L\244\225\231\exR\270U"
|
||||
Digest = "\230b\265\344_\337\357\337\242\004\314\311A\211jb\350\373\254\370\365M\230B\002\372\020j\as\270\376"
|
||||
BlankHexdigest = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
Hexdigest = "9862b5e45fdfefdfa204ccc941896a62e8fbacf8f54d984202fa106a0773b8fe"
|
||||
|
||||
end
|
8
spec/ruby/library/digest/sha256/shared/length.rb
Normal file
8
spec/ruby/library/digest/sha256/shared/length.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
describe :sha256_length, shared: true do
|
||||
it "returns the length of the digest" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest.send(@method).should == SHA256Constants::BlankDigest.size
|
||||
cur_digest << SHA256Constants::Contents
|
||||
cur_digest.send(@method).should == SHA256Constants::Digest.size
|
||||
end
|
||||
end
|
7
spec/ruby/library/digest/sha256/shared/update.rb
Normal file
7
spec/ruby/library/digest/sha256/shared/update.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
describe :sha256_update, shared: true do
|
||||
it "can update" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest.send @method, SHA256Constants::Contents
|
||||
cur_digest.digest.should == SHA256Constants::Digest
|
||||
end
|
||||
end
|
8
spec/ruby/library/digest/sha256/size_spec.rb
Normal file
8
spec/ruby/library/digest/sha256/size_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/length', __FILE__)
|
||||
|
||||
describe "Digest::SHA256#size" do
|
||||
it_behaves_like :sha256_length, :size
|
||||
end
|
||||
|
21
spec/ruby/library/digest/sha256/to_s_spec.rb
Normal file
21
spec/ruby/library/digest/sha256/to_s_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA256#to_s" do
|
||||
|
||||
it "returns a hexdigest" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest.to_s.should == SHA256Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
it "does not change the internal state" do
|
||||
cur_digest = Digest::SHA256.new
|
||||
cur_digest.to_s.should == SHA256Constants::BlankHexdigest
|
||||
cur_digest.to_s.should == SHA256Constants::BlankHexdigest
|
||||
|
||||
cur_digest << SHA256Constants::Contents
|
||||
cur_digest.to_s.should == SHA256Constants::Hexdigest
|
||||
cur_digest.to_s.should == SHA256Constants::Hexdigest
|
||||
end
|
||||
|
||||
end
|
7
spec/ruby/library/digest/sha256/update_spec.rb
Normal file
7
spec/ruby/library/digest/sha256/update_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/update', __FILE__)
|
||||
|
||||
describe "Digest::SHA256#update" do
|
||||
it_behaves_like :sha256_update, :update
|
||||
end
|
7
spec/ruby/library/digest/sha384/append_spec.rb
Normal file
7
spec/ruby/library/digest/sha384/append_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/update', __FILE__)
|
||||
|
||||
describe "Digest::SHA384#<<" do
|
||||
it_behaves_like(:sha384_update, :<<)
|
||||
end
|
12
spec/ruby/library/digest/sha384/block_length_spec.rb
Normal file
12
spec/ruby/library/digest/sha384/block_length_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA384#block_length" do
|
||||
|
||||
it "returns the length of digest block" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest.block_length.should == SHA384Constants::BlockLength
|
||||
end
|
||||
|
||||
end
|
||||
|
13
spec/ruby/library/digest/sha384/digest_bang_spec.rb
Normal file
13
spec/ruby/library/digest/sha384/digest_bang_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA384#digest!" do
|
||||
|
||||
it "returns a digest and can digest!" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest << SHA384Constants::Contents
|
||||
cur_digest.digest!().should == SHA384Constants::Digest
|
||||
cur_digest.digest().should == SHA384Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
12
spec/ruby/library/digest/sha384/digest_length_spec.rb
Normal file
12
spec/ruby/library/digest/sha384/digest_length_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA384#digest_length" do
|
||||
|
||||
it "returns the length of computed digests" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest.digest_length.should == SHA384Constants::DigestLength
|
||||
end
|
||||
|
||||
end
|
||||
|
32
spec/ruby/library/digest/sha384/digest_spec.rb
Normal file
32
spec/ruby/library/digest/sha384/digest_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA384#digest" do
|
||||
|
||||
it "returns a digest" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest.digest().should == SHA384Constants::BlankDigest
|
||||
|
||||
# add something to check that the state is reset later
|
||||
cur_digest << "test"
|
||||
|
||||
cur_digest.digest(SHA384Constants::Contents).should == SHA384Constants::Digest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
cur_digest.digest(SHA384Constants::Contents).should == SHA384Constants::Digest
|
||||
|
||||
# after all is done, verify that the digest is in the original, blank state
|
||||
cur_digest.digest.should == SHA384Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "Digest::SHA384.digest" do
|
||||
|
||||
it "returns a digest" do
|
||||
Digest::SHA384.digest(SHA384Constants::Contents).should == SHA384Constants::Digest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
Digest::SHA384.digest(SHA384Constants::Contents).should == SHA384Constants::Digest
|
||||
Digest::SHA384.digest("").should == SHA384Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
37
spec/ruby/library/digest/sha384/equal_spec.rb
Normal file
37
spec/ruby/library/digest/sha384/equal_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA384#==" do
|
||||
|
||||
it "equals itself" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest.should == cur_digest
|
||||
end
|
||||
|
||||
it "equals the string representing its hexdigest" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest.should == SHA384Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
it "equals the appropriate object that responds to to_str" do
|
||||
# blank digest
|
||||
cur_digest = Digest::SHA384.new
|
||||
(obj = mock(SHA384Constants::BlankHexdigest)).should_receive(:to_str).and_return(SHA384Constants::BlankHexdigest)
|
||||
cur_digest.should == obj
|
||||
|
||||
# non-blank digest
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest << "test"
|
||||
d_value = cur_digest.hexdigest
|
||||
(obj = mock(d_value)).should_receive(:to_str).and_return(d_value)
|
||||
cur_digest.should == obj
|
||||
end
|
||||
|
||||
it "equals the same digest for a different object" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest2 = Digest::SHA384.new
|
||||
cur_digest.should == cur_digest2
|
||||
end
|
||||
|
||||
end
|
||||
|
43
spec/ruby/library/digest/sha384/file_spec.rb
Normal file
43
spec/ruby/library/digest/sha384/file_spec.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../../../../core/file/shared/read', __FILE__)
|
||||
|
||||
describe "Digest::SHA384.file" do
|
||||
|
||||
describe "when passed a path to a file that exists" do
|
||||
before :each do
|
||||
@file = tmp("md5_temp")
|
||||
touch(@file, 'wb') {|f| f.write SHA384Constants::Contents }
|
||||
end
|
||||
|
||||
after :each do
|
||||
rm_r @file
|
||||
end
|
||||
|
||||
it "returns a Digest::SHA384 object" do
|
||||
Digest::SHA384.file(@file).should be_kind_of(Digest::SHA384)
|
||||
end
|
||||
|
||||
it "returns a Digest::SHA384 object with the correct digest" do
|
||||
Digest::SHA384.file(@file).digest.should == SHA384Constants::Digest
|
||||
end
|
||||
|
||||
it "calls #to_str on an object and returns the Digest::SHA384 with the result" do
|
||||
obj = mock("to_str")
|
||||
obj.should_receive(:to_str).and_return(@file)
|
||||
result = Digest::SHA384.file(obj)
|
||||
result.should be_kind_of(Digest::SHA384)
|
||||
result.digest.should == SHA384Constants::Digest
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like :file_read_directory, :file, Digest::SHA384
|
||||
|
||||
it "raises a Errno::ENOENT when passed a path that does not exist" do
|
||||
lambda { Digest::SHA384.file("") }.should raise_error(Errno::ENOENT)
|
||||
end
|
||||
|
||||
it "raises a TypeError when passed nil" do
|
||||
lambda { Digest::SHA384.file(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
14
spec/ruby/library/digest/sha384/hexdigest_bang_spec.rb
Normal file
14
spec/ruby/library/digest/sha384/hexdigest_bang_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA384#hexdigest!" do
|
||||
|
||||
it "returns a hexdigest and resets the state" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
|
||||
cur_digest << SHA384Constants::Contents
|
||||
cur_digest.hexdigest!.should == SHA384Constants::Hexdigest
|
||||
cur_digest.hexdigest.should == SHA384Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
end
|
32
spec/ruby/library/digest/sha384/hexdigest_spec.rb
Normal file
32
spec/ruby/library/digest/sha384/hexdigest_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA384#hexdigest" do
|
||||
|
||||
it "returns a hexdigest" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest.hexdigest.should == SHA384Constants::BlankHexdigest
|
||||
|
||||
# add something to check that the state is reset later
|
||||
cur_digest << "test"
|
||||
|
||||
cur_digest.hexdigest(SHA384Constants::Contents).should == SHA384Constants::Hexdigest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
cur_digest.hexdigest(SHA384Constants::Contents).should == SHA384Constants::Hexdigest
|
||||
|
||||
# after all is done, verify that the digest is in the original, blank state
|
||||
cur_digest.hexdigest.should == SHA384Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "Digest::SHA384.hexdigest" do
|
||||
|
||||
it "returns a hexdigest" do
|
||||
Digest::SHA384.hexdigest(SHA384Constants::Contents).should == SHA384Constants::Hexdigest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
Digest::SHA384.hexdigest(SHA384Constants::Contents).should == SHA384Constants::Hexdigest
|
||||
Digest::SHA384.hexdigest("").should == SHA384Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
end
|
12
spec/ruby/library/digest/sha384/inspect_spec.rb
Normal file
12
spec/ruby/library/digest/sha384/inspect_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA384#inspect" do
|
||||
|
||||
it "returns a Ruby object representation" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest.inspect.should == "#<#{SHA384Constants::Klass}: #{cur_digest.hexdigest()}>"
|
||||
end
|
||||
|
||||
end
|
||||
|
8
spec/ruby/library/digest/sha384/length_spec.rb
Normal file
8
spec/ruby/library/digest/sha384/length_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/length', __FILE__)
|
||||
|
||||
describe "Digest::SHA384#length" do
|
||||
it_behaves_like :sha384_length, :length
|
||||
end
|
||||
|
15
spec/ruby/library/digest/sha384/reset_spec.rb
Normal file
15
spec/ruby/library/digest/sha384/reset_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA384#reset" do
|
||||
|
||||
it "returns digest state to initial conditions" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest.update SHA384Constants::Contents
|
||||
cur_digest.digest().should_not == SHA384Constants::BlankDigest
|
||||
cur_digest.reset
|
||||
cur_digest.digest().should == SHA384Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
||||
|
18
spec/ruby/library/digest/sha384/shared/constants.rb
Normal file
18
spec/ruby/library/digest/sha384/shared/constants.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# -*- encoding: binary -*-
|
||||
|
||||
require 'digest/sha2'
|
||||
|
||||
module SHA384Constants
|
||||
|
||||
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."
|
||||
|
||||
|
||||
Klass = ::Digest::SHA384
|
||||
BlockLength = 128
|
||||
DigestLength = 48
|
||||
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["
|
||||
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"
|
||||
BlankHexdigest = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b"
|
||||
Hexdigest = "4226b63acc8e7af1215444017b60edd3d04d5725b8ba03346e1c1667078f22db7382bd02592a8f5d87750c1ca499b666"
|
||||
|
||||
end
|
8
spec/ruby/library/digest/sha384/shared/length.rb
Normal file
8
spec/ruby/library/digest/sha384/shared/length.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
describe :sha384_length, shared: true do
|
||||
it "returns the length of the digest" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest.send(@method).should == SHA384Constants::BlankDigest.size
|
||||
cur_digest << SHA384Constants::Contents
|
||||
cur_digest.send(@method).should == SHA384Constants::Digest.size
|
||||
end
|
||||
end
|
7
spec/ruby/library/digest/sha384/shared/update.rb
Normal file
7
spec/ruby/library/digest/sha384/shared/update.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
describe :sha384_update, shared: true do
|
||||
it "can update" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest.send @method, SHA384Constants::Contents
|
||||
cur_digest.digest.should == SHA384Constants::Digest
|
||||
end
|
||||
end
|
8
spec/ruby/library/digest/sha384/size_spec.rb
Normal file
8
spec/ruby/library/digest/sha384/size_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/length', __FILE__)
|
||||
|
||||
describe "Digest::SHA384#size" do
|
||||
it_behaves_like :sha384_length, :size
|
||||
end
|
||||
|
21
spec/ruby/library/digest/sha384/to_s_spec.rb
Normal file
21
spec/ruby/library/digest/sha384/to_s_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA384#to_s" do
|
||||
|
||||
it "returns a hexdigest" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest.to_s.should == SHA384Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
it "does not change the internal state" do
|
||||
cur_digest = Digest::SHA384.new
|
||||
cur_digest.to_s.should == SHA384Constants::BlankHexdigest
|
||||
cur_digest.to_s.should == SHA384Constants::BlankHexdigest
|
||||
|
||||
cur_digest << SHA384Constants::Contents
|
||||
cur_digest.to_s.should == SHA384Constants::Hexdigest
|
||||
cur_digest.to_s.should == SHA384Constants::Hexdigest
|
||||
end
|
||||
|
||||
end
|
7
spec/ruby/library/digest/sha384/update_spec.rb
Normal file
7
spec/ruby/library/digest/sha384/update_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/update', __FILE__)
|
||||
|
||||
describe "Digest::SHA384#update" do
|
||||
it_behaves_like :sha384_update, :update
|
||||
end
|
7
spec/ruby/library/digest/sha512/append_spec.rb
Normal file
7
spec/ruby/library/digest/sha512/append_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/update', __FILE__)
|
||||
|
||||
describe "Digest::SHA512#<<" do
|
||||
it_behaves_like(:sha512_update, :<<)
|
||||
end
|
12
spec/ruby/library/digest/sha512/block_length_spec.rb
Normal file
12
spec/ruby/library/digest/sha512/block_length_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA512#block_length" do
|
||||
|
||||
it "returns the length of digest block" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest.block_length.should == SHA512Constants::BlockLength
|
||||
end
|
||||
|
||||
end
|
||||
|
13
spec/ruby/library/digest/sha512/digest_bang_spec.rb
Normal file
13
spec/ruby/library/digest/sha512/digest_bang_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA512#digest!" do
|
||||
|
||||
it "returns a digest and can digest!" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest << SHA512Constants::Contents
|
||||
cur_digest.digest!().should == SHA512Constants::Digest
|
||||
cur_digest.digest().should == SHA512Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
12
spec/ruby/library/digest/sha512/digest_length_spec.rb
Normal file
12
spec/ruby/library/digest/sha512/digest_length_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA512#digest_length" do
|
||||
|
||||
it "returns the length of computed digests" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest.digest_length.should == SHA512Constants::DigestLength
|
||||
end
|
||||
|
||||
end
|
||||
|
32
spec/ruby/library/digest/sha512/digest_spec.rb
Normal file
32
spec/ruby/library/digest/sha512/digest_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA512#digest" do
|
||||
|
||||
it "returns a digest" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest.digest().should == SHA512Constants::BlankDigest
|
||||
|
||||
# add something to check that the state is reset later
|
||||
cur_digest << "test"
|
||||
|
||||
cur_digest.digest(SHA512Constants::Contents).should == SHA512Constants::Digest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
cur_digest.digest(SHA512Constants::Contents).should == SHA512Constants::Digest
|
||||
|
||||
# after all is done, verify that the digest is in the original, blank state
|
||||
cur_digest.digest.should == SHA512Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "Digest::SHA512.digest" do
|
||||
|
||||
it "returns a digest" do
|
||||
Digest::SHA512.digest(SHA512Constants::Contents).should == SHA512Constants::Digest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
Digest::SHA512.digest(SHA512Constants::Contents).should == SHA512Constants::Digest
|
||||
Digest::SHA512.digest("").should == SHA512Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
37
spec/ruby/library/digest/sha512/equal_spec.rb
Normal file
37
spec/ruby/library/digest/sha512/equal_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA512#==" do
|
||||
|
||||
it "equals itself" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest.should == cur_digest
|
||||
end
|
||||
|
||||
it "equals the string representing its hexdigest" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest.should == SHA512Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
it "equals the appropriate object that responds to to_str" do
|
||||
# blank digest
|
||||
cur_digest = Digest::SHA512.new
|
||||
(obj = mock(SHA512Constants::BlankHexdigest)).should_receive(:to_str).and_return(SHA512Constants::BlankHexdigest)
|
||||
cur_digest.should == obj
|
||||
|
||||
# non-blank digest
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest << "test"
|
||||
d_value = cur_digest.hexdigest
|
||||
(obj = mock(d_value)).should_receive(:to_str).and_return(d_value)
|
||||
cur_digest.should == obj
|
||||
end
|
||||
|
||||
it "equals the same digest for a different object" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest2 = Digest::SHA512.new
|
||||
cur_digest.should == cur_digest2
|
||||
end
|
||||
|
||||
end
|
||||
|
43
spec/ruby/library/digest/sha512/file_spec.rb
Normal file
43
spec/ruby/library/digest/sha512/file_spec.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../../../../core/file/shared/read', __FILE__)
|
||||
|
||||
describe "Digest::SHA512.file" do
|
||||
|
||||
describe "when passed a path to a file that exists" do
|
||||
before :each do
|
||||
@file = tmp("md5_temp")
|
||||
touch(@file, 'wb') {|f| f.write SHA512Constants::Contents }
|
||||
end
|
||||
|
||||
after :each do
|
||||
rm_r @file
|
||||
end
|
||||
|
||||
it "returns a Digest::SHA512 object" do
|
||||
Digest::SHA512.file(@file).should be_kind_of(Digest::SHA512)
|
||||
end
|
||||
|
||||
it "returns a Digest::SHA512 object with the correct digest" do
|
||||
Digest::SHA512.file(@file).digest.should == SHA512Constants::Digest
|
||||
end
|
||||
|
||||
it "calls #to_str on an object and returns the Digest::SHA512 with the result" do
|
||||
obj = mock("to_str")
|
||||
obj.should_receive(:to_str).and_return(@file)
|
||||
result = Digest::SHA512.file(obj)
|
||||
result.should be_kind_of(Digest::SHA512)
|
||||
result.digest.should == SHA512Constants::Digest
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like :file_read_directory, :file, Digest::SHA512
|
||||
|
||||
it "raises a Errno::ENOENT when passed a path that does not exist" do
|
||||
lambda { Digest::SHA512.file("") }.should raise_error(Errno::ENOENT)
|
||||
end
|
||||
|
||||
it "raises a TypeError when passed nil" do
|
||||
lambda { Digest::SHA512.file(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
14
spec/ruby/library/digest/sha512/hexdigest_bang_spec.rb
Normal file
14
spec/ruby/library/digest/sha512/hexdigest_bang_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA512#hexdigest!" do
|
||||
|
||||
it "returns a hexdigest and resets the state" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
|
||||
cur_digest << SHA512Constants::Contents
|
||||
cur_digest.hexdigest!.should == SHA512Constants::Hexdigest
|
||||
cur_digest.hexdigest.should == SHA512Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
end
|
32
spec/ruby/library/digest/sha512/hexdigest_spec.rb
Normal file
32
spec/ruby/library/digest/sha512/hexdigest_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA512#hexdigest" do
|
||||
|
||||
it "returns a hexdigest" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest.hexdigest.should == SHA512Constants::BlankHexdigest
|
||||
|
||||
# add something to check that the state is reset later
|
||||
cur_digest << "test"
|
||||
|
||||
cur_digest.hexdigest(SHA512Constants::Contents).should == SHA512Constants::Hexdigest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
cur_digest.hexdigest(SHA512Constants::Contents).should == SHA512Constants::Hexdigest
|
||||
|
||||
# after all is done, verify that the digest is in the original, blank state
|
||||
cur_digest.hexdigest.should == SHA512Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "Digest::SHA512.hexdigest" do
|
||||
|
||||
it "returns a hexdigest" do
|
||||
Digest::SHA512.hexdigest(SHA512Constants::Contents).should == SHA512Constants::Hexdigest
|
||||
# second invocation is intentional, to make sure there are no side-effects
|
||||
Digest::SHA512.hexdigest(SHA512Constants::Contents).should == SHA512Constants::Hexdigest
|
||||
Digest::SHA512.hexdigest("").should == SHA512Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
end
|
12
spec/ruby/library/digest/sha512/inspect_spec.rb
Normal file
12
spec/ruby/library/digest/sha512/inspect_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA512#inspect" do
|
||||
|
||||
it "returns a Ruby object representation" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest.inspect.should == "#<#{SHA512Constants::Klass}: #{cur_digest.hexdigest()}>"
|
||||
end
|
||||
|
||||
end
|
||||
|
8
spec/ruby/library/digest/sha512/length_spec.rb
Normal file
8
spec/ruby/library/digest/sha512/length_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/length', __FILE__)
|
||||
|
||||
describe "Digest::SHA512#length" do
|
||||
it_behaves_like :sha512_length, :length
|
||||
end
|
||||
|
15
spec/ruby/library/digest/sha512/reset_spec.rb
Normal file
15
spec/ruby/library/digest/sha512/reset_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA512#reset" do
|
||||
|
||||
it "returns digest state to initial conditions" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest.update SHA512Constants::Contents
|
||||
cur_digest.digest().should_not == SHA512Constants::BlankDigest
|
||||
cur_digest.reset
|
||||
cur_digest.digest().should == SHA512Constants::BlankDigest
|
||||
end
|
||||
|
||||
end
|
||||
|
17
spec/ruby/library/digest/sha512/shared/constants.rb
Normal file
17
spec/ruby/library/digest/sha512/shared/constants.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# -*- encoding: binary -*-
|
||||
|
||||
require 'digest/sha2'
|
||||
|
||||
module SHA512Constants
|
||||
|
||||
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."
|
||||
|
||||
Klass = ::Digest::SHA512
|
||||
BlockLength = 128
|
||||
DigestLength = 64
|
||||
BlankDigest = "\317\203\3415~\357\270\275\361T(P\326m\200\a\326 \344\005\vW\025\334\203\364\251!\323l\351\316G\320\321<]\205\362\260\377\203\030\322\207~\354/c\2711\275GAz\201\24582z\371'\332>"
|
||||
Digest = "\241\231\232\365\002z\241\331\242\310=\367F\272\004\326\331g\315n\251Q\222\250\374E\257\254=\325\225\003SM\350\244\234\220\233=\031\230A;\000\203\233\340\323t\333\271\222w\266\307\2678\344\255j\003\216\300"
|
||||
BlankHexdigest = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
|
||||
Hexdigest = "a1999af5027aa1d9a2c83df746ba04d6d967cd6ea95192a8fc45afac3dd59503534de8a49c909b3d1998413b00839be0d374dbb99277b6c7b738e4ad6a038ec0"
|
||||
|
||||
end
|
8
spec/ruby/library/digest/sha512/shared/length.rb
Normal file
8
spec/ruby/library/digest/sha512/shared/length.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
describe :sha512_length, shared: true do
|
||||
it "returns the length of the digest" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest.send(@method).should == SHA512Constants::BlankDigest.size
|
||||
cur_digest << SHA512Constants::Contents
|
||||
cur_digest.send(@method).should == SHA512Constants::Digest.size
|
||||
end
|
||||
end
|
7
spec/ruby/library/digest/sha512/shared/update.rb
Normal file
7
spec/ruby/library/digest/sha512/shared/update.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
describe :sha512_update, shared: true do
|
||||
it "can update" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest.send @method, SHA512Constants::Contents
|
||||
cur_digest.digest.should == SHA512Constants::Digest
|
||||
end
|
||||
end
|
8
spec/ruby/library/digest/sha512/size_spec.rb
Normal file
8
spec/ruby/library/digest/sha512/size_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/length', __FILE__)
|
||||
|
||||
describe "Digest::SHA512#size" do
|
||||
it_behaves_like :sha512_length, :size
|
||||
end
|
||||
|
21
spec/ruby/library/digest/sha512/to_s_spec.rb
Normal file
21
spec/ruby/library/digest/sha512/to_s_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
|
||||
describe "Digest::SHA512#to_s" do
|
||||
|
||||
it "returns a hexdigest" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest.to_s.should == SHA512Constants::BlankHexdigest
|
||||
end
|
||||
|
||||
it "does not change the internal state" do
|
||||
cur_digest = Digest::SHA512.new
|
||||
cur_digest.to_s.should == SHA512Constants::BlankHexdigest
|
||||
cur_digest.to_s.should == SHA512Constants::BlankHexdigest
|
||||
|
||||
cur_digest << SHA512Constants::Contents
|
||||
cur_digest.to_s.should == SHA512Constants::Hexdigest
|
||||
cur_digest.to_s.should == SHA512Constants::Hexdigest
|
||||
end
|
||||
|
||||
end
|
7
spec/ruby/library/digest/sha512/update_spec.rb
Normal file
7
spec/ruby/library/digest/sha512/update_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/constants', __FILE__)
|
||||
require File.expand_path('../shared/update', __FILE__)
|
||||
|
||||
describe "Digest::SHA512#update" do
|
||||
it_behaves_like :sha512_update, :update
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue