Skip to content

Commit

Permalink
* ext/openssl/ossl_digest.c (GetDigestPtr): Allow to pass the
Browse files Browse the repository at this point in the history
  OpenSSL::Digest class in place of where either an instance of
  the class or the algorithm name was demanded.  For example,
  OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1, key, data) is now
  accepted as well as the usual
  OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, key, data) and
  OpenSSL::HMAC.digest("SHA1", key, data).




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
knu committed Feb 23, 2010
1 parent 3cd6a65 commit eb845be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Wed Feb 24 00:50:09 2010 Akinori MUSHA <[email protected]>

* ext/openssl/ossl_digest.c (GetDigestPtr): Allow to pass the
OpenSSL::Digest class in place of where either an instance of
the class or the algorithm name was demanded. For example,
OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1, key, data) is now
accepted as well as the usual
OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, key, data) and
OpenSSL::HMAC.digest("SHA1", key, data).

Wed Feb 24 00:39:17 2010 Yusuke Endoh <[email protected]>

* string.c (str_new_empty): String#split, partition, rpartition
Expand Down
19 changes: 13 additions & 6 deletions ext/openssl/ossl_digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,25 @@ GetDigestPtr(VALUE obj)
{
const EVP_MD *md;

if (TYPE(obj) == T_STRING) {
const char *name = StringValueCStr(obj);
if (TYPE(obj) == T_CLASS) {
EVP_MD_CTX *ctx;
VALUE digest = rb_funcall(obj, rb_intern("new"), 0, 0);

md = EVP_get_digestbyname(name);
if (!md)
ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%s).", name);
} else {
SafeGetDigest(digest, ctx);

md = EVP_MD_CTX_md(ctx);
} else if (rb_obj_is_kind_of(obj, cDigest)) {
EVP_MD_CTX *ctx;

SafeGetDigest(obj, ctx);

md = EVP_MD_CTX_md(ctx);
} else {
const char *name = StringValueCStr(obj);

md = EVP_get_digestbyname(name);
if (!md)
ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%s).", name);
}

return md;
Expand Down

0 comments on commit eb845be

Please sign in to comment.