@@ -90,16 +90,18 @@ ossl_pkcs12_s_create(int argc, VALUE *argv, VALUE self)
9090{
9191 VALUE pass , name , pkey , cert , ca , key_nid , cert_nid , key_iter , mac_iter , keytype ;
9292 VALUE obj ;
93- char * passphrase , * friendlyname ;
93+ const char * passphrase , * friendlyname ;
9494 EVP_PKEY * key ;
9595 X509 * x509 ;
9696 STACK_OF (X509 ) * x509s ;
9797 int nkey = 0 , ncert = 0 , kiter = 0 , miter = 0 , ktype = 0 ;
9898 PKCS12 * p12 ;
9999
100100 rb_scan_args (argc , argv , "46" , & pass , & name , & pkey , & cert , & ca , & key_nid , & cert_nid , & key_iter , & mac_iter , & keytype );
101- passphrase = NIL_P (pass ) ? NULL : StringValueCStr (pass );
102- friendlyname = NIL_P (name ) ? NULL : StringValueCStr (name );
101+ if (!NIL_P (pass ))
102+ StringValue (pass );
103+ if (!NIL_P (name ))
104+ StringValue (name );
103105 key = GetPKeyPtr (pkey );
104106 x509 = GetX509CertPtr (cert );
105107/* TODO: make a VALUE to nid function */
@@ -117,6 +119,8 @@ ossl_pkcs12_s_create(int argc, VALUE *argv, VALUE self)
117119 miter = NUM2INT (mac_iter );
118120 if (!NIL_P (keytype ))
119121 ktype = NUM2INT (keytype );
122+ passphrase = NIL_P (pass ) ? NULL : rb_str_cstr (pass );
123+ friendlyname = NIL_P (name ) ? NULL : rb_str_cstr (name );
120124
121125#if defined(OPENSSL_IS_AWSLC )
122126 if (ktype != 0 ) {
@@ -177,7 +181,7 @@ ossl_pkcs12_initialize(int argc, VALUE *argv, VALUE self)
177181 PKCS12 * p12 ;
178182 BIO * in ;
179183 VALUE arg , pass , pkey , cert , ca ;
180- char * passphrase ;
184+ const char * passphrase ;
181185 EVP_PKEY * key ;
182186 X509 * x509 ;
183187 STACK_OF (X509 ) * x509s = NULL ;
@@ -192,7 +196,8 @@ ossl_pkcs12_initialize(int argc, VALUE *argv, VALUE self)
192196 RTYPEDDATA_DATA (self ) = p12 ;
193197 return self ;
194198 }
195- passphrase = NIL_P (pass ) ? NULL : StringValueCStr (pass );
199+ if (!NIL_P (pass ))
200+ StringValue (pass );
196201 in = ossl_obj2bio (& arg );
197202 p12 = d2i_PKCS12_bio (in , NULL );
198203 BIO_free (in );
@@ -201,6 +206,7 @@ ossl_pkcs12_initialize(int argc, VALUE *argv, VALUE self)
201206 RTYPEDDATA_DATA (self ) = p12 ;
202207
203208 pkey = cert = ca = Qnil ;
209+ passphrase = NIL_P (pass ) ? NULL : rb_str_cstr (pass );
204210 if (!PKCS12_parse (p12 , passphrase , & key , & x509 , & x509s ))
205211 ossl_raise (ePKCS12Error , "PKCS12_parse" );
206212 if (key ) {
0 commit comments