Skip to content

Commit 7ea9e50

Browse files
committed
[refactor] use BC utility when resolving curve/oid
1 parent ea6d7c6 commit 7ea9e50

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

src/main/java/org/jruby/ext/openssl/PKeyEC.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
5353
import org.bouncycastle.crypto.signers.ECDSASigner;
5454
import org.bouncycastle.jcajce.provider.asymmetric.util.EC5Util;
55+
import org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil;
5556
import org.bouncycastle.jce.ECNamedCurveTable;
5657
import org.bouncycastle.jce.ECPointUtil;
5758
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
@@ -171,33 +172,19 @@ public static RubyArray builtin_curves(ThreadContext context, IRubyObject self)
171172
}
172173

173174
private static Optional<ASN1ObjectIdentifier> getCurveOID(final String curveName) {
174-
ASN1ObjectIdentifier id;
175-
id = org.bouncycastle.asn1.sec.SECNamedCurves.getOID(curveName);
176-
if ( id != null ) return Optional.of(id);
177-
id = org.bouncycastle.asn1.x9.X962NamedCurves.getOID(curveName);
178-
if ( id != null ) return Optional.of(id);
179-
id = org.bouncycastle.asn1.nist.NISTNamedCurves.getOID(curveName);
180-
if ( id != null ) return Optional.of(id);
181-
id = org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves.getOID(curveName);
182-
if ( id != null ) return Optional.of(id);
183-
return Optional.empty();
175+
return Optional.ofNullable(ECUtil.getNamedCurveOid(curveName));
184176
}
185177

186178
private static boolean isCurveName(final String curveName) {
187179
return getCurveOID(curveName).isPresent();
188180
}
189181

190182
private static String getCurveName(final ASN1ObjectIdentifier oid) {
191-
String name;
192-
name = org.bouncycastle.asn1.sec.SECNamedCurves.getName(oid);
193-
if ( name != null ) return name;
194-
name = org.bouncycastle.asn1.x9.X962NamedCurves.getName(oid);
195-
if ( name != null ) return name;
196-
name = org.bouncycastle.asn1.nist.NISTNamedCurves.getName(oid);
197-
if ( name != null ) return name;
198-
name = org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves.getName(oid);
199-
if ( name != null ) return name;
200-
throw new IllegalStateException("could not identify curve name from: " + oid);
183+
final String name = ECUtil.getCurveName(oid);
184+
if (name == null) {
185+
throw new IllegalStateException("could not identify curve name from: " + oid);
186+
}
187+
return name;
201188
}
202189

203190
public PKeyEC(Ruby runtime, RubyClass type) {

0 commit comments

Comments
 (0)