Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 6056ba1c710782c718a47e7fdb1b80a601242f85 1 parent dd8d5c8
@dbussink dbussink authored
Showing with 570 additions and 143 deletions.
  1. +51 −16 lib/digest.rb
  2. +2 −0  lib/digest/ext/.gitignore
  3. +0 −19 lib/digest/ext/Rakefile
  4. +2 −0  lib/digest/ext/bubblebabble/.gitignore
  5. +0 −20 lib/digest/ext/bubblebabble/Rakefile
  6. +3 −0  lib/digest/ext/bubblebabble/depend
  7. +4 −0 lib/digest/ext/bubblebabble/extconf.h
  8. +6 −0 lib/digest/ext/bubblebabble/extconf.rb
  9. +2 −0  lib/digest/ext/depend
  10. +3 −0  lib/digest/ext/extconf.h
  11. +10 −0 lib/digest/ext/extconf.rb
  12. +2 −0  lib/digest/ext/md5/.gitignore
  13. +0 −20 lib/digest/ext/md5/Rakefile
  14. +6 −0 lib/digest/ext/md5/depend
  15. +6 −0 lib/digest/ext/md5/extconf.h
  16. +29 −0 lib/digest/ext/md5/extconf.rb
  17. +2 −0  lib/digest/ext/rmd160/.gitignore
  18. +0 −20 lib/digest/ext/rmd160/Rakefile
  19. +6 −0 lib/digest/ext/rmd160/depend
  20. +7 −0 lib/digest/ext/rmd160/extconf.h
  21. +28 −0 lib/digest/ext/rmd160/extconf.rb
  22. +2 −0  lib/digest/ext/sha1/.gitignore
  23. +0 −20 lib/digest/ext/sha1/Rakefile
  24. +6 −0 lib/digest/ext/sha1/depend
  25. +6 −0 lib/digest/ext/sha1/extconf.h
  26. +28 −0 lib/digest/ext/sha1/extconf.rb
  27. +2 −0  lib/digest/ext/sha2/.gitignore
  28. +0 −20 lib/digest/ext/sha2/Rakefile
  29. +5 −0 lib/digest/ext/sha2/depend
  30. +11 −0 lib/digest/ext/sha2/extconf.h
  31. +24 −0 lib/digest/ext/sha2/extconf.rb
  32. +302 −0 lib/digest/hmac.rb
  33. +15 −8 rakelib/extensions.rake
View
67 lib/digest.rb
@@ -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
View
2  lib/digest/ext/.gitignore
@@ -0,0 +1,2 @@
+Makefile
+*.log
View
19 lib/digest/ext/Rakefile
@@ -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
View
2  lib/digest/ext/bubblebabble/.gitignore
@@ -0,0 +1,2 @@
+Makefile
+*.log
View
20 lib/digest/ext/bubblebabble/Rakefile
@@ -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
View
3  lib/digest/ext/bubblebabble/depend
@@ -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
View
4 lib/digest/ext/bubblebabble/extconf.h
@@ -0,0 +1,4 @@
+#ifndef EXTCONF_H
+#define EXTCONF_H
+#define HAVE_CONFIG_H 1
+#endif
View
6 lib/digest/ext/bubblebabble/extconf.rb
@@ -0,0 +1,6 @@
+require 'mkmf'
+
+$defs << "-DHAVE_CONFIG_H"
+$INCFLAGS << " -I$(srcdir)/.."
+
+create_makefile('digest/bubblebabble')
View
2  lib/digest/ext/depend
@@ -0,0 +1,2 @@
+digest.o: digest.c digest.h $(hdrdir)/ruby.h $(topdir)/config.h \
+ $(hdrdir)/defines.h $(hdrdir)/intern.h
View
3  lib/digest/ext/extconf.h
@@ -0,0 +1,3 @@
+#ifndef EXTCONF_H
+#define EXTCONF_H
+#endif
View
10 lib/digest/ext/extconf.rb
@@ -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")
View
2  lib/digest/ext/md5/.gitignore
@@ -0,0 +1,2 @@
+Makefile
+*.log
View
20 lib/digest/ext/md5/Rakefile
@@ -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
View
6 lib/digest/ext/md5/depend
@@ -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
View
6 lib/digest/ext/md5/extconf.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
View
29 lib/digest/ext/md5/extconf.rb
@@ -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")
View
2  lib/digest/ext/rmd160/.gitignore
@@ -0,0 +1,2 @@
+Makefile
+*.log
View
20 lib/digest/ext/rmd160/Rakefile
@@ -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
View
6 lib/digest/ext/rmd160/depend
@@ -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
View
7 lib/digest/ext/rmd160/extconf.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
View
28 lib/digest/ext/rmd160/extconf.rb
@@ -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")
View
2  lib/digest/ext/sha1/.gitignore
@@ -0,0 +1,2 @@
+Makefile
+*.log
View
20 lib/digest/ext/sha1/Rakefile
@@ -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
View
6 lib/digest/ext/sha1/depend
@@ -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
View
6 lib/digest/ext/sha1/extconf.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
View
28 lib/digest/ext/sha1/extconf.rb
@@ -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")
View
2  lib/digest/ext/sha2/.gitignore
@@ -0,0 +1,2 @@
+Makefile
+*.log
View
20 lib/digest/ext/sha2/Rakefile
@@ -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"
-
-sha2 = "sha2.#{$DLEXT}"
-
-file sha2 => project_files
-
-graph_dependencies sources, "./../"
-
-import dependency_file
-
-desc "Build Digest/sha2 extension"
-task :build => sha2
View
5 lib/digest/ext/sha2/depend
@@ -0,0 +1,5 @@
+sha2.o: sha2.c sha2.h $(srcdir)/../defs.h $(hdrdir)/ruby.h \
+ $(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/intern.h
+sha2init.o: sha2init.c $(srcdir)/../digest.h $(hdrdir)/ruby.h \
+ $(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/intern.h \
+ sha2.h $(srcdir)/../defs.h
View
11 lib/digest/ext/sha2/extconf.h
@@ -0,0 +1,11 @@
+#ifndef EXTCONF_H
+#define EXTCONF_H
+#define HAVE_CONFIG_H 1
+#define HAVE_SHA256_TRANSFORM 1
+#define HAVE_SHA512_TRANSFORM 1
+#define HAVE_TYPE_SHA256_CTX 1
+#define HAVE_TYPE_SHA512_CTX 1
+#define SHA2_USE_OPENSSL 1
+#define HAVE_SYS_CDEFS_H 1
+#define HAVE_TYPE_UINT64_T 1
+#endif
View
24 lib/digest/ext/sha2/extconf.rb
@@ -0,0 +1,24 @@
+# $RoughId: extconf.rb,v 1.4 2001/08/14 19:54:51 knu Exp $
+# $Id$
+
+require "mkmf"
+
+$defs << "-DHAVE_CONFIG_H"
+$INCFLAGS << " -I$(srcdir)/.."
+
+$objs = [
+ "sha2.#{$OBJEXT}",
+ "sha2init.#{$OBJEXT}",
+]
+
+have_header("sys/cdefs.h")
+
+have_header("inttypes.h")
+
+have_header("unistd.h")
+
+$preload = %w[digest]
+
+if have_type("uint64_t", "defs.h", $defs.join(' '))
+ create_makefile("digest/sha2")
+end
View
302 lib/digest/hmac.rb
@@ -0,0 +1,302 @@
+# == License
+#
+# Copyright (c) 2006 Akinori MUSHA <knu@iDaemons.org>
+#
+# Documentation by Akinori MUSHA
+#
+# All rights reserved. You can redistribute and/or modify it under
+# the same terms as Ruby.
+#
+# $Id$
+#
+
+warn "use of the experimetal library 'digest/hmac' is discouraged; require 'openssl' and use OpenSSL::HMAC instead." if $VERBOSE
+
+require 'digest'
+
+module Digest
+ # = digest/hmac.rb
+ #
+ # An experimental implementation of HMAC keyed-hashing algorithm
+ #
+ # == Overview
+ #
+ # CAUTION: Use of this library is discouraged, because this
+ # implementation was meant to be experimental but somehow got into the
+ # 1.9 series without being noticed. Please use OpenSSL::HMAC in the
+ # "openssl" library instead.
+ #
+ # == Examples
+ #
+ # require 'digest/hmac'
+ #
+ # # one-liner example
+ # puts Digest::HMAC.hexdigest("data", "hash key", Digest::SHA1)
+ #
+ # # rather longer one
+ # hmac = Digest::HMAC.new("foo", Digest::RMD160)
+ #
+ # buf = ""
+ # while stream.read(16384, buf)
+ # hmac.update(buf)
+ # end
+ #
+ # puts hmac.bubblebabble
+ #
+ class HMAC < Digest::Class
+
+ # Creates a Digest::HMAC instance.
+
+ def initialize(key, digester)
+ @md = digester.new
+
+ block_len = @md.block_length
+
+ if key.bytesize > block_len
+ key = @md.digest(key)
+ end
+
+ ipad = Array.new(block_len, 0x36)
+ opad = Array.new(block_len, 0x5c)
+
+ key.bytes.each_with_index { |c, i|
+ ipad[i] ^= c
+ opad[i] ^= c
+ }
+
+ @key = key.freeze
+ @ipad = ipad.pack('C*').freeze
+ @opad = opad.pack('C*').freeze
+ @md.update(@ipad)
+ end
+
+ def initialize_copy(other) # :nodoc:
+ @md = other.instance_eval { @md.clone }
+ end
+
+ # call-seq:
+ # hmac.update(string) -> hmac
+ # hmac << string -> hmac
+ #
+ # Updates the hmac using a given +string+ and returns self.
+ def update(text)
+ @md.update(text)
+ self
+ end
+ alias << update
+
+ # call-seq:
+ # hmac.reset -> hmac
+ #
+ # Resets the hmac to the initial state and returns self.
+ def reset
+ @md.reset
+ @md.update(@ipad)
+ self
+ end
+
+ def finish # :nodoc:
+ d = @md.digest!
+ @md.update(@opad)
+ @md.update(d)
+ @md.digest!
+ end
+ private :finish
+
+ # call-seq:
+ # hmac.digest_length -> Integer
+ #
+ # Returns the length in bytes of the hash value of the digest.
+ def digest_length
+ @md.digest_length
+ end
+
+ # call-seq:
+ # hmac.block_length -> Integer
+ #
+ # Returns the block length in bytes of the hmac.
+ def block_length
+ @md.block_length
+ end
+
+ # call-seq:
+ # hmac.inspect -> string
+ #
+ # Creates a printable version of the hmac object.
+ def inspect
+ sprintf('#<%s: key=%s, digest=%s>', self.class.name, @key.inspect, @md.inspect.sub(/^\#<(.*)>$/) { $1 });
+ end
+ end
+end
+
+if $0 == __FILE__
+ eval DATA.gets(nil), nil, $0, DATA.lineno
+end
+
+__END__
+
+require 'test/unit'
+
+module TM_HMAC
+ def test_s_hexdigest
+ cases.each { |h|
+ digesters.each { |d|
+ assert_equal(h[:hexdigest], Digest::HMAC.hexdigest(h[:data], h[:key], d))
+ }
+ }
+ end
+
+ def test_hexdigest
+ cases.each { |h|
+ digesters.each { |d|
+ hmac = Digest::HMAC.new(h[:key], d)
+
+ hmac.update(h[:data])
+
+ assert_equal(h[:hexdigest], hmac.hexdigest)
+ }
+ }
+ end
+
+ def test_reset
+ cases.each { |h|
+ digesters.each { |d|
+ hmac = Digest::HMAC.new(h[:key], d)
+ hmac.update("test")
+ hmac.reset
+ hmac.update(h[:data])
+
+ assert_equal(h[:hexdigest], hmac.hexdigest)
+ }
+ }
+ end
+end
+
+class TC_HMAC_MD5 < Test::Unit::TestCase
+ include TM_HMAC
+
+ def digesters
+ [Digest::MD5, Digest::MD5.new]
+ end
+
+ # Taken from RFC 2202: Test Cases for HMAC-MD5 and HMAC-SHA-1
+ def cases
+ [
+ {
+ :key => "\x0b" * 16,
+ :data => "Hi There",
+ :hexdigest => "9294727a3638bb1c13f48ef8158bfc9d",
+ }, {
+ :key => "Jefe",
+ :data => "what do ya want for nothing?",
+ :hexdigest => "750c783e6ab0b503eaa86e310a5db738",
+ }, {
+ :key => "\xaa" * 16,
+ :data => "\xdd" * 50,
+ :hexdigest => "56be34521d144c88dbb8c733f0e8b3f6",
+ }, {
+ :key => "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
+ :data => "\xcd" * 50,
+ :hexdigest => "697eaf0aca3a3aea3a75164746ffaa79",
+ }, {
+ :key => "\x0c" * 16,
+ :data => "Test With Truncation",
+ :hexdigest => "56461ef2342edc00f9bab995690efd4c",
+ }, {
+ :key => "\xaa" * 80,
+ :data => "Test Using Larger Than Block-Size Key - Hash Key First",
+ :hexdigest => "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd",
+ }, {
+ :key => "\xaa" * 80,
+ :data => "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
+ :hexdigest => "6f630fad67cda0ee1fb1f562db3aa53e",
+ }
+ ]
+ end
+end
+
+class TC_HMAC_SHA1 < Test::Unit::TestCase
+ include TM_HMAC
+
+ def digesters
+ [Digest::SHA1, Digest::SHA1.new]
+ end
+
+ # Taken from RFC 2202: Test Cases for HMAC-MD5 and HMAC-SHA-1
+ def cases
+ [
+ {
+ :key => "\x0b" * 20,
+ :data => "Hi There",
+ :hexdigest => "b617318655057264e28bc0b6fb378c8ef146be00",
+ }, {
+ :key => "Jefe",
+ :data => "what do ya want for nothing?",
+ :hexdigest => "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79",
+ }, {
+ :key => "\xaa" * 20,
+ :data => "\xdd" * 50,
+ :hexdigest => "125d7342b9ac11cd91a39af48aa17b4f63f175d3",
+ }, {
+ :key => "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
+ :data => "\xcd" * 50,
+ :hexdigest => "4c9007f4026250c6bc8414f9bf50c86c2d7235da",
+ }, {
+ :key => "\x0c" * 20,
+ :data => "Test With Truncation",
+ :hexdigest => "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04",
+ }, {
+ :key => "\xaa" * 80,
+ :data => "Test Using Larger Than Block-Size Key - Hash Key First",
+ :hexdigest => "aa4ae5e15272d00e95705637ce8a3b55ed402112",
+ }, {
+ :key => "\xaa" * 80,
+ :data => "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
+ :hexdigest => "e8e99d0f45237d786d6bbaa7965c7808bbff1a91",
+ }
+ ]
+ end
+end
+
+class TC_HMAC_RMD160 < Test::Unit::TestCase
+ include TM_HMAC
+
+ def digesters
+ [Digest::RMD160, Digest::RMD160.new]
+ end
+
+ # Taken from RFC 2286: Test Cases for HMAC-RIPEMD160 and HMAC-RIPEMD128
+ def cases
+ [
+ {
+ :key => "\x0b" * 20,
+ :data => "Hi There",
+ :hexdigest => "24cb4bd67d20fc1a5d2ed7732dcc39377f0a5668",
+ }, {
+ :key => "Jefe",
+ :data => "what do ya want for nothing?",
+ :hexdigest => "dda6c0213a485a9e24f4742064a7f033b43c4069",
+ }, {
+ :key => "\xaa" * 20,
+ :data => "\xdd" * 50,
+ :hexdigest => "b0b105360de759960ab4f35298e116e295d8e7c1",
+ }, {
+ :key => "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
+ :data => "\xcd" * 50,
+ :hexdigest => "d5ca862f4d21d5e610e18b4cf1beb97a4365ecf4",
+ }, {
+ :key => "\x0c" * 20,
+ :data => "Test With Truncation",
+ :hexdigest => "7619693978f91d90539ae786500ff3d8e0518e39",
+ }, {
+ :key => "\xaa" * 80,
+ :data => "Test Using Larger Than Block-Size Key - Hash Key First",
+ :hexdigest => "6466ca07ac5eac29e1bd523e5ada7605b791fd8b",
+ }, {
+ :key => "\xaa" * 80,
+ :data => "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
+ :hexdigest => "69ea60798d71616cce5fd0871e23754cd75d5a0a",
+ }
+ ]
+ end
+end
View
23 rakelib/extensions.rake
@@ -134,12 +134,19 @@ compile_ext "melbourne", :task => "rbx",
:env => melbourne_env,
:doc => "for Rubinius"
-compile_ext "digest", :dir => "#{libprefixdir}/digest/ext"
-compile_ext "digest:md5", :dir => "#{libprefixdir}/digest/ext/md5"
-compile_ext "digest:rmd160", :dir => "#{libprefixdir}/digest/ext/rmd160"
-compile_ext "digest:sha1", :dir => "#{libprefixdir}/digest/ext/sha1"
-compile_ext "digest:sha2", :dir => "#{libprefixdir}/digest/ext/sha2"
-compile_ext "digest:bubblebabble", :dir => "#{libprefixdir}/digest/ext/bubblebabble"
+compile_ext "digest", :deps => ["Makefile", "extconf.rb"],
+ :dir => "#{libprefixdir}/digest/ext"
+
+compile_ext "digest:md5", :deps => ["Makefile", "extconf.rb"],
+ :dir => "#{libprefixdir}/digest/ext/md5"
+compile_ext "digest:rmd160", :deps => ["Makefile", "extconf.rb"],
+ :dir => "#{libprefixdir}/digest/ext/rmd160"
+compile_ext "digest:sha1", :deps => ["Makefile", "extconf.rb"],
+ :dir => "#{libprefixdir}/digest/ext/sha1"
+compile_ext "digest:sha2", :deps => ["Makefile", "extconf.rb"],
+ :dir => "#{libprefixdir}/digest/ext/sha2"
+compile_ext "digest:bubblebabble", :deps => ["Makefile", "extconf.rb"],
+ :dir => "#{libprefixdir}/digest/ext/bubblebabble"
if enabled_18
compile_ext "18/bigdecimal", :dir => "#{libprefixdir}/18/bigdecimal/ext", :env => "-X18"
@@ -149,8 +156,8 @@ if enabled_18
if BUILD_CONFIG[:readline] == :c_readline
compile_ext "18/readline", :dir => "#{libprefixdir}/18/readline/ext",
- :deps => ["Makefile", "extconf.rb"],
- :env => "-X18"
+ :deps => ["Makefile", "extconf.rb"],
+ :env => "-X18"
end
# rbx must be able to run to build these because they use
Please sign in to comment.
Something went wrong with that request. Please try again.