Skip to content

Commit 153028d

Browse files
committed
[refactor] internals - no need to have old JRuby 1.7 support around
1 parent 4a94bd1 commit 153028d

File tree

1 file changed

+7
-56
lines changed
  • src/main/java/org/jruby/ext/openssl/x509store

1 file changed

+7
-56
lines changed

src/main/java/org/jruby/ext/openssl/x509store/Lookup.java

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

30-
import org.jruby.ext.openssl.OpenSSL;
31-
import org.jruby.ext.openssl.util.Cache;
32-
import static org.jruby.ext.openssl.x509store.X509Utils.X509_CERT_DIR;
33-
import static org.jruby.ext.openssl.x509store.X509Utils.X509_FILETYPE_ASN1;
34-
import static org.jruby.ext.openssl.x509store.X509Utils.X509_FILETYPE_DEFAULT;
35-
import static org.jruby.ext.openssl.x509store.X509Utils.X509_FILETYPE_PEM;
36-
import static org.jruby.ext.openssl.x509store.X509Utils.X509_LU_CRL;
37-
import static org.jruby.ext.openssl.x509store.X509Utils.X509_LU_FAIL;
38-
import static org.jruby.ext.openssl.x509store.X509Utils.X509_LU_X509;
39-
import static org.jruby.ext.openssl.x509store.X509Utils.X509_L_ADD_DIR;
40-
import static org.jruby.ext.openssl.x509store.X509Utils.X509_L_FILE_LOAD;
41-
import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_BAD_X509_FILETYPE;
42-
import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_INVALID_DIRECTORY;
43-
import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_LOADING_CERT_DIR;
44-
import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_LOADING_DEFAULTS;
45-
import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_WRONG_LOOKUP_TYPE;
46-
import static org.jruby.ext.openssl.x509store.X509Utils.getDefaultCertificateDirectoryEnvironment;
47-
import static org.jruby.ext.openssl.x509store.X509Utils.getDefaultCertificateFileEnvironment;
48-
49-
import java.io.BufferedInputStream;
5030
import java.io.BufferedReader;
5131
import java.io.File;
5232
import java.io.FileInputStream;
5333
import java.io.IOException;
5434
import java.io.InputStream;
5535
import java.io.InputStreamReader;
56-
import java.io.Reader;
5736
import java.math.BigInteger;
5837
import java.security.GeneralSecurityException;
5938
import java.security.KeyStore;
@@ -67,15 +46,13 @@
6746
import java.util.Iterator;
6847

6948
import org.jruby.Ruby;
70-
import org.jruby.RubyHash;
49+
import org.jruby.ext.openssl.OpenSSL;
7150
import org.jruby.ext.openssl.SecurityHelper;
51+
import org.jruby.ext.openssl.util.Cache;
7252
import org.jruby.util.JRubyFile;
7353
import org.jruby.util.SafePropertyAccessor;
74-
import org.jruby.util.io.ChannelDescriptor;
75-
import org.jruby.util.io.ChannelStream;
76-
import org.jruby.util.io.FileExistsException;
77-
import org.jruby.util.io.InvalidValueException;
78-
import org.jruby.util.io.ModeFlags;
54+
55+
import static org.jruby.ext.openssl.x509store.X509Utils.*;
7956

8057
/**
8158
* X509_LOOKUP
@@ -84,7 +61,6 @@
8461
*/
8562
public class Lookup {
8663

87-
boolean init = false;
8864
boolean skip = false;
8965

9066
final LookupMethod method;
@@ -376,37 +352,11 @@ public int loadDefaultJavaCACertsFile(String certsFile) throws IOException, Gene
376352
}
377353

378354
private InputStream wrapJRubyNormalizedInputStream(String file) throws IOException {
379-
try {
380-
return JRubyFile.createResource(runtime, file).inputStream();
381-
}
382-
catch (NoSuchMethodError e) { // JRubyFile.createResource.inputStream (JRuby < 1.7.17)
383-
try {
384-
ChannelDescriptor descriptor = ChannelDescriptor.open(runtime.getCurrentDirectory(), file, new ModeFlags(ModeFlags.RDONLY));
385-
return ChannelStream.open(runtime, descriptor).newInputStream();
386-
}
387-
catch (NoSuchMethodError ex) {
388-
File f = new File(file);
389-
if ( ! f.isAbsolute() ) {
390-
f = new File(runtime.getCurrentDirectory(), file);
391-
}
392-
return new BufferedInputStream(new FileInputStream(f));
393-
}
394-
catch (FileExistsException ex) {
395-
// should not happen because ModeFlag does not contain CREAT.
396-
OpenSSL.debugStackTrace(ex);
397-
throw new IllegalStateException(ex);
398-
}
399-
catch (InvalidValueException ex) {
400-
// should not happen because ModeFlasg does not contain APPEND.
401-
OpenSSL.debugStackTrace(ex);
402-
throw new IllegalStateException(ex);
403-
}
404-
}
355+
return JRubyFile.createResource(runtime, file).inputStream();
405356
}
406357

407358
private String envEntry(final String key) {
408-
RubyHash env = (RubyHash) runtime.getObject().getConstant("ENV");
409-
return (String) env.get( runtime.newString(key) );
359+
return (String) runtime.getENV().get( runtime.newString(key) );
410360
}
411361

412362
/**
@@ -679,6 +629,7 @@ else if ( type == X509_LU_CRL ) {
679629
buffer.append('.').append(postfix).append(k);
680630

681631
final String path = buffer.toString();
632+
682633
if ( ! new File(path).exists() ) break;
683634

684635
if ( type == X509_LU_X509 ) {

0 commit comments

Comments
 (0)