File tree Expand file tree Collapse file tree
main/java/org/jruby/ext/openssl Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -280,7 +280,7 @@ public IRubyObject to_i() {
280280 }
281281
282282 @ JRubyMethod (name = "to_bn" )
283- public IRubyObject to_bn () {
283+ public BN to_bn () {
284284 return this ;
285285 }
286286
@@ -852,4 +852,14 @@ public static BigInteger getBigInteger(final IRubyObject arg) {
852852 throw arg .getRuntime ().newTypeError ("Cannot convert into OpenSSL::BN" );
853853 }
854854
855+ @ Override
856+ public Object toJava (Class target ) {
857+ if ( target .isAssignableFrom (BigInteger .class ) || target == Number .class ) return value ;
858+ if ( target == Long .class || target == Long .TYPE ) return value .longValue ();
859+ if ( target == Integer .class || target == Integer .TYPE ) return value .intValue ();
860+ if ( target == Double .class || target == Double .TYPE ) return value .doubleValue ();
861+ if ( target == Float .class || target == Float .TYPE ) return value .floatValue ();
862+ return super .toJava (target );
863+ }
864+
855865}
Original file line number Diff line number Diff line change @@ -38,4 +38,9 @@ def test_to_bn
3838 assert_equal bn , 1234567890123456789012345678901234567890 . to_bn
3939 end
4040
41+ def test_to_java
42+ assert_equal java . lang . Integer . new ( 42 ) , OpenSSL ::BN . new ( '42' ) . to_java ( :int )
43+ assert_equal java . math . BigInteger . valueOf ( 24 ) , OpenSSL ::BN . new ( '24' ) . to_java
44+ end if defined? JRUBY_VERSION
45+
4146end
You can’t perform that action at this time.
0 commit comments