@@ -149,10 +149,14 @@ static const rb_data_type_t ossl_ocsp_certid_type = {
149
149
* Public
150
150
*/
151
151
static VALUE
152
- ossl_ocspcertid_new ( OCSP_CERTID * cid )
152
+ ossl_ocspcid_new ( const OCSP_CERTID * cid )
153
153
{
154
154
VALUE obj = NewOCSPCertId (cOCSPCertId );
155
- SetOCSPCertId (obj , cid );
155
+ /* OpenSSL 1.1.1 takes a non-const pointer */
156
+ OCSP_CERTID * cid_new = OCSP_CERTID_dup ((OCSP_CERTID * )cid );
157
+ if (!cid_new )
158
+ ossl_raise (eOCSPError , "OCSP_CERTID_dup" );
159
+ SetOCSPCertId (obj , cid_new );
156
160
return obj ;
157
161
}
158
162
@@ -328,21 +332,19 @@ static VALUE
328
332
ossl_ocspreq_get_certid (VALUE self )
329
333
{
330
334
OCSP_REQUEST * req ;
331
- OCSP_ONEREQ * one ;
332
- OCSP_CERTID * id ;
333
- VALUE ary , tmp ;
334
- int i , count ;
335
335
336
336
GetOCSPReq (self , req );
337
- count = OCSP_request_onereq_count (req );
338
- ary = (count > 0 ) ? rb_ary_new () : Qnil ;
339
- for (i = 0 ; i < count ; i ++ ){
340
- one = OCSP_request_onereq_get0 (req , i );
341
- tmp = NewOCSPCertId (cOCSPCertId );
342
- if (!(id = OCSP_CERTID_dup (OCSP_onereq_get0_id (one ))))
343
- ossl_raise (eOCSPError , NULL );
344
- SetOCSPCertId (tmp , id );
345
- rb_ary_push (ary , tmp );
337
+ int count = OCSP_request_onereq_count (req );
338
+ if (count < 0 )
339
+ ossl_raise (eOCSPError , "OCSP_request_onereq_count" );
340
+ if (count == 0 )
341
+ return Qnil ;
342
+
343
+ VALUE ary = rb_ary_new_capa (count );
344
+ for (int i = 0 ; i < count ; i ++ ) {
345
+ OCSP_ONEREQ * one = OCSP_request_onereq_get0 (req , i );
346
+ OCSP_CERTID * cid = OCSP_onereq_get0_id (one );
347
+ rb_ary_push (ary , ossl_ocspcid_new (cid ));
346
348
}
347
349
348
350
return ary ;
@@ -899,42 +901,34 @@ static VALUE
899
901
ossl_ocspbres_get_status (VALUE self )
900
902
{
901
903
OCSP_BASICRESP * bs ;
902
- OCSP_SINGLERESP * single ;
903
- OCSP_CERTID * cid ;
904
- ASN1_TIME * revtime , * thisupd , * nextupd ;
905
- int status , reason ;
906
- X509_EXTENSION * x509ext ;
907
- VALUE ret , ary , ext ;
908
- int count , ext_count , i , j ;
909
904
910
905
GetOCSPBasicRes (self , bs );
911
- ret = rb_ary_new ();
912
- count = OCSP_resp_count (bs );
913
- for (i = 0 ; i < count ; i ++ ){
914
- single = OCSP_resp_get0 (bs , i );
915
- if (!single ) continue ;
916
-
917
- revtime = thisupd = nextupd = NULL ;
918
- status = OCSP_single_get0_status (single , & reason , & revtime ,
919
- & thisupd , & nextupd );
920
- if (status < 0 ) continue ;
921
- if (!(cid = OCSP_CERTID_dup ((OCSP_CERTID * )OCSP_SINGLERESP_get0_id (single )))) /* FIXME */
922
- ossl_raise (eOCSPError , NULL );
923
- ary = rb_ary_new ();
924
- rb_ary_push (ary , ossl_ocspcertid_new (cid ));
925
- rb_ary_push (ary , INT2NUM (status ));
926
- rb_ary_push (ary , INT2NUM (reason ));
927
- rb_ary_push (ary , revtime ? asn1time_to_time (revtime ) : Qnil );
928
- rb_ary_push (ary , thisupd ? asn1time_to_time (thisupd ) : Qnil );
929
- rb_ary_push (ary , nextupd ? asn1time_to_time (nextupd ) : Qnil );
930
- ext = rb_ary_new ();
931
- ext_count = OCSP_SINGLERESP_get_ext_count (single );
932
- for (j = 0 ; j < ext_count ; j ++ ){
933
- x509ext = OCSP_SINGLERESP_get_ext (single , j );
934
- rb_ary_push (ext , ossl_x509ext_new (x509ext ));
935
- }
936
- rb_ary_push (ary , ext );
937
- rb_ary_push (ret , ary );
906
+ VALUE ret = rb_ary_new ();
907
+ int count = OCSP_resp_count (bs );
908
+ for (int i = 0 ; i < count ; i ++ ) {
909
+ OCSP_SINGLERESP * single = OCSP_resp_get0 (bs , i );
910
+ ASN1_TIME * revtime , * thisupd , * nextupd ;
911
+ int reason ;
912
+
913
+ int status = OCSP_single_get0_status (single , & reason , & revtime , & thisupd , & nextupd );
914
+ if (status < 0 )
915
+ ossl_raise (eOCSPError , "OCSP_single_get0_status" );
916
+
917
+ VALUE ary = rb_ary_new ();
918
+ rb_ary_push (ary , ossl_ocspcid_new (OCSP_SINGLERESP_get0_id (single )));
919
+ rb_ary_push (ary , INT2NUM (status ));
920
+ rb_ary_push (ary , INT2NUM (reason ));
921
+ rb_ary_push (ary , revtime ? asn1time_to_time (revtime ) : Qnil );
922
+ rb_ary_push (ary , thisupd ? asn1time_to_time (thisupd ) : Qnil );
923
+ rb_ary_push (ary , nextupd ? asn1time_to_time (nextupd ) : Qnil );
924
+ VALUE ext = rb_ary_new ();
925
+ int ext_count = OCSP_SINGLERESP_get_ext_count (single );
926
+ for (int j = 0 ; j < ext_count ; j ++ ) {
927
+ X509_EXTENSION * x509ext = OCSP_SINGLERESP_get_ext (single , j );
928
+ rb_ary_push (ext , ossl_x509ext_new (x509ext ));
929
+ }
930
+ rb_ary_push (ary , ext );
931
+ rb_ary_push (ret , ary );
938
932
}
939
933
940
934
return ret ;
@@ -1225,12 +1219,9 @@ static VALUE
1225
1219
ossl_ocspsres_get_certid (VALUE self )
1226
1220
{
1227
1221
OCSP_SINGLERESP * sres ;
1228
- OCSP_CERTID * id ;
1229
1222
1230
1223
GetOCSPSingleRes (self , sres );
1231
- id = OCSP_CERTID_dup ((OCSP_CERTID * )OCSP_SINGLERESP_get0_id (sres )); /* FIXME */
1232
-
1233
- return ossl_ocspcertid_new (id );
1224
+ return ossl_ocspcid_new (OCSP_SINGLERESP_get0_id (sres ));
1234
1225
}
1235
1226
1236
1227
/*
0 commit comments