mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/digest/lib/digest.rb (Digest::Class.file): Take optional
arguments that are passed to the constructor of the digest class. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
51d586c64e
commit
07a6b4cbb5
3 changed files with 35 additions and 2 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue