From 0b2c70eaa1e8e41fcb6332b22b084dabb81e637c Mon Sep 17 00:00:00 2001 From: Bart de Water Date: Sun, 19 Apr 2020 11:14:36 -0400 Subject: [ruby/openssl] Look up digest by name instead of constant https://github.com/ruby/openssl/commit/b28fb2f05c --- ext/openssl/lib/openssl.rb | 4 ++-- ext/openssl/lib/openssl/digest.rb | 15 ++------------- 2 files changed, 4 insertions(+), 15 deletions(-) (limited to 'ext/openssl/lib') diff --git a/ext/openssl/lib/openssl.rb b/ext/openssl/lib/openssl.rb index 00e2db1f40..b047485785 100644 --- a/ext/openssl/lib/openssl.rb +++ b/ext/openssl/lib/openssl.rb @@ -31,8 +31,8 @@ module OpenSSL # the length of the secret. Returns +true+ if the strings are identical, # +false+ otherwise. def self.secure_compare(a, b) - hashed_a = OpenSSL::Digest::SHA256.digest(a) - hashed_b = OpenSSL::Digest::SHA256.digest(b) + hashed_a = OpenSSL::Digest.digest('SHA256', a) + hashed_b = OpenSSL::Digest.digest('SHA256', b) OpenSSL.fixed_length_secure_compare(hashed_a, hashed_b) && a == b end end diff --git a/ext/openssl/lib/openssl/digest.rb b/ext/openssl/lib/openssl/digest.rb index 92d358d241..2ff8398e44 100644 --- a/ext/openssl/lib/openssl/digest.rb +++ b/ext/openssl/lib/openssl/digest.rb @@ -15,17 +15,6 @@ module OpenSSL class Digest - # You can get a list of all algorithms: - # openssl list -digest-algorithms - - ALGORITHMS = %w(MD4 MD5 RIPEMD160 SHA1 SHA224 SHA256 SHA384 SHA512) - - if !OPENSSL_VERSION.include?("LibreSSL") && OPENSSL_VERSION_NUMBER > 0x10101000 - ALGORITHMS.concat %w(BLAKE2b512 BLAKE2s256 SHA3-224 SHA3-256 SHA3-384 SHA3-512 SHA512-224 SHA512-256) - end - - ALGORITHMS.freeze - # Return the hash value computed with _name_ Digest. _name_ is either the # long name or short name of a supported digest algorithm. # @@ -35,13 +24,13 @@ module OpenSSL # # which is equivalent to: # - # OpenSSL::Digest::SHA256.digest("abc") + # OpenSSL::Digest.digest('SHA256', "abc") def self.digest(name, data) super(data, name) end - ALGORITHMS.each do |name| + %w(MD4 MD5 RIPEMD160 SHA1 SHA224 SHA256 SHA384 SHA512).each do |name| klass = Class.new(self) { define_method(:initialize, ->(data = nil) {super(name, data)}) } -- cgit v1.2.3