aboutsummaryrefslogtreecommitdiffstats
path: root/spec/rubyspec/library/digest/sha384
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-07 12:04:49 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-07 12:04:49 +0000
commit95e8c48dd3348503a8c7db5d0498894a1b676395 (patch)
tree9eef7f720314ebaff56845a74e203770e62284e4 /spec/rubyspec/library/digest/sha384
parented7d803500de38186c74bce94d233e85ef51e503 (diff)
downloadruby-95e8c48dd3348503a8c7db5d0498894a1b676395.tar.gz
Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers. * .gitignore: track changes under spec. * spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec. These files can therefore be updated like any other file in MRI. Instructions are provided in spec/README. [Feature #13156] [ruby-core:79246] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/rubyspec/library/digest/sha384')
-rw-r--r--spec/rubyspec/library/digest/sha384/append_spec.rb7
-rw-r--r--spec/rubyspec/library/digest/sha384/block_length_spec.rb12
-rw-r--r--spec/rubyspec/library/digest/sha384/digest_bang_spec.rb13
-rw-r--r--spec/rubyspec/library/digest/sha384/digest_length_spec.rb12
-rw-r--r--spec/rubyspec/library/digest/sha384/digest_spec.rb32
-rw-r--r--spec/rubyspec/library/digest/sha384/equal_spec.rb37
-rw-r--r--spec/rubyspec/library/digest/sha384/file_spec.rb43
-rw-r--r--spec/rubyspec/library/digest/sha384/hexdigest_bang_spec.rb14
-rw-r--r--spec/rubyspec/library/digest/sha384/hexdigest_spec.rb32
-rw-r--r--spec/rubyspec/library/digest/sha384/inspect_spec.rb12
-rw-r--r--spec/rubyspec/library/digest/sha384/length_spec.rb8
-rw-r--r--spec/rubyspec/library/digest/sha384/reset_spec.rb15
-rw-r--r--spec/rubyspec/library/digest/sha384/shared/constants.rb18
-rw-r--r--spec/rubyspec/library/digest/sha384/shared/length.rb8
-rw-r--r--spec/rubyspec/library/digest/sha384/shared/update.rb7
-rw-r--r--spec/rubyspec/library/digest/sha384/size_spec.rb8
-rw-r--r--spec/rubyspec/library/digest/sha384/to_s_spec.rb21
-rw-r--r--spec/rubyspec/library/digest/sha384/update_spec.rb7
18 files changed, 306 insertions, 0 deletions
diff --git a/spec/rubyspec/library/digest/sha384/append_spec.rb b/spec/rubyspec/library/digest/sha384/append_spec.rb
new file mode 100644
index 0000000000..d694812e85
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/append_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/digest/sha384/block_length_spec.rb b/spec/rubyspec/library/digest/sha384/block_length_spec.rb
new file mode 100644
index 0000000000..070715b27e
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/block_length_spec.rb
@@ -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
+
diff --git a/spec/rubyspec/library/digest/sha384/digest_bang_spec.rb b/spec/rubyspec/library/digest/sha384/digest_bang_spec.rb
new file mode 100644
index 0000000000..83b68ae7c2
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/digest_bang_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/digest/sha384/digest_length_spec.rb b/spec/rubyspec/library/digest/sha384/digest_length_spec.rb
new file mode 100644
index 0000000000..a57616b44c
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/digest_length_spec.rb
@@ -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
+
diff --git a/spec/rubyspec/library/digest/sha384/digest_spec.rb b/spec/rubyspec/library/digest/sha384/digest_spec.rb
new file mode 100644
index 0000000000..3a5cd3a5d7
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/digest_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/digest/sha384/equal_spec.rb b/spec/rubyspec/library/digest/sha384/equal_spec.rb
new file mode 100644
index 0000000000..a54d328edc
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/equal_spec.rb
@@ -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
+
diff --git a/spec/rubyspec/library/digest/sha384/file_spec.rb b/spec/rubyspec/library/digest/sha384/file_spec.rb
new file mode 100644
index 0000000000..7e7c8f9565
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/file_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/digest/sha384/hexdigest_bang_spec.rb b/spec/rubyspec/library/digest/sha384/hexdigest_bang_spec.rb
new file mode 100644
index 0000000000..68da8c7200
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/hexdigest_bang_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/digest/sha384/hexdigest_spec.rb b/spec/rubyspec/library/digest/sha384/hexdigest_spec.rb
new file mode 100644
index 0000000000..a7724d1663
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/hexdigest_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/digest/sha384/inspect_spec.rb b/spec/rubyspec/library/digest/sha384/inspect_spec.rb
new file mode 100644
index 0000000000..554a22d135
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/inspect_spec.rb
@@ -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
+
diff --git a/spec/rubyspec/library/digest/sha384/length_spec.rb b/spec/rubyspec/library/digest/sha384/length_spec.rb
new file mode 100644
index 0000000000..63a57ce9ca
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/length_spec.rb
@@ -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
+
diff --git a/spec/rubyspec/library/digest/sha384/reset_spec.rb b/spec/rubyspec/library/digest/sha384/reset_spec.rb
new file mode 100644
index 0000000000..8abe39d7e2
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/reset_spec.rb
@@ -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
+
diff --git a/spec/rubyspec/library/digest/sha384/shared/constants.rb b/spec/rubyspec/library/digest/sha384/shared/constants.rb
new file mode 100644
index 0000000000..3697384fc3
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/shared/constants.rb
@@ -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
diff --git a/spec/rubyspec/library/digest/sha384/shared/length.rb b/spec/rubyspec/library/digest/sha384/shared/length.rb
new file mode 100644
index 0000000000..0c88288bcf
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/shared/length.rb
@@ -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
diff --git a/spec/rubyspec/library/digest/sha384/shared/update.rb b/spec/rubyspec/library/digest/sha384/shared/update.rb
new file mode 100644
index 0000000000..1c6e31cf6a
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/shared/update.rb
@@ -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
diff --git a/spec/rubyspec/library/digest/sha384/size_spec.rb b/spec/rubyspec/library/digest/sha384/size_spec.rb
new file mode 100644
index 0000000000..9aea3ef592
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/size_spec.rb
@@ -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
+
diff --git a/spec/rubyspec/library/digest/sha384/to_s_spec.rb b/spec/rubyspec/library/digest/sha384/to_s_spec.rb
new file mode 100644
index 0000000000..f45f2ee915
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/to_s_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/digest/sha384/update_spec.rb b/spec/rubyspec/library/digest/sha384/update_spec.rb
new file mode 100644
index 0000000000..9917f86b86
--- /dev/null
+++ b/spec/rubyspec/library/digest/sha384/update_spec.rb
@@ -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