summaryrefslogtreecommitdiff
path: root/ext/openssl/ossl_digest.c
diff options
context:
space:
mode:
authorrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-29 05:47:09 +0000
committerrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-29 05:47:09 +0000
commitc9dc0164b8ad1cb23faf6120749bcc349a7bfd45 (patch)
tree831281099f54c0be80293785761a46688a0711f3 /ext/openssl/ossl_digest.c
parent28bf4d545fb7674fcdc99c93ba7476d320551d11 (diff)
import Ruby/OpenSSL 2.0.0.beta.1
* NEWS, {ext,test,sample}/openssl: Import Ruby/OpenSSL 2.0.0.beta.1. ext/openssl is now converted into a default gem. The full commit history since r55538 can be found at: https://github.com/ruby/openssl/compare/08e1881f5663...v2.0.0.beta.1 [Feature #9612] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl_digest.c')
-rw-r--r--ext/openssl/ossl_digest.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/ext/openssl/ossl_digest.c b/ext/openssl/ossl_digest.c
index d137dc5..44d9618 100644
--- a/ext/openssl/ossl_digest.c
+++ b/ext/openssl/ossl_digest.c
@@ -111,17 +111,16 @@ VALUE ossl_digest_update(VALUE, VALUE);
*
* Creates a Digest instance based on +string+, which is either the ln
* (long name) or sn (short name) of a supported digest algorithm.
+ *
* If +data+ (a +String+) is given, it is used as the initial input to the
* Digest instance, i.e.
+ *
* digest = OpenSSL::Digest.new('sha256', 'digestdata')
+ *
* is equal to
+ *
* digest = OpenSSL::Digest.new('sha256')
* digest.update('digestdata')
- *
- * === Example
- * digest = OpenSSL::Digest.new('sha1')
- *
- *
*/
static VALUE
ossl_digest_initialize(int argc, VALUE *argv, VALUE self)
@@ -203,7 +202,9 @@ ossl_digest_update(VALUE self, VALUE data)
StringValue(data);
GetDigest(self, ctx);
- EVP_DigestUpdate(ctx, RSTRING_PTR(data), RSTRING_LEN(data));
+
+ if (!EVP_DigestUpdate(ctx, RSTRING_PTR(data), RSTRING_LEN(data)))
+ ossl_raise(eDigestError, "EVP_DigestUpdate");
return self;
}
@@ -218,19 +219,21 @@ ossl_digest_finish(int argc, VALUE *argv, VALUE self)
{
EVP_MD_CTX *ctx;
VALUE str;
-
- rb_scan_args(argc, argv, "01", &str);
+ int out_len;
GetDigest(self, ctx);
+ rb_scan_args(argc, argv, "01", &str);
+ out_len = EVP_MD_CTX_size(ctx);
if (NIL_P(str)) {
- str = rb_str_new(NULL, EVP_MD_CTX_size(ctx));
+ str = rb_str_new(NULL, out_len);
} else {
StringValue(str);
- rb_str_resize(str, EVP_MD_CTX_size(ctx));
+ rb_str_resize(str, out_len);
}
- EVP_DigestFinal_ex(ctx, (unsigned char *)RSTRING_PTR(str), NULL);
+ if (!EVP_DigestFinal_ex(ctx, (unsigned char *)RSTRING_PTR(str), NULL))
+ ossl_raise(eDigestError, "EVP_DigestFinal_ex");
return str;
}
@@ -239,7 +242,7 @@ ossl_digest_finish(int argc, VALUE *argv, VALUE self)
* call-seq:
* digest.name -> string
*
- * Returns the sn of this Digest instance.
+ * Returns the sn of this Digest algorithm.
*
* === Example
* digest = OpenSSL::Digest::SHA512.new
@@ -310,7 +313,8 @@ Init_ossl_digest(void)
rb_require("digest");
#if 0
- mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL */
+ mOSSL = rb_define_module("OpenSSL");
+ eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
#endif
/* Document-class: OpenSSL::Digest