summaryrefslogtreecommitdiffstats
path: root/ext/openssl/ossl_digest.c
diff options
context:
space:
mode:
authorknu <knu@ruby-lang.org>2010-02-23 15:51:01 +0000
committerknu <knu@ruby-lang.org>2010-02-23 15:51:01 +0000
commit09e7f888190e5c1c70b4fc935a5c15e5fbf63f40 (patch)
treeb0ac3a9ad8f541593b6313a21dc3dce9dbb2a99a /ext/openssl/ossl_digest.c
parentaa019e87a6b5137f54ac6505dd37ea40fdf533ae (diff)
downloadruby-openssl-history-09e7f888190e5c1c70b4fc935a5c15e5fbf63f40.tar.gz
* 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). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl_digest.c')
-rw-r--r--ext/openssl/ossl_digest.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/ext/openssl/ossl_digest.c b/ext/openssl/ossl_digest.c
index 9b8ced5..3047891 100644
--- a/ext/openssl/ossl_digest.c
+++ b/ext/openssl/ossl_digest.c
@@ -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;