Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate OpenSSL::Digest and OpenSSL::Cipher constants #366

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions History.md
Expand Up @@ -9,6 +9,9 @@ Compatibility notes
[[GitHub #266]](https://github.com/ruby/openssl/pull/266)
* Deprecate `OpenSSL::Config#add_value` and `#[]=` for future removal.
[[GitHub #322]](https://github.com/ruby/openssl/pull/322)
* Deprecate algorithmic constants for `OpenSSL::Cipher` and `OpenSSL::Digest`
for future removal.
[[GitHub #366]](https://github.com/ruby/openssl/pull/366)


Notable changes
Expand Down
7 changes: 6 additions & 1 deletion lib/openssl/cipher.rb
Expand Up @@ -22,6 +22,8 @@ class Cipher
}
}
const_set(name, klass)
deprecate_constant(name)
klass
}

%w(128 192 256).each{|keylen|
Expand All @@ -30,7 +32,10 @@ class Cipher
super("aes-#{keylen}-#{mode}".downcase)
}
}
const_set("AES#{keylen}", klass)
name = "AES#{keylen}"
const_set(name, klass)
deprecate_constant(name)
klass
}

# call-seq:
Expand Down
7 changes: 5 additions & 2 deletions lib/openssl/digest.rb
Expand Up @@ -24,7 +24,7 @@ class Digest
#
# which is equivalent to:
#
# OpenSSL::Digest.digest('SHA256', "abc")
# OpenSSL::Digest.new("SHA256").digest("abc")

def self.digest(name, data)
super(data, name)
Expand All @@ -42,7 +42,10 @@ def self.digest(name, data)
define_method(:hexdigest) {|data| new.hexdigest(data)}
}

const_set(name.tr('-', '_'), klass)
constant_name = name.tr('-', '_')
const_set(constant_name, klass)
deprecate_constant(constant_name)
klass
end

# Deprecated.
Expand Down
20 changes: 7 additions & 13 deletions test/openssl/test_digest.rb
Expand Up @@ -7,7 +7,7 @@ class OpenSSL::TestDigest < OpenSSL::TestCase
def setup
super
@d1 = OpenSSL::Digest.new("MD5")
@d2 = OpenSSL::Digest::MD5.new
@d2 = EnvUtil.suppress_warning { OpenSSL::Digest::MD5.new }
end

def test_digest
Expand Down Expand Up @@ -54,10 +54,12 @@ def test_reset
end

def test_digest_constants
%w{MD4 MD5 RIPEMD160 SHA1 SHA224 SHA256 SHA384 SHA512}.each do |name|
assert_not_nil(OpenSSL::Digest.new(name))
klass = OpenSSL::Digest.const_get(name.tr('-', '_'))
assert_not_nil(klass.new)
EnvUtil.suppress_warning do
%w{MD4 MD5 RIPEMD160 SHA1 SHA224 SHA256 SHA384 SHA512}.each do |name|
assert_not_nil(OpenSSL::Digest.new(name))
klass = OpenSSL::Digest.const_get(name.tr('-', '_'))
assert_not_nil(klass.new)
end
end
end

Expand Down Expand Up @@ -118,14 +120,6 @@ def test_digest_by_oid_and_name_sha2
check_digest(OpenSSL::ASN1::ObjectId.new("SHA512"))
end

def test_openssl_digest
assert_equal OpenSSL::Digest::MD5, OpenSSL::Digest("MD5")

assert_raise NameError do
OpenSSL::Digest("no such digest")
end
end

private

def check_digest(oid)
Expand Down
3 changes: 0 additions & 3 deletions test/openssl/test_ossl.rb
Expand Up @@ -11,9 +11,6 @@ def test_fixed_length_secure_compare
assert_raise(ArgumentError) { OpenSSL.fixed_length_secure_compare("aaa", "aa") }

assert OpenSSL.fixed_length_secure_compare("aaa", "aaa")
assert OpenSSL.fixed_length_secure_compare(
OpenSSL::Digest.digest('SHA256', "aaa"), OpenSSL::Digest::SHA256.digest("aaa")
)

assert_raise(ArgumentError) { OpenSSL.fixed_length_secure_compare("aaa", "aaaa") }
refute OpenSSL.fixed_length_secure_compare("aaa", "baa")
Expand Down
2 changes: 1 addition & 1 deletion test/openssl/test_pkcs7.rb
Expand Up @@ -117,7 +117,7 @@ def test_detached_sign

def test_enveloped
certs = [@ee1_cert, @ee2_cert]
cipher = OpenSSL::Cipher::AES.new("128-CBC")
cipher = OpenSSL::Cipher.new("AES-128-CBC")
data = "aaaaa\nbbbbb\nccccc\n"

tmp = OpenSSL::PKCS7.encrypt(certs, data, cipher, OpenSSL::PKCS7::BINARY)
Expand Down