forked from jruby/jruby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JRUBY-4717: Import digest.rb from CRuby stdlib.
I broke digest lib for 1.8 at 51bf9d9 and Nick fixed it at 288ef4a. And this is a new try for re-fixing digest library for JRUBY-4717. * Update tool/globals_1_8_7.rb to import digest.rb for 1.8 as same as 1.9. * Remove Java implementation of Digest.const_missing. It's defined in lib/digest.rb for both 1.8 and 1.9. * Revert 288ef1ae. It does not mean that 288ef4a is wrong. It's 51bf9d9 which should be fixed and needs above fixes. 288ef4a was needed. With importing lib/digest.rb for 1.8 mode, Digest function start working for 1.8 as same as CRuby. % ruby187 -rdigest -e 'p Digest("SHA2")' Digest::SHA2 % jruby -rdigest -e 'p Digest("SHA2")' Digest::SHA2 % jruby163 -rdigest -e 'p Digest("SHA2")' NoMethodError: undefined method `Digest' for main:Object (root) at -e:1
- Loading branch information
Hiroshi Nakamura
committed
Aug 2, 2011
1 parent
1ca723b
commit 08c38b4
Showing
4 changed files
with
52 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,50 @@ | |||
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}", caller(1) | |||
end | |||
unless Digest.const_defined?(name) | |||
raise NameError, "uninitialized constant Digest::#{name}", caller(1) | |||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters