Skip to content

Commit d0f11af

Browse files
committed
[refactor] PKey read-er methods and return types
1 parent 382a829 commit d0f11af

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727
***** END LICENSE BLOCK *****/
2828
package org.jruby.ext.openssl;
2929

30-
import java.io.ByteArrayInputStream;
3130
import java.io.Console;
3231
import java.io.IOException;
33-
import java.io.InputStreamReader;
3432
import java.io.StringReader;
3533
import java.math.BigInteger;
3634
import java.security.*;
@@ -57,11 +55,12 @@
5755
import org.jruby.runtime.ThreadContext;
5856
import org.jruby.runtime.builtin.IRubyObject;
5957
import org.jruby.runtime.Visibility;
58+
import org.jruby.util.ByteList;
6059

60+
import org.jruby.ext.openssl.impl.CipherSpec;
6161
import org.jruby.ext.openssl.x509store.PEMInputOutput;
62+
6263
import static org.jruby.ext.openssl.OpenSSL.*;
63-
import org.jruby.ext.openssl.impl.CipherSpec;
64-
import org.jruby.util.ByteList;
6564

6665
/**
6766
* @author <a href="mailto:[email protected]">Ola Bini</a>
@@ -111,14 +110,16 @@ public static IRubyObject read(final ThreadContext context, IRubyObject recv, IR
111110
}
112111

113112
final RubyString str = readInitArg(context, data);
114-
Object key = null;
113+
KeyPair keyPair;
115114
// d2i_PrivateKey_bio
116115
try {
117-
key = readPrivateKey(str, pass);
118-
} catch (IOException e) { /* ignore */ }
116+
keyPair = readPrivateKey(str, pass);
117+
} catch (IOException e) {
118+
debugStackTrace(runtime, "PKey readPrivateKey", e); /* ignore */
119+
keyPair = null;
120+
}
119121
// PEM_read_bio_PrivateKey
120-
if (key != null) {
121-
final KeyPair keyPair = (KeyPair) key;
122+
if (keyPair != null) {
122123
final String alg = getAlgorithm(keyPair);
123124
if ( "RSA".equals(alg) ) {
124125
return new PKeyRSA(runtime, _PKey(runtime).getClass("RSA"),
@@ -141,17 +142,23 @@ public static IRubyObject read(final ThreadContext context, IRubyObject recv, IR
141142
try {
142143
pubKey = PEMInputOutput.readRSAPublicKey(new StringReader(str.toString()), null);
143144
return new PKeyRSA(runtime, (RSAPublicKey) pubKey);
144-
} catch (IOException e) { /* ignore */ }
145+
} catch (IOException e) {
146+
debugStackTrace(runtime, "PKey readRSAPublicKey", e); /* ignore */
147+
}
145148
try {
146149
pubKey = PEMInputOutput.readDSAPublicKey(new StringReader(str.toString()), null);
147150
return new PKeyDSA(runtime, (DSAPublicKey) pubKey);
148-
} catch (IOException e) { /* ignore */ }
151+
} catch (IOException e) {
152+
debugStackTrace(runtime, "PKey readDSAPublicKey", e); /* ignore */
153+
}
149154

150155
final byte[] input = StringHelper.readX509PEM(context, str);
151156
// d2i_PUBKEY_bio
152157
try {
153158
pubKey = org.jruby.ext.openssl.impl.PKey.readPublicKey(input);
154-
} catch (IOException|GeneralSecurityException e) { /* ignore */ }
159+
} catch (IOException|GeneralSecurityException e) {
160+
debugStackTrace(runtime, "PKey readPublicKey", e); /* ignore */
161+
}
155162
// PEM_read_bio_PUBKEY
156163
if (pubKey == null) {
157164
try {

0 commit comments

Comments
 (0)