diff options
author | Michal Rokos <m.rokos@sh.cvut.cz> | 2002-02-13 13:09:26 +0000 |
---|---|---|
committer | Michal Rokos <m.rokos@sh.cvut.cz> | 2002-02-13 13:09:26 +0000 |
commit | 5e2a679a46e2164f8b38b71132787c3327862957 (patch) | |
tree | 4ab99602f4f8adec2a96194abd4a39c48e0fab00 /ossl_hmac.c | |
parent | 1ad093352e953cabd70c851989ce06edc233d5f4 (diff) | |
download | ruby-openssl-history-5e2a679a46e2164f8b38b71132787c3327862957.tar.gz |
* transition from rb_raise to OSSL_Raise (where possible)
* some mem checks
* preliminary DH key support
Diffstat (limited to 'ossl_hmac.c')
-rw-r--r-- | ossl_hmac.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/ossl_hmac.c b/ossl_hmac.c index 4999e99..43d9a45 100644 --- a/ossl_hmac.c +++ b/ossl_hmac.c @@ -1,7 +1,7 @@ /* * $Id$ * 'OpenSSL for Ruby' project - * Copyright (C) 2001 Michal Rokos <m.rokos@sh.cvut.cz> + * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz> * All rights reserved. */ /* @@ -74,9 +74,8 @@ ossl_hmac_initialize(int argc, VALUE *argv, VALUE self) md = ossl_digest_get_EVP_MD(digest); if (!(hmacp->hmac = OPENSSL_malloc(sizeof(HMAC_CTX)))) { - rb_raise(eHMACError, "%s", ossl_error()); + OSSL_Raise(eHMACError, ""); } - HMAC_Init(hmacp->hmac, RSTRING(key)->ptr, RSTRING(key)->len, md); return self; @@ -108,11 +107,10 @@ ossl_hmac_hmac(VALUE self) GetHMAC(self, hmacp); if (!HMAC_CTX_copy(&final, hmacp->hmac)) { - rb_raise(eHMACError, "%s", ossl_error()); + OSSL_Raise(eHMACError, ""); } - if (!(buf = OPENSSL_malloc(HMAC_size(&final)))) { - rb_raise(eHMACError, "Cannot allocate memory for hmac"); + OSSL_Raise(eHMACError, "Cannot allocate memory for hmac"); } HMAC_Final(&final, buf, &buf_len); @@ -135,23 +133,25 @@ ossl_hmac_hexhmac(VALUE self) GetHMAC(self, hmacp); if (!HMAC_CTX_copy(&final, hmacp->hmac)) { - rb_raise(eHMACError, "%s", ossl_error()); + OSSL_Raise(eHMACError, "Cannot copy HMAC CTX"); } - if (!(buf = OPENSSL_malloc(HMAC_size(&final)))) { - rb_raise(eHMACError, "Cannot allocate memory for hmac"); + OSSL_Raise(eHMACError, "Cannot allocate memory for hmac"); } HMAC_Final(&final, buf, &buf_len); if (!(hexbuf = OPENSSL_malloc(2*buf_len+1))) { - rb_raise(eHMACError, "Memory alloc error"); + OPENSSL_free(buf); + OSSL_Raise(eHMACError, "Memory alloc error"); } for (i = 0; i < buf_len; i++) { hexbuf[i + i] = hex[((unsigned char)buf[i]) >> 4]; hexbuf[i + i + 1] = hex[buf[i] & 0x0f]; } hexbuf[i + i] = '\0'; + str = rb_str_new(hexbuf, 2*buf_len); + OPENSSL_free(buf); OPENSSL_free(hexbuf); |