Permalink
Browse files

Install Digest extensions through extconf.rb

This fixes a digest issue with very large files because apparently for
large files the fallback implementation behaves differently. By uses the
extconf.rb setup we ensure the behavior is the same as MRI.

Also updates Digest extension with latest version from 1.9.3.
  • Loading branch information...
1 parent dd8d5c8 commit 6056ba1c710782c718a47e7fdb1b80a601242f85 @dbussink dbussink committed Dec 7, 2012
View
@@ -1,19 +1,20 @@
require 'digest/ext/digest'
module Digest
- def self.const_missing(name)
+ def self.const_missing(name) # :nodoc:
case name
when :SHA256, :SHA384, :SHA512
- path = "digest/sha2"
+ lib = 'digest/sha2'
else
- lib = name.to_s.downcase
- path = "digest/#{lib}"
+ lib = File.join('digest', name.to_s.downcase)
end
begin
- require path
- rescue LoadError => e
- raise LoadError, "library not found for class Digest::#{name} -- #{path}", caller(1)
+ p "REQUIRING"
+ require lib
+ p "BOOOO"
+ rescue LoadError
+ 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)
@@ -23,12 +24,19 @@ def self.const_missing(name)
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"
+ #
+ # p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
+ # # => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"
def self.file(name)
new.file(name)
end
+
+ # Returns the base64 encoded hash value of a given _string_. The
+ # return value is properly padded with '=' and contains no line
+ # feeds.
+ def self.base64digest(str, *args)
+ [digest(str, *args)].pack('m0')
+ end
end
module Instance
@@ -43,13 +51,40 @@ def file(name)
}
self
end
- end
-end
-class Object
- def Digest(name)
- Digest.const_get(name)
+ # If none is given, returns the resulting hash value of the digest
+ # in a base64 encoded form, keeping the digest's state.
+ #
+ # If a +string+ is given, returns the hash value for the given
+ # +string+ in a base64 encoded form, resetting the digest to the
+ # initial state before and after the process.
+ #
+ # In either case, the return value is properly padded with '=' and
+ # contains no line feeds.
+ def base64digest(str = nil)
+ [str ? digest(str) : digest].pack('m0')
+ end
+
+ # Returns the resulting hash value and resets the digest to the
+ # initial state.
+ def base64digest!
+ [digest!].pack('m0')
+ end
end
+end
- private :Digest
+# call-seq:
+# Digest(name) -> digest_subclass
+#
+# Returns a Digest subclass by +name+.
+#
+# require 'digest'
+#
+# Digest("MD5")
+# # => Digest::MD5
+#
+# Digest("Foo")
+# # => LoadError: library not found for class Digest::Foo -- digest/foo
+def Digest(name)
+ Digest.const_get(name)
end
@@ -0,0 +1,2 @@
+Makefile
+*.log
View
@@ -1,19 +0,0 @@
-require 'rake/loaders/makefile'
-
-# Setup project files
-project_files = common_headers + headers + sources + objects
-
-add_rbx_capi
-
-add_shared_lib "crypto"
-
-digest = "digest.#{$DLEXT}"
-
-file digest => project_files
-
-graph_dependencies sources
-
-import dependency_file
-
-desc "Build Digest extension"
-task :build => digest
@@ -0,0 +1,2 @@
+Makefile
+*.log
@@ -1,20 +0,0 @@
-require 'rake/loaders/makefile'
-
-# Setup project files
-project_files = common_headers + headers + sources + objects
-
-add_rbx_capi
-
-add_include_dir ".."
-add_shared_lib "crypto"
-
-bubblebabble = "bubblebabble.#{$DLEXT}"
-
-file bubblebabble => project_files
-
-graph_dependencies sources, "./../"
-
-import dependency_file
-
-desc "Build Digest/bubblebabble extension"
-task :build => bubblebabble
@@ -0,0 +1,3 @@
+bubblebabble.o: bubblebabble.c $(srcdir)/../digest.h $(hdrdir)/ruby.h \
+ $(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/intern.h \
+ $(srcdir)/../defs.h
@@ -0,0 +1,4 @@
+#ifndef EXTCONF_H
+#define EXTCONF_H
+#define HAVE_CONFIG_H 1
+#endif
@@ -0,0 +1,6 @@
+require 'mkmf'
+
+$defs << "-DHAVE_CONFIG_H"
+$INCFLAGS << " -I$(srcdir)/.."
+
+create_makefile('digest/bubblebabble')
View
@@ -0,0 +1,2 @@
+digest.o: digest.c digest.h $(hdrdir)/ruby.h $(topdir)/config.h \
+ $(hdrdir)/defines.h $(hdrdir)/intern.h
View
@@ -0,0 +1,3 @@
+#ifndef EXTCONF_H
+#define EXTCONF_H
+#endif
View
@@ -0,0 +1,10 @@
+# $RoughId: extconf.rb,v 1.6 2001/07/13 15:38:27 knu Exp $
+# $Id$
+
+require "mkmf"
+
+$INSTALLFILES = {
+ "digest.h" => "$(RUBYARCHDIR)"
+}
+
+create_makefile("digest")
@@ -0,0 +1,2 @@
+Makefile
+*.log
@@ -1,20 +0,0 @@
-require 'rake/loaders/makefile'
-
-# Setup project files
-project_files = common_headers + headers + sources + objects
-
-add_rbx_capi
-
-add_include_dir ".."
-add_shared_lib "crypto"
-
-md5 = "md5.#{$DLEXT}"
-
-file md5 => project_files
-
-graph_dependencies sources, "./../"
-
-import dependency_file
-
-desc "Build Digest/md5 extension"
-task :build => md5
@@ -0,0 +1,6 @@
+md5.o: md5.c md5.h $(srcdir)/../defs.h $(hdrdir)/ruby.h $(topdir)/config.h \
+ $(hdrdir)/defines.h $(hdrdir)/intern.h
+md5init.o: md5init.c $(srcdir)/../digest.h $(hdrdir)/ruby.h \
+ $(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/intern.h md5.h \
+ $(srcdir)/../defs.h
+md5ossl.o: md5ossl.h
@@ -0,0 +1,6 @@
+#ifndef EXTCONF_H
+#define EXTCONF_H
+#define HAVE_CONFIG_H 1
+#define HAVE_OPENSSL_MD5_H 1
+#define HAVE_SYS_CDEFS_H 1
+#endif
@@ -0,0 +1,29 @@
+# $RoughId: extconf.rb,v 1.3 2001/08/14 19:54:51 knu Exp $
+# $Id$
+
+require "mkmf"
+
+$defs << "-DHAVE_CONFIG_H"
+$INCFLAGS << " -I$(srcdir)/.."
+
+$objs = [ "md5init.#{$OBJEXT}" ]
+
+dir_config("openssl")
+
+if !with_config("bundled-md5") &&
+ have_library("crypto") && have_header("openssl/md5.h")
+ $objs << "md5ossl.#{$OBJEXT}"
+
+else
+ $objs << "md5.#{$OBJEXT}"
+end
+
+have_header("sys/cdefs.h")
+
+have_header("inttypes.h")
+
+have_header("unistd.h")
+
+$preload = %w[digest]
+
+create_makefile("digest/md5")
@@ -0,0 +1,2 @@
+Makefile
+*.log
@@ -1,20 +0,0 @@
-require 'rake/loaders/makefile'
-
-# Setup project files
-project_files = common_headers + headers + sources + objects
-
-add_rbx_capi
-
-add_include_dir ".."
-add_shared_lib "crypto"
-
-rmd160 = "rmd160.#{$DLEXT}"
-
-file rmd160 => project_files
-
-graph_dependencies sources, "./../"
-
-import dependency_file
-
-desc "Build Digest/rmd160 extension"
-task :build => rmd160
@@ -0,0 +1,6 @@
+rmd160.o: rmd160.c rmd160.h $(srcdir)/../defs.h $(hdrdir)/ruby.h \
+ $(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/intern.h
+rmd160init.o: rmd160init.c $(srcdir)/../digest.h $(hdrdir)/ruby.h \
+ $(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/intern.h \
+ rmd160.h $(srcdir)/../defs.h
+rmd160ossl.o: rmd160ossl.h $(srcdir)/../defs.h
@@ -0,0 +1,7 @@
+#ifndef EXTCONF_H
+#define EXTCONF_H
+#define NDEBUG 1
+#define HAVE_CONFIG_H 1
+#define HAVE_OPENSSL_RIPEMD_H 1
+#define HAVE_SYS_CDEFS_H 1
+#endif
@@ -0,0 +1,28 @@
+# $RoughId: extconf.rb,v 1.3 2001/08/14 19:54:51 knu Exp $
+# $Id$
+
+require "mkmf"
+
+$defs << "-DNDEBUG" << "-DHAVE_CONFIG_H"
+$INCFLAGS << " -I$(srcdir)/.."
+
+$objs = [ "rmd160init.#{$OBJEXT}" ]
+
+dir_config("openssl")
+
+if !with_config("bundled-rmd160") &&
+ have_library("crypto") && have_header("openssl/ripemd.h")
+ $objs << "rmd160ossl.#{$OBJEXT}"
+else
+ $objs << "rmd160.#{$OBJEXT}"
+end
+
+have_header("sys/cdefs.h")
+
+have_header("inttypes.h")
+
+have_header("unistd.h")
+
+$preload = %w[digest]
+
+create_makefile("digest/rmd160")
@@ -0,0 +1,2 @@
+Makefile
+*.log
@@ -1,20 +0,0 @@
-require 'rake/loaders/makefile'
-
-# Setup project files
-project_files = common_headers + headers + sources + objects
-
-add_rbx_capi
-
-add_include_dir ".."
-add_shared_lib "crypto"
-
-sha1 = "sha1.#{$DLEXT}"
-
-file sha1 => project_files
-
-graph_dependencies sources, "./../"
-
-import dependency_file
-
-desc "Build Digest/sha1 extension"
-task :build => sha1
@@ -0,0 +1,6 @@
+sha1.o: sha1.c sha1.h $(srcdir)/../defs.h $(hdrdir)/ruby.h \
+ $(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/intern.h
+sha1init.o: sha1init.c $(srcdir)/../digest.h $(hdrdir)/ruby.h \
+ $(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/intern.h \
+ sha1.h $(srcdir)/../defs.h
+sha1ossl.o: sha1ossl.h $(srcdir)/../defs.h
@@ -0,0 +1,6 @@
+#ifndef EXTCONF_H
+#define EXTCONF_H
+#define HAVE_CONFIG_H 1
+#define HAVE_OPENSSL_SHA_H 1
+#define HAVE_SYS_CDEFS_H 1
+#endif
@@ -0,0 +1,28 @@
+# $RoughId: extconf.rb,v 1.3 2001/08/14 19:54:51 knu Exp $
+# $Id$
+
+require "mkmf"
+
+$defs << "-DHAVE_CONFIG_H"
+$INCFLAGS << " -I$(srcdir)/.."
+
+$objs = [ "sha1init.#{$OBJEXT}" ]
+
+dir_config("openssl")
+
+if !with_config("bundled-sha1") &&
+ have_library("crypto") && have_header("openssl/sha.h")
+ $objs << "sha1ossl.#{$OBJEXT}"
+else
+ $objs << "sha1.#{$OBJEXT}"
+end
+
+have_header("sys/cdefs.h")
+
+have_header("inttypes.h")
+
+have_header("unistd.h")
+
+$preload = %w[digest]
+
+create_makefile("digest/sha1")
@@ -0,0 +1,2 @@
+Makefile
+*.log
Oops, something went wrong.

0 comments on commit 6056ba1

Please sign in to comment.