commit 2b84a32fc1f5dc3648bf088a6d85110c1b448f5c Author: Jared Jennings Date: Thu Mar 27 16:11:59 2014 -0500 expect digest init and finish functions to indicate success or failure; raise exception on failure diff --git a/ext/digest/digest.c b/ext/digest/digest.c index 951f73d..5b82635 100644 --- a/ext/digest/digest.c +++ b/ext/digest/digest.c @@ -520,7 +520,7 @@ get_digest_base_metadata(VALUE klass) Data_Get_Struct(obj, rb_digest_metadata_t, algo); switch (algo->api_version) { - case 2: + case 3: break; /* @@ -548,7 +548,9 @@ rb_digest_base_alloc(VALUE klass) algo = get_digest_base_metadata(klass); pctx = xmalloc(algo->ctx_size); - algo->init_func(pctx); + if (algo->init_func(pctx) != 1) { + rb_raise(rb_eRuntimeError, "Digest initialization failed."); + } obj = Data_Wrap_Struct(klass, 0, xfree, pctx); @@ -586,7 +588,9 @@ rb_digest_base_reset(VALUE self) Data_Get_Struct(self, void, pctx); - algo->init_func(pctx); + if (algo->init_func(pctx) != 1) { + rb_raise(rb_eRuntimeError, "Digest initialization failed."); + } return self; } @@ -624,7 +628,9 @@ rb_digest_base_finish(VALUE self) algo->finish_func(pctx, (unsigned char *)RSTRING_PTR(str)); /* avoid potential coredump caused by use of a finished context */ - algo->init_func(pctx); + if (algo->init_func(pctx) != 1) { + rb_raise(rb_eRuntimeError, "Digest initialization failed."); + } return str; } diff --git a/ext/digest/digest.h b/ext/digest/digest.h index 89b26d8..56b7566 100644 --- a/ext/digest/digest.h +++ b/ext/digest/digest.h @@ -15,11 +15,11 @@ #include "ruby.h" -#define RUBY_DIGEST_API_VERSION 2 +#define RUBY_DIGEST_API_VERSION 3 -typedef void (*rb_digest_hash_init_func_t)(void *); +typedef int (*rb_digest_hash_init_func_t)(void *); typedef void (*rb_digest_hash_update_func_t)(void *, unsigned char *, size_t); -typedef void (*rb_digest_hash_finish_func_t)(void *, unsigned char *); +typedef int (*rb_digest_hash_finish_func_t)(void *, unsigned char *); typedef struct { int api_version;