diff --git a/src/main/java/org/jruby/ext/openssl/impl/Signed.java b/src/main/java/org/jruby/ext/openssl/impl/Signed.java index 0acc45be..1dba04bf 100644 --- a/src/main/java/org/jruby/ext/openssl/impl/Signed.java +++ b/src/main/java/org/jruby/ext/openssl/impl/Signed.java @@ -354,19 +354,21 @@ private static X509AuxCertificate certificateFromASN1(ASN1Encodable current) thr } private static Set algorithmIdentifiersFromASN1Set(ASN1Encodable content) { - ASN1Set set = (ASN1Set)content; - Set result = new HashSet(); - for(Enumeration e = set.getObjects(); e.hasMoreElements();) { - result.add(AlgorithmIdentifier.getInstance(e.nextElement())); + ASN1Set set = (ASN1Set) content; + final int len = set.size(); + Set result = new HashSet<>(len); + for (int i = 0; i < len; i++) { + result.add(AlgorithmIdentifier.getInstance(set.getObjectAt(i))); } return result; } private static Collection signerInfosFromASN1Set(ASN1Encodable content) { - ASN1Set set = (ASN1Set)content; - Collection result = new ArrayList(); - for(Enumeration e = set.getObjects(); e.hasMoreElements();) { - result.add(SignerInfoWithPkey.getInstance(e.nextElement())); + ASN1Set set = (ASN1Set) content; + final int len = set.size(); + Collection result = new ArrayList<>(); + for (int i = 0; i < len; i++) { + result.add(SignerInfoWithPkey.getInstance(set.getObjectAt(i))); } return result; } diff --git a/src/main/java/org/jruby/ext/openssl/impl/SignerInfoWithPkey.java b/src/main/java/org/jruby/ext/openssl/impl/SignerInfoWithPkey.java index 3efd3422..8b8fd66f 100644 --- a/src/main/java/org/jruby/ext/openssl/impl/SignerInfoWithPkey.java +++ b/src/main/java/org/jruby/ext/openssl/impl/SignerInfoWithPkey.java @@ -72,11 +72,15 @@ public class SignerInfoWithPkey implements ASN1Encodable { private ASN1OctetString encryptedDigest; private ASN1Set unauthenticatedAttributes; - public static SignerInfoWithPkey getInstance(Object o) { - if(o instanceof SignerInfo) { - return (SignerInfoWithPkey)o; - } else if (o instanceof ASN1Sequence) { - return new SignerInfoWithPkey((ASN1Sequence)o); + public static SignerInfoWithPkey getInstance(ASN1Encodable o) { + if (o instanceof SignerInfo) { + final SignerInfo info = (SignerInfo) o; + return new SignerInfoWithPkey(info.getVersion(), info.getIssuerAndSerialNumber(), info.getDigestAlgorithm(), + info.getAuthenticatedAttributes(), info.getDigestEncryptionAlgorithm(), + info.getEncryptedDigest(), info.getUnauthenticatedAttributes()); + } + if (o instanceof ASN1Sequence) { + return new SignerInfoWithPkey((ASN1Sequence) o); } throw new IllegalArgumentException("unknown object in factory: " + o.getClass().getName()); @@ -97,13 +101,13 @@ public SignerInfoWithPkey dup() { SignerInfoWithPkey() { } - public SignerInfoWithPkey(ASN1Integer version, - IssuerAndSerialNumber issuerAndSerialNumber, - AlgorithmIdentifier digAlgorithm, - ASN1Set authenticatedAttributes, - AlgorithmIdentifier digEncryptionAlgorithm, - ASN1OctetString encryptedDigest, - ASN1Set unauthenticatedAttributes) { + public SignerInfoWithPkey(ASN1Integer version, + IssuerAndSerialNumber issuerAndSerialNumber, + AlgorithmIdentifier digAlgorithm, + ASN1Set authenticatedAttributes, + AlgorithmIdentifier digEncryptionAlgorithm, + ASN1OctetString encryptedDigest, + ASN1Set unauthenticatedAttributes) { this.version = version; this.issuerAndSerialNumber = issuerAndSerialNumber; this.digAlgorithm = digAlgorithm; @@ -113,8 +117,8 @@ public SignerInfoWithPkey(ASN1Integer version, this.unauthenticatedAttributes = unauthenticatedAttributes; } - public SignerInfoWithPkey(ASN1Sequence seq) { - Enumeration e = seq.getObjects(); + SignerInfoWithPkey(ASN1Sequence seq) { + Enumeration e = seq.getObjects(); version = (ASN1Integer)e.nextElement(); issuerAndSerialNumber = IssuerAndSerialNumber.getInstance(e.nextElement()); @@ -122,7 +126,7 @@ public SignerInfoWithPkey(ASN1Sequence seq) { Object obj = e.nextElement(); - if(obj instanceof ASN1TaggedObject) { + if (obj instanceof ASN1TaggedObject) { authenticatedAttributes = ASN1Set.getInstance((ASN1TaggedObject)obj, false); digEncryptionAlgorithm = AlgorithmIdentifier.getInstance(e.nextElement());