mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
ossl_digest.c: typed data
* ext/openssl/ossl_digest.c (ossl_digest_type): use typed data. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48791 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0ae6db41ca
commit
cfa7024e25
1 changed files with 16 additions and 2 deletions
|
@ -11,7 +11,7 @@
|
|||
#include "ossl.h"
|
||||
|
||||
#define GetDigest(obj, ctx) do { \
|
||||
Data_Get_Struct((obj), EVP_MD_CTX, (ctx)); \
|
||||
TypedData_Get_Struct((obj), EVP_MD_CTX, &ossl_digest_type, (ctx)); \
|
||||
if (!(ctx)) { \
|
||||
ossl_raise(rb_eRuntimeError, "Digest CTX wasn't initialized!"); \
|
||||
} \
|
||||
|
@ -29,6 +29,20 @@ VALUE eDigestError;
|
|||
|
||||
static VALUE ossl_digest_alloc(VALUE klass);
|
||||
|
||||
static void
|
||||
ossl_digest_free(void *ctx)
|
||||
{
|
||||
EVP_MD_CTX_destroy(ctx);
|
||||
}
|
||||
|
||||
static const rb_data_type_t ossl_digest_type = {
|
||||
"OpenSSL/Digest",
|
||||
{
|
||||
0, ossl_digest_free,
|
||||
},
|
||||
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
||||
};
|
||||
|
||||
/*
|
||||
* Public
|
||||
*/
|
||||
|
@ -87,7 +101,7 @@ ossl_digest_alloc(VALUE klass)
|
|||
ctx = EVP_MD_CTX_create();
|
||||
if (ctx == NULL)
|
||||
ossl_raise(rb_eRuntimeError, "EVP_MD_CTX_create() failed");
|
||||
obj = Data_Wrap_Struct(klass, 0, EVP_MD_CTX_destroy, ctx);
|
||||
obj = TypedData_Wrap_Struct(klass, &ossl_digest_type, ctx);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue