summaryrefslogtreecommitdiff
path: root/ext/openssl/ossl_cipher.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-04 23:33:15 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-04 23:33:15 +0000
commit163cb5b43de68cef7ae4fa053d710098399d1359 (patch)
tree52b20b455e2ed0292535f73926518fa5c402efc7 /ext/openssl/ossl_cipher.c
parent1e46f02394fdce76e51d5304f1ad1beffc0b9e77 (diff)
openssl: typed data
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47799 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl_cipher.c')
-rw-r--r--ext/openssl/ossl_cipher.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/ext/openssl/ossl_cipher.c b/ext/openssl/ossl_cipher.c
index 1cd185e69c..0efadd1925 100644
--- a/ext/openssl/ossl_cipher.c
+++ b/ext/openssl/ossl_cipher.c
@@ -11,13 +11,13 @@
#include "ossl.h"
#define WrapCipher(obj, klass, ctx) \
- (obj) = Data_Wrap_Struct((klass), 0, ossl_cipher_free, (ctx))
+ (obj) = TypedData_Wrap_Struct((klass), &ossl_cipher_type, (ctx))
#define MakeCipher(obj, klass, ctx) \
- (obj) = Data_Make_Struct((klass), EVP_CIPHER_CTX, 0, ossl_cipher_free, (ctx))
+ (obj) = TypedData_Make_Struct((klass), EVP_CIPHER_CTX, &ossl_cipher_type, (ctx))
#define AllocCipher(obj, ctx) \
- memset(DATA_PTR(obj) = (ctx) = ALLOC(EVP_CIPHER_CTX), 0, sizeof(EVP_CIPHER_CTX))
+ (DATA_PTR(obj) = (ctx) = ZALLOC(EVP_CIPHER_CTX))
#define GetCipherInit(obj, ctx) do { \
- Data_Get_Struct((obj), EVP_CIPHER_CTX, (ctx)); \
+ TypedData_Get_Struct((obj), EVP_CIPHER_CTX, &ossl_cipher_type, (ctx)); \
} while (0)
#define GetCipher(obj, ctx) do { \
GetCipherInit((obj), (ctx)); \
@@ -37,6 +37,15 @@ VALUE cCipher;
VALUE eCipherError;
static VALUE ossl_cipher_alloc(VALUE klass);
+static void ossl_cipher_free(void *ptr);
+static size_t ossl_cipher_memsize(const void *ptr);
+
+static const rb_data_type_t ossl_cipher_type = {
+ "OpenSSL/Cipher",
+ {0, ossl_cipher_free, ossl_cipher_memsize,},
+ NULL, NULL,
+ RUBY_TYPED_FREE_IMMEDIATELY,
+};
/*
* PUBLIC
@@ -70,14 +79,22 @@ ossl_cipher_new(const EVP_CIPHER *cipher)
* PRIVATE
*/
static void
-ossl_cipher_free(EVP_CIPHER_CTX *ctx)
+ossl_cipher_free(void *ptr)
{
+ EVP_CIPHER_CTX *ctx = ptr;
if (ctx) {
EVP_CIPHER_CTX_cleanup(ctx);
ruby_xfree(ctx);
}
}
+static size_t
+ossl_cipher_memsize(const void *ptr)
+{
+ const EVP_CIPHER_CTX *ctx = ptr;
+ return ctx ? sizeof(*ctx) : 0;
+}
+
static VALUE
ossl_cipher_alloc(VALUE klass)
{