Skip to content

Commit 6a5b3c3

Browse files
committed
fix indexBySubject returning correct index + degrade List type on other retrievals
1 parent 684b850 commit 6a5b3c3

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

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

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

30+
import java.util.Collection;
3031
import java.util.List;
3132

3233
/**
@@ -35,33 +36,34 @@
3536
* @author <a href="mailto:[email protected]">Ola Bini</a>
3637
*/
3738
public abstract class X509Object implements Comparable<X509Object> {
39+
3840
/**
3941
* c: X509_OBJECT_idx_by_subject
4042
*/
41-
public static int indexBySubject(List<? extends X509Object> h, int type, Name name) {
42-
int ix = 0;
43-
for ( X509Object oo : h ) {
44-
if ( type == oo.type() && oo.isName(name) ) return ix;
43+
public static int indexBySubject(final List<? extends X509Object> list, int type, Name name) {
44+
for ( int i = 0; i < list.size(); i++ ) {
45+
final X509Object obj = list.get(i);
46+
if ( type == obj.type() && obj.isName(name) ) return i;
4547
}
4648
return -1;
4749
}
4850

4951
/**
5052
* c: X509_OBJECT_retrieve_by_subject
5153
*/
52-
public static X509Object retrieveBySubject(final List<? extends X509Object> h, int type, Name name) {
53-
for ( X509Object o : h ) {
54-
if ( type == o.type() && o.isName(name) ) return o;
54+
public static X509Object retrieveBySubject(final Collection<? extends X509Object> list, int type, Name name) {
55+
for ( X509Object obj : list ) {
56+
if ( type == obj.type() && obj.isName(name) ) return obj;
5557
}
5658
return null;
5759
}
5860

5961
/**
6062
* c: X509_OBJECT_retrieve_match
6163
*/
62-
public static X509Object retrieveMatch(final List<? extends X509Object> h, X509Object x) {
63-
for ( X509Object o : h ) {
64-
if ( o.matches(x) ) return o;
64+
public static X509Object retrieveMatch(final Collection<? extends X509Object> list, X509Object x) {
65+
for ( X509Object obj : list ) {
66+
if ( obj.matches(x) ) return obj;
6567
}
6668
return null;
6769
}
@@ -79,4 +81,5 @@ public boolean matches(X509Object o) {
7981
public int compareTo(X509Object other) {
8082
return type() - other.type();
8183
}
84+
8285
}// X509_OBJECT

0 commit comments

Comments
 (0)