@@ -226,19 +226,19 @@ obj_to_asn1int(VALUE obj)
226226}
227227
228228static ASN1_BIT_STRING *
229- obj_to_asn1bstr (VALUE obj , long unused_bits )
229+ obj_to_asn1bstr (VALUE obj , int unused_bits )
230230{
231231 ASN1_BIT_STRING * bstr ;
232232
233233 if (unused_bits < 0 || unused_bits > 7 )
234234 ossl_raise (eASN1Error , "unused_bits for a bitstring value must be in " \
235235 "the range 0 to 7" );
236236 StringValue (obj );
237- if (!(bstr = ASN1_BIT_STRING_new ()))
238- ossl_raise (eASN1Error , NULL );
239- ASN1_BIT_STRING_set ( bstr , (unsigned char * )RSTRING_PTR (obj ), RSTRING_LENINT ( obj ));
240- bstr -> flags &= ~( ASN1_STRING_FLAG_BITS_LEFT | 0x07 ); /* clear */
241- bstr -> flags |= ASN1_STRING_FLAG_BITS_LEFT | unused_bits ;
237+ if (!(bstr = ASN1_BIT_STRING_new ()))
238+ ossl_raise (eASN1Error , "ASN1_BIT_STRING_new" );
239+ if (! ASN1_BIT_STRING_set1 ( bstr , (uint8_t * )RSTRING_PTR (obj ),
240+ RSTRING_LEN ( obj ), unused_bits ))
241+ ossl_raise ( eASN1Error , "ASN1_BIT_STRING_set1" ) ;
242242
243243 return bstr ;
244244}
@@ -362,22 +362,25 @@ decode_int(unsigned char* der, long length)
362362}
363363
364364static VALUE
365- decode_bstr (unsigned char * der , long length , long * unused_bits )
365+ decode_bstr (unsigned char * der , long length , int * unused_bits )
366366{
367367 ASN1_BIT_STRING * bstr ;
368368 const unsigned char * p ;
369- long len ;
369+ size_t len ;
370370 VALUE ret ;
371+ int state ;
371372
372373 p = der ;
373- if (!(bstr = d2i_ASN1_BIT_STRING (NULL , & p , length )))
374- ossl_raise (eASN1Error , NULL );
375- len = bstr -> length ;
376- * unused_bits = 0 ;
377- if ( bstr -> flags & ASN1_STRING_FLAG_BITS_LEFT )
378- * unused_bits = bstr -> flags & 0x07 ;
379- ret = rb_str_new ((const char * )bstr -> data , len );
374+ if (!(bstr = d2i_ASN1_BIT_STRING (NULL , & p , length )))
375+ ossl_raise (eASN1Error , "d2i_ASN1_BIT_STRING" );
376+ if (! ASN1_BIT_STRING_get_length ( bstr , & len , unused_bits )) {
377+ ASN1_BIT_STRING_free ( bstr ) ;
378+ ossl_raise ( eASN1Error , "ASN1_BIT_STRING_get_length" );
379+ }
380+ ret = ossl_str_new ((const char * )ASN1_STRING_get0_data ( bstr ) , len , & state );
380381 ASN1_BIT_STRING_free (bstr );
382+ if (state )
383+ rb_jump_tag (state );
381384
382385 return ret ;
383386}
@@ -761,7 +764,7 @@ int_ossl_asn1_decode0_prim(unsigned char **pp, long length, long hlen, int tag,
761764{
762765 VALUE value , asn1data ;
763766 unsigned char * p ;
764- long flag = 0 ;
767+ int flag = 0 ;
765768
766769 p = * pp ;
767770
@@ -818,7 +821,7 @@ int_ossl_asn1_decode0_prim(unsigned char **pp, long length, long hlen, int tag,
818821 asn1data = rb_obj_alloc (klass );
819822 ossl_asn1_initialize (4 , args , asn1data );
820823 if (tag == V_ASN1_BIT_STRING ){
821- rb_ivar_set (asn1data , sivUNUSED_BITS , LONG2NUM (flag ));
824+ rb_ivar_set (asn1data , sivUNUSED_BITS , INT2NUM (flag ));
822825 }
823826 }
824827 else {
0 commit comments