mirror of
https://github.com/ruby/ruby.git
synced 2025-09-20 02:53:57 +02:00

Import current master (2c43241dc0ed) of ruby/openssl.git.
Below are the commits that were made since the last batch at commit
b99775b163
(ruby/openssl.git commit f49e7110ca1e). Note that some of
them have been applied already.
----------------------------------------------------------------
Benoit Daloze (1):
Remove redundant and ignored workflow file
DBL-Lee (1):
add support for SHA512_256/SHA512_224
Hiroshi SHIBATA (2):
Guard for OpenSSL::PKey::EC::Group::Error with unsupported platforms
Fixed inconsistency directory structure with ruby/ruby repo
Jeremy Evans (2):
Fix keyword argument separation issues in OpenSSL::SSL::SSLSocket#sys{read,write}_nonblock
Remove taint support
Kazuki Yamaguchi (26):
config: support .include directive
random: make OpenSSL::Random.pseudo_bytes alias of .random_bytes
extconf.rb: get rid of -Werror=deprecated-declarations
test/openssl/test_ssl: skip test_fallback_scsv if necessary
ts: simplify OpenSSL::Timestamp::Request#algorithm
History.md: add missing references to GitHub issues
config: deprecate OpenSSL::Config#add_value and #[]=
test/openssl/test_ssl: remove sleep from test_finished_messages
test/openssl/test_ssl: fix random failure in SSLSocket.open test
test/openssl/test_ssl: avoid explicitly-sized private keys
test/openssl/test_ssl: remove commented-out test case
test/openssl/test_ssl: allow kRSA tests to fail
ssl: avoid declarations after statements
engine: revert OpenSSL::Engine.load changes for cloudhsm
engine: remove really outdated static engines
engine: do not check for ENGINE_load_builtin_engines()
engine: fix guards for 'dynamic' and 'cryptodev' engines
lib/openssl.rb: require openssl/version.rb
x509: add error code and verify flags constants
ssl: set verify error code in the case of verify_hostname failure
.github/workflows: merge CI jobs into a single workflow
.github/workflows: test against different OpenSSL versions
.travis.yml: fully migrate to GitHub Actions
ssl: suppress test failure with SSLContext#add_certificate_chain_file
ssl: remove test case test_puts_meta from test_pair
Revert "Use version.rb in gemspec"
MSP-Greg (2):
.travis.yml - remove 2.3/1.0.2, 2.5/1.1.1, head/1.0.2
Use version.rb in gemspec
Samuel Williams (1):
Restore compatibility with older versions of Ruby.
Yusuke Endoh (1):
Make OpenSSL::OSSL#test_memcmp_timing robust
84 lines
2 KiB
Ruby
84 lines
2 KiB
Ruby
# frozen_string_literal: true
|
|
#--
|
|
# = Ruby-space predefined Digest subclasses
|
|
#
|
|
# = Info
|
|
# 'OpenSSL for Ruby 2' project
|
|
# Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
# All rights reserved.
|
|
#
|
|
# = Licence
|
|
# This program is licensed under the same licence as Ruby.
|
|
# (See the file 'LICENCE'.)
|
|
#++
|
|
|
|
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.
|
|
#
|
|
# === Examples
|
|
#
|
|
# OpenSSL::Digest.digest("SHA256", "abc")
|
|
#
|
|
# which is equivalent to:
|
|
#
|
|
# OpenSSL::Digest::SHA256.digest("abc")
|
|
|
|
def self.digest(name, data)
|
|
super(data, name)
|
|
end
|
|
|
|
ALGORITHMS.each do |name|
|
|
klass = Class.new(self) {
|
|
define_method(:initialize, ->(data = nil) {super(name, data)})
|
|
}
|
|
|
|
singleton = (class << klass; self; end)
|
|
|
|
singleton.class_eval{
|
|
define_method(:digest) {|data| new.digest(data)}
|
|
define_method(:hexdigest) {|data| new.hexdigest(data)}
|
|
}
|
|
|
|
const_set(name.tr('-', '_'), klass)
|
|
end
|
|
|
|
# Deprecated.
|
|
#
|
|
# This class is only provided for backwards compatibility.
|
|
# Use OpenSSL::Digest instead.
|
|
class Digest < Digest; end # :nodoc:
|
|
deprecate_constant :Digest
|
|
|
|
end # Digest
|
|
|
|
# Returns a Digest subclass by _name_
|
|
#
|
|
# require 'openssl'
|
|
#
|
|
# OpenSSL::Digest("MD5")
|
|
# # => OpenSSL::Digest::MD5
|
|
#
|
|
# Digest("Foo")
|
|
# # => NameError: wrong constant name Foo
|
|
|
|
def Digest(name)
|
|
OpenSSL::Digest.const_get(name)
|
|
end
|
|
|
|
module_function :Digest
|
|
|
|
end # OpenSSL
|