|
23 | 23 |
|
24 | 24 | import java.security.interfaces.ECPrivateKey;
|
25 | 25 | import java.security.interfaces.ECPublicKey;
|
| 26 | +import java.security.spec.ECFieldFp; |
26 | 27 | import java.security.spec.ECGenParameterSpec;
|
27 | 28 | import java.security.spec.ECParameterSpec;
|
28 | 29 | import java.security.spec.ECPoint;
|
@@ -740,16 +741,52 @@ public Group(Ruby runtime, RubyClass type) {
|
740 | 741 | public IRubyObject initialize(final ThreadContext context, final IRubyObject[] args) {
|
741 | 742 | final Ruby runtime = context.runtime;
|
742 | 743 |
|
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]; |
745 | 747 |
|
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; |
749 | 755 | }
|
| 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 | + } |
750 | 783 |
|
751 |
| - this.curve_name = arg.convertToString(); |
| 784 | + break; |
| 785 | + } |
| 786 | + default: |
| 787 | + throw context.runtime.newArgumentError("wrong number of arguments"); |
752 | 788 | }
|
| 789 | + |
753 | 790 | return this;
|
754 | 791 | }
|
755 | 792 |
|
|
0 commit comments