@@ -697,11 +697,12 @@ to_der_internal(VALUE self, int constructed, int indef_len, VALUE body)
697697 int tag_number = ossl_asn1_tag (self );
698698 int default_tag_number = ossl_asn1_default_tag (self );
699699 int body_length , total_length ;
700+ VALUE tagging = ossl_asn1_get_tagging (self );
700701 VALUE str ;
701702 unsigned char * p ;
702703
703704 body_length = RSTRING_LENINT (body );
704- if (ossl_asn1_get_tagging ( self ) == sym_EXPLICIT ) {
705+ if (tagging == sym_EXPLICIT ) {
705706 int inner_length , e_encoding = indef_len ? 2 : 1 ;
706707
707708 if (default_tag_number == -1 )
@@ -722,7 +723,7 @@ to_der_internal(VALUE self, int constructed, int indef_len, VALUE body)
722723 ASN1_put_eoc (& p ); /* For wrapper object */
723724 }
724725 }
725- else {
726+ else if ( NIL_P ( tagging ) || tagging == sym_IMPLICIT ) {
726727 total_length = ASN1_object_size (encoding , body_length , tag_number );
727728 str = rb_str_new (NULL , total_length );
728729 p = (unsigned char * )RSTRING_PTR (str );
@@ -732,6 +733,9 @@ to_der_internal(VALUE self, int constructed, int indef_len, VALUE body)
732733 if (indef_len )
733734 ASN1_put_eoc (& p );
734735 }
736+ else {
737+ ossl_raise (eASN1Error , "invalid tagging method" );
738+ }
735739 assert (p - (unsigned char * )RSTRING_PTR (str ) == total_length );
736740 return str ;
737741}
0 commit comments