|
34 | 34 | import java.math.BigInteger;
|
35 | 35 | import java.security.*;
|
36 | 36 | import java.security.interfaces.DSAKey;
|
| 37 | +import java.security.interfaces.DSAParams; |
37 | 38 | import java.security.interfaces.DSAPrivateKey;
|
38 | 39 | import java.security.interfaces.DSAPublicKey;
|
39 | 40 | import java.security.spec.DSAPrivateKeySpec;
|
|
45 | 46 | import org.jruby.RubyBoolean;
|
46 | 47 | import org.jruby.RubyClass;
|
47 | 48 | import org.jruby.RubyFixnum;
|
| 49 | +import org.jruby.RubyHash; |
48 | 50 | import org.jruby.RubyModule;
|
49 | 51 | import org.jruby.RubyNumeric;
|
50 | 52 | import org.jruby.RubyString;
|
@@ -348,6 +350,31 @@ public PKeyDSA public_key() {
|
348 | 350 | return new PKeyDSA(getRuntime(), this.publicKey);
|
349 | 351 | }
|
350 | 352 |
|
| 353 | + @JRubyMethod |
| 354 | + public IRubyObject params(final ThreadContext context) { |
| 355 | + final Ruby runtime = context.runtime; |
| 356 | + RubyHash hash = RubyHash.newHash(runtime); |
| 357 | + if (publicKey != null) { |
| 358 | + if (publicKey.getParams() != null) { |
| 359 | + setParams(context, runtime, hash, publicKey.getParams()); |
| 360 | + } |
| 361 | + hash.op_aset(context, runtime.newString("pub_key"), BN.newBN(runtime, publicKey.getY())); |
| 362 | + } |
| 363 | + if (privateKey != null) { |
| 364 | + if (publicKey == null && privateKey.getParams() != null) { |
| 365 | + setParams(context, runtime, hash, privateKey.getParams()); |
| 366 | + } |
| 367 | + hash.op_aset(context, runtime.newString("priv_key"), BN.newBN(runtime, privateKey.getX())); |
| 368 | + } |
| 369 | + return hash; |
| 370 | + } |
| 371 | + |
| 372 | + private static void setParams(ThreadContext context, Ruby runtime, RubyHash hash, DSAParams params) { |
| 373 | + hash.op_aset(context, runtime.newString("p"), BN.newBN(runtime, params.getP())); |
| 374 | + hash.op_aset(context, runtime.newString("q"), BN.newBN(runtime, params.getQ())); |
| 375 | + hash.op_aset(context, runtime.newString("g"), BN.newBN(runtime, params.getG())); |
| 376 | + } |
| 377 | + |
351 | 378 | @Override
|
352 | 379 | @JRubyMethod(name = { "to_pem", "to_s" }, alias = "export", rest = true)
|
353 | 380 | public RubyString to_pem(final ThreadContext context, final IRubyObject[] args) {
|
|
0 commit comments