ext/rubysl/openssl/ossl_pkey.c in rubysl-openssl-2.4.0 vs ext/rubysl/openssl/ossl_pkey.c in rubysl-openssl-2.5.0

- old
+ new

@@ -1,13 +1,12 @@ /* - * $Id: ossl_pkey.c 48806 2014-12-12 23:19:07Z nobu $ * 'OpenSSL for Ruby' project * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz> * All rights reserved. */ /* - * This program is licenced under the same licence as Ruby. + * This program is licensed under the same licence as Ruby. * (See the file 'LICENCE'.) */ #include "ossl.h" /* @@ -197,11 +196,11 @@ EVP_PKEY * GetPrivPKeyPtr(VALUE obj) { EVP_PKEY *pkey; - if (rb_funcall(obj, id_private_q, 0, NULL) != Qtrue) { + if (rb_funcallv(obj, id_private_q, 0, NULL) != Qtrue) { ossl_raise(rb_eArgError, "Private key is needed."); } SafeGetPKey(obj, pkey); return pkey; @@ -221,11 +220,11 @@ EVP_PKEY * DupPrivPKeyPtr(VALUE obj) { EVP_PKEY *pkey; - if (rb_funcall(obj, id_private_q, 0, NULL) != Qtrue) { + if (rb_funcallv(obj, id_private_q, 0, NULL) != Qtrue) { ossl_raise(rb_eArgError, "Private key is needed."); } SafeGetPKey(obj, pkey); CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); @@ -239,14 +238,15 @@ ossl_pkey_alloc(VALUE klass) { EVP_PKEY *pkey; VALUE obj; + obj = NewPKey(klass); if (!(pkey = EVP_PKEY_new())) { ossl_raise(ePKeyError, NULL); } - WrapPKey(klass, obj, pkey); + SetPKey(obj, pkey); return obj; } /* @@ -287,20 +287,23 @@ { EVP_PKEY *pkey; EVP_MD_CTX ctx; unsigned int buf_len; VALUE str; + int result; - if (rb_funcall(self, id_private_q, 0, NULL) != Qtrue) { + if (rb_funcallv(self, id_private_q, 0, NULL) != Qtrue) { ossl_raise(rb_eArgError, "Private key is needed."); } GetPKey(self, pkey); EVP_SignInit(&ctx, GetDigestPtr(digest)); StringValue(data); EVP_SignUpdate(&ctx, RSTRING_PTR(data), RSTRING_LEN(data)); str = rb_str_new(0, EVP_PKEY_size(pkey)+16); - if (!EVP_SignFinal(&ctx, (unsigned char *)RSTRING_PTR(str), &buf_len, pkey)) + result = EVP_SignFinal(&ctx, (unsigned char *)RSTRING_PTR(str), &buf_len, pkey); + EVP_MD_CTX_cleanup(&ctx); + if (!result) ossl_raise(ePKeyError, NULL); assert((long)buf_len <= RSTRING_LEN(str)); rb_str_set_len(str, buf_len); return str; @@ -448,6 +451,5 @@ Init_ossl_rsa(); Init_ossl_dsa(); Init_ossl_dh(); Init_ossl_ec(); } -