--mimepart_4d6145368b89f_1dc2ae2d38a32047
Content-Type: text/plain
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline

Feature #4412: [ext/openssl] Create Digest by OID
http://redmine.ruby-lang.org/issues/show/4412

Author: Martin Bosslet
Status: Open, Priority: Normal
Category: ext, Target version: 1.9.3

Currently it is not possible to create a Digest instance by using he OID instead of the name (sn or ln).

oid = OpenSSL::ASN1::ObjectId.new('SHA1')
digest = OpenSSL::ASN1::Digest.new(oid.oid)

=> Unsupported digest algorithm (1.3.14.3.2.26).

This is counter-intuitive, since the only thing that is always
available in the case of object identifiers is the numeric oid,
sn or ln are not always present. Since sn and ln are also quite
error-prone (spelling), I'd like to suggest to have all three possibilities
for instantiating a Digest: by sn, by ln and by oid.

I included a patch and a test to support this behaviour.

Regards,
Martin


----------------------------------------
http://redmine.ruby-lang.org

--mimepart_4d6145368b89f_1dc2ae2d38a32047
Content-Type: text/x-patch; name=digest_by_oid.diff
Content-Transfer-Encoding: Base64
Content-Disposition: attachment; filename=digest_by_oid.diff

SW5kZXg6IHJ1YnkvZXh0L29wZW5zc2wvb3NzbF9kaWdlc3QuYwo9PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09Ci0tLSBydWJ5L2V4dC9vcGVuc3NsL29zc2xfZGln
ZXN0LmMJKFJldmlzaW9uIDMwOTI3KQorKysgcnVieS9leHQvb3BlbnNzbC9v
c3NsX2RpZ2VzdC5jCShBcmJlaXRza29waWUpCkBAIC0zNiwxMSArMzYsMTUg
QEAKIEdldERpZ2VzdFB0cihWQUxVRSBvYmopCiB7CiAgICAgY29uc3QgRVZQ
X01EICptZDsKKyAgICBBU04xX09CSkVDVCAqb2lkID0gTlVMTDsKIAogICAg
IGlmIChUWVBFKG9iaikgPT0gVF9TVFJJTkcpIHsKICAgICAJY29uc3QgY2hh
ciAqbmFtZSA9IFN0cmluZ1ZhbHVlQ1N0cihvYmopOwogCi0gICAgIC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