Feature #6819
OpenSSL::Digest.new should return an instance of the chosen subclass
Description
=begin
(({OpenSSL::Digest.new})) allows you to create a digest given the digest name:
digester = OpenSSL::Digest.new "SHA1"
digester.update "hello"
# …
The digester returned is of class (({OpenSSL::Digest})) regardless of the input type.
I would like this changed so that it returns the specific subclass of (({OpenSSL::Digest})):
digester = OpenSSL::Digest.new "SHA1"
digester.class #=> OpenSSL::Digest::SHA1
When multiple digests are created this makes it easier to distinguish the type of digest you are working with.
This will also make (({OpenSSL::Digest.new})) behave similarly to (({Digest})):
digester = Digest("SHA1").new
digester.class #=> Digest::SHA1
=end
Associated revisions
- ext/openssl/lib/openssl/digest.rb test/openssl/test_digest.rb: Add Digest module function to OpenSSL module and test it. Patch provided by Eric Hodel. [Feature #6819]
- ext/openssl/lib/openssl/digest.rb test/openssl/test_digest.rb: Add Digest module function to OpenSSL module and test it. Patch provided by Eric Hodel. [Feature #6819]
- ext/openssl/lib/openssl/digest.rb test/openssl/test_digest.rb: Add Digest module function to OpenSSL module and test it. Patch provided by Eric Hodel. [Feature #6819]
- ext/openssl/lib/openssl/digest.rb test/openssl/test_digest.rb: Add Digest module function to OpenSSL module and test it. Patch provided by Eric Hodel. [Feature #6819]
- ext/openssl/lib/openssl/digest.rb test/openssl/test_digest.rb: Add Digest module function to OpenSSL module and test it. Patch provided by Eric Hodel. [Feature #6819]
History
#1
[ruby-core:46910]
Updated by nobu (Nobuyoshi Nakada) over 5 years ago
=begin
--- drbrain (Eric Hodel) wrote:
I would like this changed so that it returns the specific subclass of OpenSSL::Digest:
digester = OpenSSL::Digest.new "SHA1" digester.class #=> OpenSSL::Digest::SHA1
It sounds like quite exceptional.
Rather I'd suggest (({OpenSSL.Digest()})) method as well as (({Digest()})), or new similar class method.
--- drbrain (Eric Hodel) wrote:
This will also make OpenSSL::Digest.new behave similarly to Digest:
digester = Digest("SHA1").new digester.class #=> Digest::SHA1
It differs than your proposal.
=end
#2
[ruby-core:46911]
Updated by nobu (Nobuyoshi Nakada) over 5 years ago
- Description updated (diff)
#3
[ruby-core:46920]
Updated by drbrain (Eric Hodel) over 5 years ago
I agree. I have attached a patch to implement your suggestion.
#4
Updated by Anonymous over 5 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r36592.
Eric, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- ext/openssl/lib/openssl/digest.rb test/openssl/test_digest.rb: Add Digest module function to OpenSSL module and test it. Patch provided by Eric Hodel. [Feature #6819]
#5
[ruby-core:46923]
Updated by MartinBosslet (Martin Bosslet) over 5 years ago
drbrain (Eric Hodel) wrote:
I agree. I have attached a patch to implement your suggestion.
Thanks to both of you!
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e