diff --git a/VERSION b/VERSION index a8fdfda..53adb84 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.8.1 +1.8.2 diff --git a/ext/openssl/cipher/aead/aead.c b/ext/openssl/cipher/aead/aead.c index 1fbbd16..dc850d2 100644 --- a/ext/openssl/cipher/aead/aead.c +++ b/ext/openssl/cipher/aead/aead.c @@ -1,20 +1,27 @@ #include +#include #include #include VALUE dOSSL; VALUE eCipherError; -#define GetCipherInit(obj, ctx) do { \ - Data_Get_Struct((obj), EVP_CIPHER_CTX, (ctx)); \ - } while (0) +#if RUBY_API_VERSION_CODE >= 20200 +#define GetCipherInit(obj, ctx) do { \ + TypedData_Get_Struct((obj), EVP_CIPHER_CTX, RTYPEDDATA_TYPE(obj), (ctx)); \ +} while (0) +#else +#define GetCipherInit(obj, ctx) do { \ + Data_Get_Struct((obj), EVP_CIPHER_CTX, (ctx)); \ +} while (0) +#endif -#define GetCipher(obj, ctx) do { \ - GetCipherInit((obj), (ctx)); \ - if (!(ctx)) { \ - ossl_raise(rb_eRuntimeError, "Cipher not inititalized!"); \ - } \ - } while (0) +#define GetCipher(obj, ctx) do { \ + GetCipherInit((obj), (ctx)); \ + if (!(ctx)) { \ + ossl_raise(rb_eRuntimeError, "Cipher not inititalized!"); \ + } \ +} while (0) static VALUE ossl_make_error(VALUE exc, const char *fmt, va_list args) @@ -65,7 +72,7 @@ static VALUE ossl_cipher_set_aad(VALUE self, VALUE data) { EVP_CIPHER_CTX *ctx; - char *in = NULL; + unsigned char *in = NULL; int in_len = 0; int out_len = 0; @@ -106,7 +113,7 @@ static VALUE ossl_cipher_set_tag(VALUE self, VALUE data) { EVP_CIPHER_CTX *ctx; - char *in = NULL; + unsigned char *in = NULL; int in_len = 0; StringValue(data); @@ -131,7 +138,6 @@ ossl_cipher_set_iv_length(VALUE self, VALUE iv_length) { EVP_CIPHER_CTX *ctx; int ivlen = NUM2INT(iv_length); - GetCipher(self, ctx); #ifndef EVP_CTRL_GCM_SET_IVLEN @@ -161,15 +167,13 @@ ossl_cipher_verify(VALUE self) void Init_aead(void) { - VALUE mOSSL = rb_define_module("OpenSSL"); - VALUE mOSSLCipher = rb_define_class_under(mOSSL, "Cipher", rb_cObject); - VALUE eOSSLError = rb_define_class_under(mOSSL,"OpenSSLError",rb_eStandardError); - - eCipherError = rb_define_class_under(mOSSLCipher, "CipherError", eOSSLError); - - rb_define_method(mOSSLCipher, "aad=", ossl_cipher_set_aad, 1); - rb_define_method(mOSSLCipher, "gcm_tag", ossl_cipher_get_tag, 0); - rb_define_method(mOSSLCipher, "gcm_tag=", ossl_cipher_set_tag, 1); - rb_define_method(mOSSLCipher, "gcm_iv_len=", ossl_cipher_set_iv_length, 1); - rb_define_method(mOSSLCipher, "verify", ossl_cipher_verify, 0); + rb_require("openssl"); + VALUE cOSSLCipher = rb_path2class("OpenSSL::Cipher"); + eCipherError = rb_path2class("OpenSSL::Cipher::CipherError"); + + rb_define_method(cOSSLCipher, "aad=", ossl_cipher_set_aad, 1); + rb_define_method(cOSSLCipher, "gcm_tag", ossl_cipher_get_tag, 0); + rb_define_method(cOSSLCipher, "gcm_tag=", ossl_cipher_set_tag, 1); + rb_define_method(cOSSLCipher, "gcm_iv_len=", ossl_cipher_set_iv_length, 1); + rb_define_method(cOSSLCipher, "verify", ossl_cipher_verify, 0); } diff --git a/lib/aead/cipher.rb b/lib/aead/cipher.rb index b0c2830..0336e96 100644 --- a/lib/aead/cipher.rb +++ b/lib/aead/cipher.rb @@ -1,6 +1,5 @@ require 'aead' -require 'openssl' require 'openssl/cipher/aead' require 'securerandom'