Skip to content

Commit df905a1

Browse files
committed
Broken partial impl of ..EC::Group.new 4-arg form
See #308
1 parent 23ff684 commit df905a1

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

Diff for: src/main/java/org/jruby/ext/openssl/PKeyEC.java

+43-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.security.interfaces.ECPrivateKey;
2525
import java.security.interfaces.ECPublicKey;
26+
import java.security.spec.ECFieldFp;
2627
import java.security.spec.ECGenParameterSpec;
2728
import java.security.spec.ECParameterSpec;
2829
import java.security.spec.ECPoint;
@@ -740,16 +741,52 @@ public Group(Ruby runtime, RubyClass type) {
740741
public IRubyObject initialize(final ThreadContext context, final IRubyObject[] args) {
741742
final Ruby runtime = context.runtime;
742743

743-
if ( Arity.checkArgumentCount(runtime, args, 1, 4) == 1 ) {
744-
IRubyObject arg = args[0];
744+
switch ( Arity.checkArgumentCount(runtime, args, 1, 4) ) {
745+
case 1: {
746+
IRubyObject arg = args[0];
745747

746-
if ( arg instanceof Group ) {
747-
this.curve_name = ((Group) arg).implCurveName(runtime);
748-
return this;
748+
if (arg instanceof Group) {
749+
this.curve_name = ((Group) arg).implCurveName(runtime);
750+
return this;
751+
}
752+
753+
this.curve_name = arg.convertToString();
754+
break;
749755
}
756+
case 4: {
757+
if (args[0] instanceof RubySymbol) {
758+
RubyString curveName = args[0].asString();
759+
String curveID = curveName.toString();
760+
761+
BigInteger p = getBigInteger(context, args[1]);
762+
BigInteger a = getBigInteger(context, args[2]);
763+
BigInteger b = getBigInteger(context, args[3]);
764+
765+
EllipticCurve curve;
766+
767+
if (curveID.equals("GFp")) {
768+
this.curve_name = curveName;
769+
curve = new EllipticCurve(new ECFieldFp(p), a, b);
770+
771+
// unsure how to implement this... what to use for `m` in ECFieldF2m constructor?
772+
// } else if (curveID.equals("GF2m")) {
773+
// this.curve_name = curveName;
774+
// curve = new EllipticCurve(new ECFieldF2m(1, p), a, b);
775+
} else {
776+
throw runtime.newArgumentError("unknown symbol, must be :GFp or :GF2m");
777+
}
778+
779+
this.paramSpec = PKeyEC.getParamSpec(curveID, curve);
780+
} else {
781+
throw runtime.newArgumentError("unknown argument, must be :GFp or :GF2m");
782+
}
750783

751-
this.curve_name = arg.convertToString();
784+
break;
785+
}
786+
default:
787+
throw context.runtime.newArgumentError("wrong number of arguments");
752788
}
789+
753790
return this;
754791
}
755792

0 commit comments

Comments
 (0)