diff options
Diffstat (limited to 'spec/ruby/library/digest/sha512')
18 files changed, 299 insertions, 0 deletions
diff --git a/spec/ruby/library/digest/sha512/append_spec.rb b/spec/ruby/library/digest/sha512/append_spec.rb new file mode 100644 index 0000000000..9106e9685d --- /dev/null +++ b/spec/ruby/library/digest/sha512/append_spec.rb @@ -0,0 +1,7 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' +require_relative 'shared/update' + +describe "Digest::SHA512#<<" do + it_behaves_like :sha512_update, :<< +end diff --git a/spec/ruby/library/digest/sha512/block_length_spec.rb b/spec/ruby/library/digest/sha512/block_length_spec.rb new file mode 100644 index 0000000000..947af841dd --- /dev/null +++ b/spec/ruby/library/digest/sha512/block_length_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' + +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 diff --git a/spec/ruby/library/digest/sha512/digest_bang_spec.rb b/spec/ruby/library/digest/sha512/digest_bang_spec.rb new file mode 100644 index 0000000000..981570b907 --- /dev/null +++ b/spec/ruby/library/digest/sha512/digest_bang_spec.rb @@ -0,0 +1,13 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' + +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 diff --git a/spec/ruby/library/digest/sha512/digest_length_spec.rb b/spec/ruby/library/digest/sha512/digest_length_spec.rb new file mode 100644 index 0000000000..ff5956dd75 --- /dev/null +++ b/spec/ruby/library/digest/sha512/digest_length_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' + +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 diff --git a/spec/ruby/library/digest/sha512/digest_spec.rb b/spec/ruby/library/digest/sha512/digest_spec.rb new file mode 100644 index 0000000000..092efccc62 --- /dev/null +++ b/spec/ruby/library/digest/sha512/digest_spec.rb @@ -0,0 +1,32 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' + +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 diff --git a/spec/ruby/library/digest/sha512/equal_spec.rb b/spec/ruby/library/digest/sha512/equal_spec.rb new file mode 100644 index 0000000000..5100ced6e8 --- /dev/null +++ b/spec/ruby/library/digest/sha512/equal_spec.rb @@ -0,0 +1,36 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' + +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 diff --git a/spec/ruby/library/digest/sha512/file_spec.rb b/spec/ruby/library/digest/sha512/file_spec.rb new file mode 100644 index 0000000000..78d6d3d4f3 --- /dev/null +++ b/spec/ruby/library/digest/sha512/file_spec.rb @@ -0,0 +1,43 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' +require_relative '../../../core/file/shared/read' + +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.is_a?(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.is_a?(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 + -> { Digest::SHA512.file("") }.should.raise(Errno::ENOENT) + end + + it "raises a TypeError when passed nil" do + -> { Digest::SHA512.file(nil) }.should.raise(TypeError) + end +end diff --git a/spec/ruby/library/digest/sha512/hexdigest_bang_spec.rb b/spec/ruby/library/digest/sha512/hexdigest_bang_spec.rb new file mode 100644 index 0000000000..e9b0da6191 --- /dev/null +++ b/spec/ruby/library/digest/sha512/hexdigest_bang_spec.rb @@ -0,0 +1,14 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' + +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 diff --git a/spec/ruby/library/digest/sha512/hexdigest_spec.rb b/spec/ruby/library/digest/sha512/hexdigest_spec.rb new file mode 100644 index 0000000000..6e1dc3c642 --- /dev/null +++ b/spec/ruby/library/digest/sha512/hexdigest_spec.rb @@ -0,0 +1,32 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' + +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 diff --git a/spec/ruby/library/digest/sha512/inspect_spec.rb b/spec/ruby/library/digest/sha512/inspect_spec.rb new file mode 100644 index 0000000000..54a466043a --- /dev/null +++ b/spec/ruby/library/digest/sha512/inspect_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' + +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 diff --git a/spec/ruby/library/digest/sha512/length_spec.rb b/spec/ruby/library/digest/sha512/length_spec.rb new file mode 100644 index 0000000000..e9fde90577 --- /dev/null +++ b/spec/ruby/library/digest/sha512/length_spec.rb @@ -0,0 +1,7 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' +require_relative 'shared/length' + +describe "Digest::SHA512#length" do + it_behaves_like :sha512_length, :length +end diff --git a/spec/ruby/library/digest/sha512/reset_spec.rb b/spec/ruby/library/digest/sha512/reset_spec.rb new file mode 100644 index 0000000000..24a936d4ba --- /dev/null +++ b/spec/ruby/library/digest/sha512/reset_spec.rb @@ -0,0 +1,14 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' + +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 diff --git a/spec/ruby/library/digest/sha512/shared/constants.rb b/spec/ruby/library/digest/sha512/shared/constants.rb new file mode 100644 index 0000000000..91787381ee --- /dev/null +++ b/spec/ruby/library/digest/sha512/shared/constants.rb @@ -0,0 +1,18 @@ +# 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" + Base64digest = "oZma9QJ6odmiyD33RroE1tlnzW6pUZKo/EWvrD3VlQNTTeiknJCbPRmYQTsAg5vg03TbuZJ3tse3OOStagOOwA==" + +end diff --git a/spec/ruby/library/digest/sha512/shared/length.rb b/spec/ruby/library/digest/sha512/shared/length.rb new file mode 100644 index 0000000000..c0609d5386 --- /dev/null +++ b/spec/ruby/library/digest/sha512/shared/length.rb @@ -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 diff --git a/spec/ruby/library/digest/sha512/shared/update.rb b/spec/ruby/library/digest/sha512/shared/update.rb new file mode 100644 index 0000000000..ca74dbf4df --- /dev/null +++ b/spec/ruby/library/digest/sha512/shared/update.rb @@ -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 diff --git a/spec/ruby/library/digest/sha512/size_spec.rb b/spec/ruby/library/digest/sha512/size_spec.rb new file mode 100644 index 0000000000..6d0acdabdb --- /dev/null +++ b/spec/ruby/library/digest/sha512/size_spec.rb @@ -0,0 +1,7 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' +require_relative 'shared/length' + +describe "Digest::SHA512#size" do + it_behaves_like :sha512_length, :size +end diff --git a/spec/ruby/library/digest/sha512/to_s_spec.rb b/spec/ruby/library/digest/sha512/to_s_spec.rb new file mode 100644 index 0000000000..68d86241c9 --- /dev/null +++ b/spec/ruby/library/digest/sha512/to_s_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' + +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 diff --git a/spec/ruby/library/digest/sha512/update_spec.rb b/spec/ruby/library/digest/sha512/update_spec.rb new file mode 100644 index 0000000000..682d3a19bb --- /dev/null +++ b/spec/ruby/library/digest/sha512/update_spec.rb @@ -0,0 +1,7 @@ +require_relative '../../../spec_helper' +require_relative 'shared/constants' +require_relative 'shared/update' + +describe "Digest::SHA512#update" do + it_behaves_like :sha512_update, :update +end |
