Skip to content

Commit b16bcdd

Browse files
committed
[refactor] internals - one fallback raise should do
1 parent 9173da0 commit b16bcdd

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
272272
}
273273
// TODO: ugly NoClassDefFoundError catching for no BC env. How can we remove this?
274274
boolean noClassDef = false;
275-
if ( key == null && ! noClassDef ) { // PEM_read_bio_DSAPrivateKey
275+
if ( key == null && ! noClassDef ) {
276276
try {
277277
key = readPrivateKey(strJava, passwd);
278278
}
@@ -304,8 +304,7 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
304304
key = readECPrivateKey(ecdsaFactory, str.getBytes());
305305
}
306306
catch (NoClassDefFoundError e) { noClassDef = true; debugStackTrace(runtime, e); }
307-
catch (InvalidKeySpecException e) { debug(runtime, "PKeyEC could not read private key", e); }
308-
catch (IOException e) { debugStackTrace(runtime, "PKeyEC could not read private key", e); }
307+
catch (InvalidKeySpecException|IOException e) { debug(runtime, "PKeyEC could not read private key", e); }
309308
catch (RuntimeException e) {
310309
if ( isKeyGenerationFailure(e) ) debug(runtime, "PKeyEC could not read private key", e);
311310
else debugStackTrace(runtime, e);
@@ -331,8 +330,6 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
331330
if ( key == null ) key = tryPKCS8EncodedKey(runtime, ecdsaFactory, str.getBytes());
332331
if ( key == null ) key = tryX509EncodedKey(runtime, ecdsaFactory, str.getBytes());
333332

334-
if ( key == null ) throw newECError(runtime, "Neither PUB key nor PRIV key:");
335-
336333
if ( key instanceof KeyPair ) {
337334
final PublicKey pubKey = ((KeyPair) key).getPublic();
338335
final PrivateKey privKey = ((KeyPair) key).getPrivate();
@@ -353,7 +350,7 @@ else if ( key instanceof ECPublicKey ) {
353350
this.privateKey = null;
354351
}
355352
else {
356-
throw newECError(runtime, "Neither PUB key nor PRIV key: " + key.getClass().getName());
353+
throw newECError(runtime, "Neither PUB key nor PRIV key: ");
357354
}
358355

359356
if ( curveName == null && publicKey != null ) {

0 commit comments

Comments
 (0)