diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-22 01:53:51 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-22 01:53:51 +0000 |
commit | 1e760c0be3ed35874204114e7454509f740c0fe2 (patch) | |
tree | a75eb2b1eea073830902d1fa49c568c4525c8b57 /ruby_1_8_6/ext/digest/lib | |
parent | a2055d63b41a6678dc7aeb17d0bece314e700c5a (diff) |
add tag v1_8_6_71v1_8_5_71
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_8_5_71@13189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_1_8_6/ext/digest/lib')
-rw-r--r-- | ruby_1_8_6/ext/digest/lib/digest.rb | 48 | ||||
-rw-r--r-- | ruby_1_8_6/ext/digest/lib/md5.rb | 23 | ||||
-rw-r--r-- | ruby_1_8_6/ext/digest/lib/sha1.rb | 23 |
3 files changed, 94 insertions, 0 deletions
diff --git a/ruby_1_8_6/ext/digest/lib/digest.rb b/ruby_1_8_6/ext/digest/lib/digest.rb new file mode 100644 index 0000000000..244cd436b3 --- /dev/null +++ b/ruby_1_8_6/ext/digest/lib/digest.rb @@ -0,0 +1,48 @@ +require 'digest.so' + +module Digest + def self.const_missing(name) + case name + when :SHA256, :SHA384, :SHA512 + lib = 'digest/sha2.so' + else + lib = File.join('digest', name.to_s.downcase) + end + + begin + require lib + rescue LoadError => e + raise LoadError, "library not found for class Digest::#{name} -- #{lib}" + end + + Digest.const_get(name) + end + + class ::Digest::Class + # creates a digest object and reads a given file, _name_. + # + # p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest + # # => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534" + def self.file(name) + new.file(name) + end + end + + module Instance + # updates the digest with the contents of a given file _name_ and + # returns self. + def file(name) + File.open(name, "rb") {|f| + buf = "" + while f.read(16384, buf) + update buf + end + } + self + end + end +end + +def Digest(name) + Digest.const_get(name) +end diff --git a/ruby_1_8_6/ext/digest/lib/md5.rb b/ruby_1_8_6/ext/digest/lib/md5.rb new file mode 100644 index 0000000000..c399f2de1d --- /dev/null +++ b/ruby_1_8_6/ext/digest/lib/md5.rb @@ -0,0 +1,23 @@ +# just for compatibility; requiring "md5" is obsoleted +# +# $RoughId: md5.rb,v 1.4 2001/07/13 15:38:27 knu Exp $ +# $Id$ + +require 'digest/md5' + +class MD5 < Digest::MD5 + class << self + alias orig_new new + def new(str = nil) + if str + orig_new.update(str) + else + orig_new + end + end + + def md5(*args) + new(*args) + end + end +end diff --git a/ruby_1_8_6/ext/digest/lib/sha1.rb b/ruby_1_8_6/ext/digest/lib/sha1.rb new file mode 100644 index 0000000000..4446e12e8d --- /dev/null +++ b/ruby_1_8_6/ext/digest/lib/sha1.rb @@ -0,0 +1,23 @@ +# just for compatibility; requiring "sha1" is obsoleted +# +# $RoughId: sha1.rb,v 1.4 2001/07/13 15:38:27 knu Exp $ +# $Id$ + +require 'digest/sha1' + +class SHA1 < Digest::SHA1 + class << self + alias orig_new new + def new(str = nil) + if str + orig_new.update(str) + else + orig_new + end + end + + def sha1(*args) + new(*args) + end + end +end |