6262import org .jruby .anno .JRubyMethod ;
6363import org .jruby .exceptions .RaiseException ;
6464import org .jruby .runtime .Arity ;
65+ import org .jruby .runtime .Block ;
6566import org .jruby .runtime .ObjectAllocator ;
6667import org .jruby .runtime .ThreadContext ;
6768import org .jruby .runtime .builtin .IRubyObject ;
@@ -218,26 +219,26 @@ static PKeyRSA newInstance(final Ruby runtime, final PublicKey publicKey) {
218219 }
219220
220221 @ JRubyMethod (rest = true , visibility = Visibility .PRIVATE )
221- public IRubyObject initialize (final ThreadContext context , final IRubyObject [] args ) {
222+ public IRubyObject initialize (final ThreadContext context , final IRubyObject [] args , final Block block ) {
222223 final Ruby runtime = context .runtime ;
223224
224225 if ( Arity .checkArgumentCount (runtime , args , 0 , 2 ) == 0 ) {
225226 privateKey = null ; publicKey = null ; return this ;
226227 }
227228
228- IRubyObject arg = args [0 ]; IRubyObject pass = null ;
229- if ( args .length > 1 ) pass = args [1 ];
229+ IRubyObject arg = args [0 ];
230+ IRubyObject arg1 = args .length > 1 ? args [1 ] : null ; // exponent (Fixnum) or password (String)
230231
231232 if ( arg instanceof RubyFixnum ) {
232233 int keySize = RubyNumeric .fix2int ((RubyFixnum ) arg );
233234 BigInteger exp = RSAKeyGenParameterSpec .F4 ;
234- if ( pass != null && ! pass .isNil () ) {
235- exp = BigInteger .valueOf (RubyNumeric .num2long (pass ));
235+ if (arg1 != null && !arg1 .isNil ()) {
236+ exp = BigInteger .valueOf (RubyNumeric .num2long (arg1 ));
236237 }
237238 return rsaGenerate (runtime , this , keySize , exp );
238239 }
239240
240- final char [] passwd = password (pass );
241+ final char [] passwd = password (context , arg1 , block );
241242 final RubyString str = readInitArg (context , arg );
242243 final String strJava = str .toString ();
243244
@@ -434,13 +435,13 @@ public RubyString to_text() {
434435
435436 @ Override
436437 @ JRubyMethod (name = { "to_pem" , "to_s" }, alias = "export" , rest = true )
437- public RubyString to_pem (final IRubyObject [] args ) {
438- Arity .checkArgumentCount (getRuntime () , args , 0 , 2 );
438+ public RubyString to_pem (ThreadContext context , final IRubyObject [] args ) {
439+ Arity .checkArgumentCount (context . runtime , args , 0 , 2 );
439440
440441 CipherSpec spec = null ; char [] passwd = null ;
441442 if ( args .length > 0 ) {
442443 spec = cipherSpec ( args [0 ] );
443- if ( args .length > 1 ) passwd = password (args [1 ]);
444+ if ( args .length > 1 ) passwd = password (context , args [1 ], null );
444445 }
445446
446447 try {
@@ -451,13 +452,13 @@ public RubyString to_pem(final IRubyObject[] args) {
451452 else {
452453 PEMInputOutput .writeRSAPublicKey (writer , publicKey );
453454 }
454- return RubyString .newString (getRuntime () , writer .getBuffer ());
455+ return RubyString .newString (context . runtime , writer .getBuffer ());
455456 }
456457 catch (NoClassDefFoundError ncdfe ) {
457- throw newRSAError (getRuntime () , bcExceptionMessage (ncdfe ));
458+ throw newRSAError (context . runtime , bcExceptionMessage (ncdfe ));
458459 }
459460 catch (IOException ioe ) {
460- throw newRSAError (getRuntime () , ioe .getMessage ());
461+ throw newRSAError (context . runtime , ioe .getMessage ());
461462 }
462463 }
463464
0 commit comments