summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--ext/digest/lib/digest.rb6
-rwxr-xr-xtest/digest/test_digest.rb25
3 files changed, 35 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index b004a292f4..c07fac347b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue May 21 19:57:22 2013 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/digest/lib/digest.rb (Digest::Class.file): Take optional
+ arguments that are passed to the constructor of the digest
+ class.
+
Tue May 21 17:21:12 2013 Koichi Sasada <ko1@atdot.net>
* gc.c: remove gc_profile_record::is_marked. always true.
diff --git a/ext/digest/lib/digest.rb b/ext/digest/lib/digest.rb
index 4a98af2eae..83630f45d1 100644
--- a/ext/digest/lib/digest.rb
+++ b/ext/digest/lib/digest.rb
@@ -22,11 +22,13 @@ module Digest
class ::Digest::Class
# creates a digest object and reads a given file, _name_.
+ # Optional arguments are passed to the constructor of the digest
+ # class.
#
# p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
# # => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"
- def self.file(name)
- new.file(name)
+ def self.file(name, *args)
+ new(*args).file(name)
end
# Returns the base64 encoded hash value of a given _string_. The
diff --git a/test/digest/test_digest.rb b/test/digest/test_digest.rb
index 4b1d55e256..1af6ea3040 100755
--- a/test/digest/test_digest.rb
+++ b/test/digest/test_digest.rb
@@ -4,6 +4,7 @@
# $Id$
require 'test/unit'
+require 'tempfile'
require 'digest'
%w[digest/md5 digest/rmd160 digest/sha1 digest/sha2].each do |lib|
@@ -78,6 +79,16 @@ module TestDigest
assert_equal(md1, md2, self.class::ALGO)
end
+ def test_s_file
+ Tempfile.create("test_digest_file") { |tmpfile|
+ str = "hello, world.\r\n"
+ tmpfile.print str
+ tmpfile.close
+
+ assert_equal self.class::ALGO.new.update(str), self.class::ALGO.file(tmpfile.path)
+ }
+ end
+
def test_instance_eval
assert_nothing_raised {
self.class::ALGO.new.instance_eval { update "a" }
@@ -138,6 +149,20 @@ module TestDigest
}
end if defined?(Digest::SHA512)
+ class TestSHA2 < Test::Unit::TestCase
+
+ def test_s_file
+ Tempfile.create("test_digest_file") { |tmpfile|
+ str = Data1
+ tmpfile.print str
+ tmpfile.close
+
+ assert_equal "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7", Digest::SHA2.file(tmpfile.path, 384).hexdigest
+ }
+ end
+
+ end if defined?(Digest::SHA2)
+
class TestRMD160 < Test::Unit::TestCase
include TestDigest
ALGO = Digest::RMD160