Project

General

Profile

Feature #6819 ยป openssl.digest.module_function.patch

drbrain (Eric Hodel), 08/02/2012 07:30 AM

View differences:

ext/openssl/lib/openssl/digest.rb (working copy)
68 68
    end
69 69

  
70 70
  end # Digest
71

  
72
  # Returns a Digest subclass by +name+.
73
  #
74
  #   require 'openssl'
75
  #
76
  #   OpenSSL::Digest("MD5")
77
  #   # => OpenSSL::Digest::MD5
78
  #
79
  #   Digest("Foo")
80
  #   # => NameError: wrong constant name Foo
81

  
82
  def Digest(name)
83
    OpenSSL::Digest.const_get(name)
84
  end
85

  
86
  module_function :Digest
87

  
71 88
end # OpenSSL
72 89

  
test/openssl/test_digest.rb (working copy)
103 103
    end
104 104
  end
105 105

  
106
  def test_openssl_digest
107
    assert_equal OpenSSL::Digest::MD5, OpenSSL::Digest("MD5")
108

  
109
    assert_raises NameError do
110
      OpenSSL::Digest("no such digest")
111
    end
112
  end
113

  
106 114
  private
107 115

  
108 116
  def check_digest(oid)