1717 ossl_raise(rb_eRuntimeError, NULL); \
1818 RTYPEDDATA_DATA(obj) = (ctx); \
1919} while (0)
20- #define GetCipherInit (obj , ctx ) do { \
21- TypedData_Get_Struct((obj), EVP_CIPHER_CTX, &ossl_cipher_type, (ctx)); \
22- } while (0)
2320#define GetCipher (obj , ctx ) do { \
24- GetCipherInit ((obj), (ctx)); \
21+ TypedData_Get_Struct ((obj), EVP_CIPHER_CTX, &ossl_cipher_type , (ctx)); \
2522 if (!(ctx)) { \
2623 ossl_raise(rb_eRuntimeError, "Cipher not initialized!"); \
2724 } \
@@ -147,10 +144,7 @@ ossl_cipher_initialize(VALUE self, VALUE str)
147144 const EVP_CIPHER * cipher ;
148145 VALUE cipher_holder ;
149146
150- GetCipherInit (self , ctx );
151- if (ctx ) {
152- ossl_raise (rb_eRuntimeError , "Cipher already initialized!" );
153- }
147+ ossl_want_uninitialized (self , & ossl_cipher_type );
154148 cipher = ossl_evp_cipher_fetch (str , & cipher_holder );
155149 AllocCipher (self , ctx );
156150 if (EVP_CipherInit_ex (ctx , cipher , NULL , NULL , NULL , -1 ) != 1 )
@@ -166,14 +160,10 @@ ossl_cipher_copy(VALUE self, VALUE other)
166160{
167161 EVP_CIPHER_CTX * ctx1 , * ctx2 ;
168162
169- rb_check_frozen (self );
170- if (self == other ) return self ;
171-
172- GetCipherInit (self , ctx1 );
173- if (!ctx1 ) {
174- AllocCipher (self , ctx1 );
175- }
163+ ossl_want_uninitialized (self , & ossl_cipher_type );
176164 GetCipher (other , ctx2 );
165+
166+ AllocCipher (self , ctx1 );
177167 if (EVP_CIPHER_CTX_copy (ctx1 , ctx2 ) != 1 )
178168 ossl_raise (eCipherError , NULL );
179169
0 commit comments