Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement 4-arg form of EC::Group.initialize #309

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions src/main/java/org/jruby/ext/openssl/PKeyEC.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey;
import java.security.spec.ECFieldFp;
import java.security.spec.ECGenParameterSpec;
import java.security.spec.ECParameterSpec;
import java.security.spec.ECPoint;
Expand Down Expand Up @@ -740,16 +741,52 @@ public Group(Ruby runtime, RubyClass type) {
public IRubyObject initialize(final ThreadContext context, final IRubyObject[] args) {
final Ruby runtime = context.runtime;

if ( Arity.checkArgumentCount(runtime, args, 1, 4) == 1 ) {
IRubyObject arg = args[0];
switch ( Arity.checkArgumentCount(runtime, args, 1, 4) ) {
case 1: {
IRubyObject arg = args[0];

if ( arg instanceof Group ) {
this.curve_name = ((Group) arg).implCurveName(runtime);
return this;
if (arg instanceof Group) {
this.curve_name = ((Group) arg).implCurveName(runtime);
return this;
}

this.curve_name = arg.convertToString();
break;
}
case 4: {
if (args[0] instanceof RubySymbol) {
RubyString curveName = args[0].asString();
String curveID = curveName.toString();

BigInteger p = getBigInteger(context, args[1]);
BigInteger a = getBigInteger(context, args[2]);
BigInteger b = getBigInteger(context, args[3]);

EllipticCurve curve;

if (curveID.equals("GFp")) {
this.curve_name = curveName;
curve = new EllipticCurve(new ECFieldFp(p), a, b);

// unsure how to implement this... what to use for `m` in ECFieldF2m constructor?
// } else if (curveID.equals("GF2m")) {
// this.curve_name = curveName;
// curve = new EllipticCurve(new ECFieldF2m(1, p), a, b);
} else {
throw runtime.newArgumentError("unknown symbol, must be :GFp or :GF2m");
}

this.paramSpec = PKeyEC.getParamSpec(curveID, curve);
} else {
throw runtime.newArgumentError("unknown argument, must be :GFp or :GF2m");
}

this.curve_name = arg.convertToString();
break;
}
default:
throw context.runtime.newArgumentError("wrong number of arguments");
}

return this;
}

Expand Down
Loading