diff options
Diffstat (limited to 'gnu/java/security/x509')
-rw-r--r-- | gnu/java/security/x509/GnuPKIExtension.java | 4 | ||||
-rw-r--r-- | gnu/java/security/x509/PolicyNodeImpl.java | 39 | ||||
-rw-r--r-- | gnu/java/security/x509/X500DistinguishedName.java | 80 | ||||
-rw-r--r-- | gnu/java/security/x509/X509CRL.java | 57 | ||||
-rw-r--r-- | gnu/java/security/x509/X509CRLEntry.java | 37 | ||||
-rw-r--r-- | gnu/java/security/x509/X509CRLSelectorImpl.java | 16 | ||||
-rw-r--r-- | gnu/java/security/x509/X509CertPath.java | 46 | ||||
-rw-r--r-- | gnu/java/security/x509/X509CertSelectorImpl.java | 28 | ||||
-rw-r--r-- | gnu/java/security/x509/X509Certificate.java | 17 | ||||
-rw-r--r-- | gnu/java/security/x509/ext/BasicConstraints.java | 4 | ||||
-rw-r--r-- | gnu/java/security/x509/ext/CertificatePolicies.java | 57 | ||||
-rw-r--r-- | gnu/java/security/x509/ext/PolicyMappings.java | 8 |
12 files changed, 221 insertions, 172 deletions
diff --git a/gnu/java/security/x509/GnuPKIExtension.java b/gnu/java/security/x509/GnuPKIExtension.java index 8e74b8b24..774a8a55e 100644 --- a/gnu/java/security/x509/GnuPKIExtension.java +++ b/gnu/java/security/x509/GnuPKIExtension.java @@ -1,5 +1,5 @@ /* GnuPKIExtension.java -- interface for GNU PKI extensions. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -55,5 +55,5 @@ public interface GnuPKIExtension extends X509Extension */ Extension getExtension(OID oid); - Collection getExtensions(); + Collection<Extension> getExtensions(); } diff --git a/gnu/java/security/x509/PolicyNodeImpl.java b/gnu/java/security/x509/PolicyNodeImpl.java index 60d35574d..65dd472c7 100644 --- a/gnu/java/security/x509/PolicyNodeImpl.java +++ b/gnu/java/security/x509/PolicyNodeImpl.java @@ -1,5 +1,5 @@ /* PolicyNodeImpl.java -- An implementation of a policy tree node. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -56,9 +56,9 @@ public final class PolicyNodeImpl implements PolicyNode // ------------------------------------------------------------------------- private String policy; - private final Set expectedPolicies; - private final Set qualifiers; - private final Set children; + private final Set<String> expectedPolicies; + private final Set<PolicyQualifierInfo> qualifiers; + private final Set<PolicyNode> children; private PolicyNodeImpl parent; private int depth; private boolean critical; @@ -69,9 +69,9 @@ public final class PolicyNodeImpl implements PolicyNode public PolicyNodeImpl() { - expectedPolicies = new HashSet(); - qualifiers = new HashSet(); - children = new HashSet(); + expectedPolicies = new HashSet<String>(); + qualifiers = new HashSet<PolicyQualifierInfo>(); + children = new HashSet<PolicyNode>(); readOnly = false; critical = false; } @@ -90,11 +90,13 @@ public final class PolicyNodeImpl implements PolicyNode children.add(node); } - public Iterator getChildren() + @Override + public Iterator<? extends PolicyNode> getChildren() { return Collections.unmodifiableSet(children).iterator(); } + @Override public int getDepth() { return depth; @@ -107,7 +109,7 @@ public final class PolicyNodeImpl implements PolicyNode this.depth = depth; } - public void addAllExpectedPolicies(Set policies) + public void addAllExpectedPolicies(Set<String> policies) { if (readOnly) throw new IllegalStateException("read only"); @@ -121,24 +123,26 @@ public final class PolicyNodeImpl implements PolicyNode expectedPolicies.add(policy); } - public Set getExpectedPolicies() + @Override + public Set<String> getExpectedPolicies() { return Collections.unmodifiableSet(expectedPolicies); } + @Override public PolicyNode getParent() { return parent; } - public void addAllPolicyQualifiers (Collection qualifiers) + public void addAllPolicyQualifiers (Collection<? extends PolicyQualifierInfo> qualifiers) { - for (Iterator it = qualifiers.iterator(); it.hasNext(); ) + for (Iterator<? extends PolicyQualifierInfo> it = qualifiers.iterator(); it.hasNext(); ) { if (!(it.next() instanceof PolicyQualifierInfo)) throw new IllegalArgumentException ("can only add PolicyQualifierInfos"); } - qualifiers.addAll (qualifiers); + this.qualifiers.addAll (qualifiers); } public void addPolicyQualifier (PolicyQualifierInfo qualifier) @@ -148,11 +152,13 @@ public final class PolicyNodeImpl implements PolicyNode qualifiers.add(qualifier); } - public Set getPolicyQualifiers() + @Override + public Set<? extends PolicyQualifierInfo> getPolicyQualifiers() { return Collections.unmodifiableSet(qualifiers); } + @Override public String getValidPolicy() { return policy; @@ -165,6 +171,7 @@ public final class PolicyNodeImpl implements PolicyNode this.policy = policy; } + @Override public boolean isCritical() { return critical; @@ -182,7 +189,7 @@ public final class PolicyNodeImpl implements PolicyNode if (readOnly) return; readOnly = true; - for (Iterator it = getChildren(); it.hasNext(); ) + for (Iterator<? extends PolicyNode> it = getChildren(); it.hasNext(); ) ((PolicyNodeImpl) it.next()).setReadOnly(); } @@ -205,7 +212,7 @@ public final class PolicyNodeImpl implements PolicyNode buf.append(expectedPolicies); buf.append(") (children ("); final String nl = System.getProperty("line.separator"); - for (Iterator it = getChildren(); it.hasNext(); ) + for (Iterator<? extends PolicyNode> it = getChildren(); it.hasNext(); ) { buf.append(nl); buf.append(it.next().toString()); diff --git a/gnu/java/security/x509/X500DistinguishedName.java b/gnu/java/security/x509/X500DistinguishedName.java index e2e05c57e..ab7f99aa9 100644 --- a/gnu/java/security/x509/X500DistinguishedName.java +++ b/gnu/java/security/x509/X500DistinguishedName.java @@ -1,5 +1,5 @@ /* X500DistinguishedName.java -- X.500 distinguished name. - Copyright (C) 2004, 2006 Free Software Foundation, Inc. + Copyright (C) 2004, 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -83,8 +83,8 @@ public class X500DistinguishedName implements Principal public static final OID DC = new OID("0.9.2342.19200300.100.1.25"); public static final OID UID = new OID("0.9.2342.19200300.100.1.1"); - private List components; - private Map currentRdn; + private List<Map<OID,String>> components; + private Map<OID,String> currentRdn; private boolean fixed; private String stringRep; private byte[] encoded; @@ -94,8 +94,8 @@ public class X500DistinguishedName implements Principal public X500DistinguishedName() { - components = new LinkedList(); - currentRdn = new LinkedHashMap(); + components = new LinkedList<Map<OID,String>>(); + currentRdn = new LinkedHashMap<OID,String>(); components.add(currentRdn); } @@ -135,7 +135,7 @@ public class X500DistinguishedName implements Principal public void newRelativeDistinguishedName() { if (fixed || currentRdn.isEmpty()) return; - currentRdn = new LinkedHashMap(); + currentRdn = new LinkedHashMap<OID,String>(); components.add(currentRdn); } @@ -147,19 +147,19 @@ public class X500DistinguishedName implements Principal public int countComponents() { int count = 0; - for (Iterator it = components.iterator(); it.hasNext(); ) + for (Iterator<Map<OID,String>> it = components.iterator(); it.hasNext(); ) { - count += ((Map) it.next()).size(); + count += it.next().size(); } return count; } public boolean containsComponent(OID oid, String value) { - for (Iterator it = components.iterator(); it.hasNext(); ) + for (Iterator<Map<OID,String>> it = components.iterator(); it.hasNext(); ) { - Map rdn = (Map) it.next(); - String s = (String) rdn.get(oid); + Map<OID,String> rdn = it.next(); + String s = rdn.get(oid); if (s == null) continue; if (compressWS(value).equalsIgnoreCase(compressWS(s))) @@ -170,11 +170,11 @@ public class X500DistinguishedName implements Principal public String getComponent(OID oid) { - for (Iterator it = components.iterator(); it.hasNext(); ) + for (Iterator<Map<OID,String>> it = components.iterator(); it.hasNext(); ) { - Map rdn = (Map) it.next(); + Map<OID,String> rdn = it.next(); if (rdn.containsKey(oid)) - return (String) rdn.get(oid); + return rdn.get(oid); } return null; } @@ -183,7 +183,7 @@ public class X500DistinguishedName implements Principal { if (rdn >= size()) return null; - return (String) ((Map) components.get(rdn)).get(oid); + return components.get(rdn).get(oid); } public void putComponent(OID oid, String value) @@ -234,26 +234,26 @@ public class X500DistinguishedName implements Principal { if (fixed) return; fixed = true; - List newComps = new ArrayList(components.size()); - for (Iterator it = components.iterator(); it.hasNext(); ) + List<Map<OID,String>> newComps = + new ArrayList<Map<OID,String>>(components.size()); + for (Iterator<Map<OID,String>> it = components.iterator(); it.hasNext(); ) { - Map rdn = (Map) it.next(); + Map<OID,String> rdn = it.next(); rdn = Collections.unmodifiableMap(rdn); newComps.add(rdn); } components = Collections.unmodifiableList(newComps); - currentRdn = Collections.EMPTY_MAP; + currentRdn = Collections.emptyMap(); } public int hashCode() { int sum = 0; - for (Iterator it = components.iterator(); it.hasNext(); ) + for (Iterator<Map<OID,String>> it = components.iterator(); it.hasNext(); ) { - Map m = (Map) it.next(); - for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); ) + Map<OID,String> m = it.next(); + for (Map.Entry<OID,String> e : m.entrySet()) { - Map.Entry e = (Map.Entry) it2.next(); sum += e.getKey().hashCode(); sum += e.getValue().hashCode(); } @@ -269,12 +269,11 @@ public class X500DistinguishedName implements Principal return false; for (int i = 0; i < size(); i++) { - Map m = (Map) components.get(i); - for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); ) + Map<OID,String> m = components.get(i); + for (Map.Entry<OID,String> e : m.entrySet()) { - Map.Entry e = (Map.Entry) it2.next(); - OID oid = (OID) e.getKey(); - String v1 = (String) e.getValue(); + OID oid = e.getKey(); + String v1 = e.getValue(); String v2 = ((X500DistinguishedName) o).getComponent(oid, i); if (!compressWS(v1).equalsIgnoreCase(compressWS(v2))) return false; @@ -288,14 +287,15 @@ public class X500DistinguishedName implements Principal if (fixed && stringRep != null) return stringRep; CPStringBuilder str = new CPStringBuilder(); - for (Iterator it = components.iterator(); it.hasNext(); ) + for (Iterator<Map<OID,String>> it = components.iterator(); it.hasNext(); ) { - Map m = (Map) it.next(); - for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); ) + Map<OID,String> m = it.next(); + for (Iterator<Map.Entry<OID,String>> it2 = m.entrySet().iterator(); + it2.hasNext(); ) { - Map.Entry entry = (Map.Entry) it2.next(); - OID oid = (OID) entry.getKey(); - String value = (String) entry.getValue(); + Map.Entry<OID,String> entry = it2.next(); + OID oid = entry.getKey(); + String value = entry.getValue(); if (oid.equals(CN)) str.append("CN"); else if (oid.equals(C)) @@ -334,18 +334,16 @@ public class X500DistinguishedName implements Principal if (fixed && encoded != null) return (byte[]) encoded.clone(); - ArrayList name = new ArrayList(components.size()); - for (Iterator it = components.iterator(); it.hasNext(); ) + ArrayList<DERValue> name = new ArrayList<DERValue>(components.size()); + for (Map<OID,String> m : components) { - Map m = (Map) it.next(); if (m.isEmpty()) continue; - Set rdn = new HashSet(); - for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); ) + Set<DERValue> rdn = new HashSet<DERValue>(); + for (Map.Entry<OID,String> e : m.entrySet()) { - Map.Entry e = (Map.Entry) it2.next(); - ArrayList atav = new ArrayList(2); + ArrayList<DERValue> atav = new ArrayList<DERValue>(2); atav.add(new DERValue(DER.OBJECT_IDENTIFIER, e.getKey())); atav.add(new DERValue(DER.UTF8_STRING, e.getValue())); rdn.add(new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, atav)); diff --git a/gnu/java/security/x509/X509CRL.java b/gnu/java/security/x509/X509CRL.java index 518edaa24..9e1ed0f5c 100644 --- a/gnu/java/security/x509/X509CRL.java +++ b/gnu/java/security/x509/X509CRL.java @@ -1,5 +1,5 @@ /* X509CRL.java -- X.509 certificate revocation list. - Copyright (C) 2003, 2004, 2010 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2010, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -63,7 +63,6 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import java.util.logging.Logger; @@ -92,12 +91,11 @@ public class X509CRL extends java.security.cert.X509CRL private byte[] tbsCRLBytes; private int version; private OID algId; - private byte[] algParams; private Date thisUpdate; private Date nextUpdate; private X500DistinguishedName issuerDN; - private HashMap revokedCerts; - private HashMap extensions; + private HashMap<BigInteger,X509CRLEntry> revokedCerts; + private HashMap<OID,Extension> extensions; private OID sigAlg; private byte[] sigAlgParams; @@ -117,8 +115,8 @@ public class X509CRL extends java.security.cert.X509CRL public X509CRL(InputStream encoded) throws CRLException, IOException { super(); - revokedCerts = new HashMap(); - extensions = new HashMap(); + revokedCerts = new HashMap<BigInteger,X509CRLEntry>(); + extensions = new HashMap<OID,Extension>(); try { parse(encoded); @@ -150,11 +148,13 @@ public class X509CRL extends java.security.cert.X509CRL return revokedCerts.hashCode(); } + @Override public byte[] getEncoded() throws CRLException { return (byte[]) encoded.clone(); } + @Override public void verify(PublicKey key) throws CRLException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException @@ -163,6 +163,7 @@ public class X509CRL extends java.security.cert.X509CRL doVerify(sig, key); } + @Override public void verify(PublicKey key, String provider) throws CRLException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException @@ -171,11 +172,13 @@ public class X509CRL extends java.security.cert.X509CRL doVerify(sig, key); } + @Override public int getVersion() { return version; } + @Override public Principal getIssuerDN() { return issuerDN; @@ -186,11 +189,13 @@ public class X509CRL extends java.security.cert.X509CRL return new X500Principal(issuerDN.getDer()); } + @Override public Date getThisUpdate() { return (Date) thisUpdate.clone(); } + @Override public Date getNextUpdate() { if (nextUpdate != null) @@ -198,26 +203,31 @@ public class X509CRL extends java.security.cert.X509CRL return null; } + @Override public java.security.cert.X509CRLEntry getRevokedCertificate(BigInteger serialNo) { - return (java.security.cert.X509CRLEntry) revokedCerts.get(serialNo); + return revokedCerts.get(serialNo); } - public Set getRevokedCertificates() + @Override + public Set<? extends X509CRLEntry> getRevokedCertificates() { - return Collections.unmodifiableSet(new HashSet(revokedCerts.values())); + return Collections.unmodifiableSet(new HashSet<X509CRLEntry>(revokedCerts.values())); } + @Override public byte[] getTBSCertList() throws CRLException { return (byte[]) tbsCRLBytes.clone(); } + @Override public byte[] getSignature() { return (byte[]) rawSig.clone(); } + @Override public String getSigAlgName() { if (sigAlg.equals(ID_DSA_WITH_SHA1)) @@ -231,11 +241,13 @@ public class X509CRL extends java.security.cert.X509CRL return "unknown"; } + @Override public String getSigAlgOID() { return sigAlg.toString(); } + @Override public byte[] getSigAlgParams() { if (sigAlgParams != null) @@ -248,33 +260,30 @@ public class X509CRL extends java.security.cert.X509CRL public boolean hasUnsupportedCriticalExtension() { - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + for (Extension e : extensions.values()) { - Extension e = (Extension) it.next(); if (e.isCritical() && !e.isSupported()) return true; } return false; } - public Set getCriticalExtensionOIDs() + public Set<String> getCriticalExtensionOIDs() { - HashSet s = new HashSet(); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + HashSet<String> s = new HashSet<String>(); + for (Extension e : extensions.values()) { - Extension e = (Extension) it.next(); if (e.isCritical()) s.add(e.getOid().toString()); } return Collections.unmodifiableSet(s); } - public Set getNonCriticalExtensionOIDs() + public Set<String> getNonCriticalExtensionOIDs() { - HashSet s = new HashSet(); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + HashSet<String> s = new HashSet<String>(); + for (Extension e : extensions.values()) { - Extension e = (Extension) it.next(); if (!e.isCritical()) s.add(e.getOid().toString()); } @@ -294,12 +303,14 @@ public class X509CRL extends java.security.cert.X509CRL // GnuPKIExtension method. // ------------------------------------------------------------------------- + @Override public Extension getExtension(OID oid) { - return (Extension) extensions.get(oid); + return extensions.get(oid); } - public Collection getExtensions() + @Override + public Collection<Extension> getExtensions() { return extensions.values(); } @@ -307,6 +318,7 @@ public class X509CRL extends java.security.cert.X509CRL // CRL methods. // ------------------------------------------------------------------------- + @Override public String toString() { return X509CRL.class.getName(); @@ -382,7 +394,6 @@ public class X509CRL extends java.security.cert.X509CRL val = der.read(); if (Configuration.DEBUG) log.fine("read parameters len == " + val.getEncodedLength()); - algParams = val.getEncoded(); if (val.isConstructed()) in.skip(val.getLength()); } diff --git a/gnu/java/security/x509/X509CRLEntry.java b/gnu/java/security/x509/X509CRLEntry.java index 64adf7f69..b54f8eae6 100644 --- a/gnu/java/security/x509/X509CRLEntry.java +++ b/gnu/java/security/x509/X509CRLEntry.java @@ -1,5 +1,5 @@ /* X509CRLEntry.java -- an entry in a X.509 CRL. - Copyright (C) 2003, 2004, 2010 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2010, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -52,7 +52,6 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import java.util.logging.Logger; @@ -78,7 +77,7 @@ class X509CRLEntry extends java.security.cert.X509CRLEntry private Date revocationDate; /** The CRL entry extensions. */ - private HashMap extensions; + private HashMap<OID,Extension> extensions; // Constructor. // ------------------------------------------------------------------------ @@ -96,7 +95,7 @@ class X509CRLEntry extends java.security.cert.X509CRLEntry throws CRLException, IOException { super(); - extensions = new HashMap(); + extensions = new HashMap<OID,Extension>(); try { parse(version, encoded); @@ -114,6 +113,7 @@ class X509CRLEntry extends java.security.cert.X509CRLEntry // X509CRLEntry methods. // ------------------------------------------------------------------------ + @Override public boolean equals(Object o) { if (!(o instanceof X509CRLEntry)) @@ -122,31 +122,37 @@ class X509CRLEntry extends java.security.cert.X509CRLEntry ((X509CRLEntry) o).getRevocationDate().equals(revocationDate); } + @Override public int hashCode() { return serialNo.hashCode(); } + @Override public byte[] getEncoded() throws CRLException { return (byte[]) encoded.clone(); } + @Override public BigInteger getSerialNumber() { return serialNo; } + @Override public Date getRevocationDate() { return (Date) revocationDate.clone(); } + @Override public boolean hasExtensions() { return ! extensions.isEmpty(); } + @Override public String toString() { return "X509CRLEntry serial=" + serialNo + " revocation date=" @@ -158,33 +164,30 @@ class X509CRLEntry extends java.security.cert.X509CRLEntry public boolean hasUnsupportedCriticalExtension() { - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + for (Extension e : extensions.values()) { - Extension e = (Extension) it.next(); if (e.isCritical() && !e.isSupported()) return true; } return false; } - public Set getCriticalExtensionOIDs() + public Set<String> getCriticalExtensionOIDs() { - HashSet s = new HashSet(); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + HashSet<String> s = new HashSet<String>(); + for (Extension e : extensions.values()) { - Extension e = (Extension) it.next(); if (e.isCritical()) s.add(e.getOid().toString()); } return Collections.unmodifiableSet(s); } - public Set getNonCriticalExtensionOIDs() + public Set<String> getNonCriticalExtensionOIDs() { - HashSet s = new HashSet(); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + HashSet<String> s = new HashSet<String>(); + for (Extension e : extensions.values()) { - Extension e = (Extension) it.next(); if (!e.isCritical()) s.add(e.getOid().toString()); } @@ -204,12 +207,14 @@ class X509CRLEntry extends java.security.cert.X509CRLEntry // GnuPKIExtension method. // ------------------------------------------------------------------------- + @Override public Extension getExtension(OID oid) { - return (Extension) extensions.get(oid); + return extensions.get(oid); } - public Collection getExtensions() + @Override + public Collection<Extension> getExtensions() { return extensions.values(); } diff --git a/gnu/java/security/x509/X509CRLSelectorImpl.java b/gnu/java/security/x509/X509CRLSelectorImpl.java index 582d18583..c8f25d58d 100644 --- a/gnu/java/security/x509/X509CRLSelectorImpl.java +++ b/gnu/java/security/x509/X509CRLSelectorImpl.java @@ -1,5 +1,5 @@ /* X509CRLSelectorImpl.java -- implementation of an X509CRLSelector. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -48,7 +48,6 @@ import java.security.cert.X509CRL; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import javax.security.auth.x500.X500Principal; @@ -63,14 +62,14 @@ public class X509CRLSelectorImpl implements CRLSelector // Fields. // ------------------------------------------------------------------------- - private Set issuerNames; + private Set<X500DistinguishedName> issuerNames; // Constructor. // ------------------------------------------------------------------------- public X509CRLSelectorImpl() { - issuerNames = new HashSet(); + issuerNames = new HashSet<X500DistinguishedName>(); } // Instance methods. @@ -89,18 +88,19 @@ public class X509CRLSelectorImpl implements CRLSelector public void addIssuerName(Principal issuerName) throws IOException { if (issuerName instanceof X500DistinguishedName) - issuerNames.add(issuerName); + issuerNames.add((X500DistinguishedName) issuerName); else if (issuerName instanceof X500Principal) issuerNames.add(new X500DistinguishedName(((X500Principal) issuerName).getEncoded())); else issuerNames.add(new X500DistinguishedName(issuerName.getName())); } - public Collection getIssuerNames() + public Collection<X500DistinguishedName> getIssuerNames() { return Collections.unmodifiableSet(issuerNames); } + @Override public Object clone() { X509CRLSelectorImpl copy = new X509CRLSelectorImpl(); @@ -108,6 +108,7 @@ public class X509CRLSelectorImpl implements CRLSelector return copy; } + @Override public boolean match(CRL crl) { if (!(crl instanceof X509CRL)) @@ -122,9 +123,8 @@ public class X509CRLSelectorImpl implements CRLSelector thisName = new X500DistinguishedName(((X500Principal) p).getEncoded()); else thisName = new X500DistinguishedName(p.getName()); - for (Iterator it = issuerNames.iterator(); it.hasNext(); ) + for (X500DistinguishedName name : issuerNames) { - X500DistinguishedName name = (X500DistinguishedName) it.next(); if (thisName.equals(name)) return true; } diff --git a/gnu/java/security/x509/X509CertPath.java b/gnu/java/security/x509/X509CertPath.java index e8ed6bf35..d2e12d269 100644 --- a/gnu/java/security/x509/X509CertPath.java +++ b/gnu/java/security/x509/X509CertPath.java @@ -1,5 +1,5 @@ /* X509CertPath.java -- an X.509 certificate path. - Copyright (C) 2004 Free Software Fonudation, Inc. + Copyright (C) 2004, 2014 Free Software Fonudation, Inc. This file is part of GNU Classpath. @@ -71,25 +71,25 @@ public class X509CertPath extends CertPath // Fields. // ------------------------------------------------------------------------- - public static final List ENCODINGS = Collections.unmodifiableList( + public static final List<String> ENCODINGS = Collections.unmodifiableList( Arrays.asList(new String[] { "PkiPath", "PKCS7" })); private static final OID PKCS7_SIGNED_DATA = new OID("1.2.840.113549.1.7.2"); private static final OID PKCS7_DATA = new OID("1.2.840.113549.1.7.1"); /** The certificate path. */ - private List path; + private List<Certificate> path; /** The cached PKCS #7 encoded bytes. */ - private byte[] pkcs_encoded; + private byte[] pkcsEncoded; /** The cached PkiPath encoded bytes. */ - private byte[] pki_encoded; + private byte[] pkiEncoded; // Constructor. // ------------------------------------------------------------------------- - public X509CertPath(List path) + public X509CertPath(List<? extends Certificate> path) { super("X.509"); this.path = Collections.unmodifiableList(path); @@ -97,7 +97,7 @@ public class X509CertPath extends CertPath public X509CertPath(InputStream in) throws CertificateEncodingException { - this(in, (String) ENCODINGS.get(0)); + this(in, ENCODINGS.get(0)); } public X509CertPath(InputStream in, String encoding) @@ -117,53 +117,53 @@ public class X509CertPath extends CertPath // Instance methods. // ------------------------------------------------------------------------- - public List getCertificates() + public List<Certificate> getCertificates() { return path; // already unmodifiable } public byte[] getEncoded() throws CertificateEncodingException { - return getEncoded((String) ENCODINGS.get(0)); + return getEncoded(ENCODINGS.get(0)); } public byte[] getEncoded(String encoding) throws CertificateEncodingException { if (encoding.equalsIgnoreCase("PkiPath")) { - if (pki_encoded == null) + if (pkiEncoded == null) { try { - pki_encoded = encodePki(); + pkiEncoded = encodePki(); } catch (IOException ioe) { throw new CertificateEncodingException(); } } - return (byte[]) pki_encoded.clone(); + return (byte[]) pkiEncoded.clone(); } else if (encoding.equalsIgnoreCase("PKCS7")) { - if (pkcs_encoded == null) + if (pkcsEncoded == null) { try { - pkcs_encoded = encodePKCS(); + pkcsEncoded = encodePKCS(); } catch (IOException ioe) { throw new CertificateEncodingException(); } } - return (byte[]) pkcs_encoded.clone(); + return (byte[]) pkcsEncoded.clone(); } else throw new CertificateEncodingException("unknown encoding: " + encoding); } - public Iterator getEncodings() + public Iterator<String> getEncodings() { return ENCODINGS.iterator(); // already unmodifiable } @@ -233,7 +233,7 @@ public class X509CertPath extends CertPath else throw new CertificateEncodingException("unknown encoding: " + encoding); - LinkedList certs = new LinkedList(); + LinkedList<Certificate> certs = new LinkedList<Certificate>(); int len = 0; while (len < path.getLength()) { @@ -259,9 +259,9 @@ public class X509CertPath extends CertPath synchronized (path) { ByteArrayOutputStream out = new ByteArrayOutputStream(); - for (Iterator i = path.iterator(); i.hasNext(); ) + for (Iterator<Certificate> i = path.iterator(); i.hasNext(); ) { - out.write(((Certificate) i.next()).getEncoded()); + out.write(i.next().getEncoded()); } byte[] b = out.toByteArray(); DERValue val = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, @@ -275,7 +275,7 @@ public class X509CertPath extends CertPath { synchronized (path) { - ArrayList signedData = new ArrayList(5); + ArrayList<DERValue> signedData = new ArrayList<DERValue>(5); signedData.add(new DERValue(DER.INTEGER, BigInteger.ONE)); signedData.add(new DERValue(DER.CONSTRUCTED | DER.SET, Collections.EMPTY_SET)); @@ -283,9 +283,9 @@ public class X509CertPath extends CertPath Collections.singletonList( new DERValue(DER.OBJECT_IDENTIFIER, PKCS7_DATA)))); ByteArrayOutputStream out = new ByteArrayOutputStream(); - for (Iterator i = path.iterator(); i.hasNext(); ) + for (Iterator<Certificate> i = path.iterator(); i.hasNext(); ) { - out.write(((Certificate) i.next()).getEncoded()); + out.write(i.next().getEncoded()); } byte[] b = out.toByteArray(); signedData.add(new DERValue(DER.CONSTRUCTED | DER.CONTEXT, @@ -293,7 +293,7 @@ public class X509CertPath extends CertPath DERValue sdValue = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, signedData); - ArrayList contentInfo = new ArrayList(2); + ArrayList<DERValue> contentInfo = new ArrayList<DERValue>(2); contentInfo.add(new DERValue(DER.OBJECT_IDENTIFIER, PKCS7_SIGNED_DATA)); contentInfo.add(new DERValue(DER.CONSTRUCTED | DER.CONTEXT, sdValue)); return new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, diff --git a/gnu/java/security/x509/X509CertSelectorImpl.java b/gnu/java/security/x509/X509CertSelectorImpl.java index 5201a76b9..e7c7ff81b 100644 --- a/gnu/java/security/x509/X509CertSelectorImpl.java +++ b/gnu/java/security/x509/X509CertSelectorImpl.java @@ -1,5 +1,5 @@ /* X509CertSelectorImpl.java -- implementation of an X509CertSelector. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -61,16 +61,16 @@ public class X509CertSelectorImpl implements CertSelector // Fields. // ------------------------------------------------------------------------- - private Set issuerNames; - private Set subjectNames; + private Set<X500DistinguishedName> issuerNames; + private Set<X500DistinguishedName> subjectNames; // Constructor. // ------------------------------------------------------------------------- public X509CertSelectorImpl() { - issuerNames = new HashSet(); - subjectNames = new HashSet(); + issuerNames = new HashSet<X500DistinguishedName>(); + subjectNames = new HashSet<X500DistinguishedName>(); } // Instance methods. @@ -89,14 +89,14 @@ public class X509CertSelectorImpl implements CertSelector public void addIssuerName(Principal issuerName) throws IOException { if (issuerName instanceof X500DistinguishedName) - issuerNames.add(issuerName); + issuerNames.add((X500DistinguishedName) issuerName); else if (issuerName instanceof X500Principal) issuerNames.add(new X500DistinguishedName(((X500Principal) issuerName).getEncoded())); else issuerNames.add(new X500DistinguishedName(issuerName.getName())); } - public Collection getIssuerNames() + public Collection<X500DistinguishedName> getIssuerNames() { return Collections.unmodifiableSet(issuerNames); } @@ -114,18 +114,19 @@ public class X509CertSelectorImpl implements CertSelector public void addSubjectName(Principal subjectName) throws IOException { if (subjectName instanceof X500DistinguishedName) - subjectNames.add(subjectName); + subjectNames.add((X500DistinguishedName) subjectName); else if (subjectName instanceof X500Principal) subjectNames.add(new X500DistinguishedName(((X500Principal) subjectName).getEncoded())); else subjectNames.add(new X500DistinguishedName(subjectName.getName())); } - public Collection getSubjectNames() + public Collection<X500DistinguishedName> getSubjectNames() { return Collections.unmodifiableSet(subjectNames); } + @Override public Object clone() { X509CertSelectorImpl copy = new X509CertSelectorImpl(); @@ -134,6 +135,7 @@ public class X509CertSelectorImpl implements CertSelector return copy; } + @Override public boolean match(Certificate cert) { if (!(cert instanceof X509Certificate)) @@ -154,9 +156,9 @@ public class X509CertSelectorImpl implements CertSelector matchIssuer = true; else { - for (Iterator it = issuerNames.iterator(); it.hasNext(); ) + for (Iterator<X500DistinguishedName> it = issuerNames.iterator(); it.hasNext(); ) { - X500DistinguishedName name = (X500DistinguishedName) it.next(); + X500DistinguishedName name = it.next(); if (thisName.equals(name)) { matchIssuer = true; @@ -177,9 +179,9 @@ public class X509CertSelectorImpl implements CertSelector matchSubject = true; else { - for (Iterator it = subjectNames.iterator(); it.hasNext(); ) + for (Iterator<X500DistinguishedName> it = subjectNames.iterator(); it.hasNext(); ) { - X500DistinguishedName name = (X500DistinguishedName) it.next(); + X500DistinguishedName name = it.next(); if (thisName.equals(name)) { matchSubject = true; diff --git a/gnu/java/security/x509/X509Certificate.java b/gnu/java/security/x509/X509Certificate.java index 14c565264..c7856bd0c 100644 --- a/gnu/java/security/x509/X509Certificate.java +++ b/gnu/java/security/x509/X509Certificate.java @@ -1,5 +1,5 @@ /* X509Certificate.java -- X.509 certificate. - Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -84,7 +84,6 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -389,9 +388,8 @@ public class X509Certificate extends java.security.cert.X509Certificate public boolean hasUnsupportedCriticalExtension() { - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + for (Extension e : extensions.values()) { - Extension e = (Extension) it.next(); if (e.isCritical() && !e.isSupported()) return true; } @@ -433,12 +431,14 @@ public class X509Certificate extends java.security.cert.X509Certificate // GnuPKIExtension method. // ------------------------------------------------------------------------- + @Override public Extension getExtension(OID oid) { - return (Extension) extensions.get(oid); + return extensions.get(oid); } - public Collection getExtensions() + @Override + public Collection<Extension> getExtensions() { return extensions.values(); } @@ -502,9 +502,9 @@ public class X509Certificate extends java.security.cert.X509Certificate out.println(" issuerUniqueId = " + issuerUniqueId + ";"); out.println(" subjectUniqueId = " + subjectUniqueId + ";"); out.println(" extensions = {"); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + for (Extension e : extensions.values()) { - out.println(" " + it.next()); + out.println(" " + e); } out.println(" }"); out.println(" }"); @@ -520,6 +520,7 @@ public class X509Certificate extends java.security.cert.X509Certificate return subjectKey; } + @Override public boolean equals(Object other) { if (!(other instanceof X509Certificate)) diff --git a/gnu/java/security/x509/ext/BasicConstraints.java b/gnu/java/security/x509/ext/BasicConstraints.java index d8f5c6158..52d9f39cd 100644 --- a/gnu/java/security/x509/ext/BasicConstraints.java +++ b/gnu/java/security/x509/ext/BasicConstraints.java @@ -1,5 +1,5 @@ /* BasicConstraints.java -- the basic constraints extension. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -111,7 +111,7 @@ public class BasicConstraints extends Extension.Value { if (encoded == null) { - List bc = new ArrayList (2); + List<DERValue> bc = new ArrayList<DERValue> (2); bc.add (new DERValue (DER.BOOLEAN, Boolean.valueOf (ca))); if (pathLenConstraint >= 0) bc.add (new DERValue (DER.INTEGER, diff --git a/gnu/java/security/x509/ext/CertificatePolicies.java b/gnu/java/security/x509/ext/CertificatePolicies.java index 874b8eeeb..9b36485b2 100644 --- a/gnu/java/security/x509/ext/CertificatePolicies.java +++ b/gnu/java/security/x509/ext/CertificatePolicies.java @@ -1,5 +1,5 @@ /* CertificatePolicies.java -- certificate policy extension. - Copyright (C) 2004, 2006 Free Software Foundation, Inc. + Copyright (C) 2004, 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -113,24 +113,49 @@ public class CertificatePolicies extends Extension.Value public CertificatePolicies (final List<OID> policies, final Map<OID, List<PolicyQualifierInfo>> policyQualifierInfos) { - for (Iterator it = policies.iterator(); it.hasNext(); ) - if (!(it.next() instanceof OID)) - throw new IllegalArgumentException ("policies must be OIDs"); - for (Iterator it = policyQualifierInfos.entrySet().iterator(); it.hasNext();) + List<OID> polCopy = new ArrayList<OID>(policies.size()); + try { - Map.Entry e = (Map.Entry) it.next(); - if (!(e.getKey() instanceof OID) || !policies.contains (e.getKey())) - throw new IllegalArgumentException - ("policyQualifierInfos keys must be OIDs"); - if (!(e.getValue() instanceof List)) - throw new IllegalArgumentException - ("policyQualifierInfos values must be Lists of PolicyQualifierInfos"); - for (Iterator it2 = ((List) e.getValue()).iterator(); it.hasNext(); ) - if (!(it2.next() instanceof PolicyQualifierInfo)) + for (OID o : policies) { polCopy.add(o); } + } + catch (ClassCastException e) + { + throw new IllegalArgumentException ("policies must be OIDs", e); + } + for (Map.Entry<OID,List<PolicyQualifierInfo>> e : policyQualifierInfos.entrySet()) + { + try + { + if (!policies.contains (e.getKey())) + throw new IllegalArgumentException + ("policyQualifierInfos keys must be OIDs"); + } + catch (ClassCastException cce) + { + throw new IllegalArgumentException + ("policyQualifierInfos keys must be OIDs", cce); + } + try + { + e.getValue(); + } + catch (ClassCastException cce) + { + throw new IllegalArgumentException + ("policyQualifierInfos values must be Lists of PolicyQualifierInfos", cce); + } + try + { + for (Iterator<PolicyQualifierInfo> i = e.getValue().iterator(); + i.hasNext(); i.next()); + } + catch (ClassCastException cce) + { throw new IllegalArgumentException - ("policyQualifierInfos values must be Lists of PolicyQualifierInfos"); + ("policyQualifierInfos values must be Lists of PolicyQualifierInfos", cce); + } } - this.policies = Collections.unmodifiableList (new ArrayList<OID>(policies)); + this.policies = Collections.unmodifiableList (polCopy); this.policyQualifierInfos = Collections.unmodifiableMap (new HashMap<OID, List<PolicyQualifierInfo>>(policyQualifierInfos)); } diff --git a/gnu/java/security/x509/ext/PolicyMappings.java b/gnu/java/security/x509/ext/PolicyMappings.java index 0493ed89d..eeac340d3 100644 --- a/gnu/java/security/x509/ext/PolicyMappings.java +++ b/gnu/java/security/x509/ext/PolicyMappings.java @@ -1,5 +1,5 @@ /* PolicyMappings.java -- policy mappings extension. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -56,7 +56,7 @@ public class PolicyMappings extends Extension.Value public static final OID ID = new OID("2.5.29.33"); - private final Map mappings; + private final Map<OID,OID> mappings; // Constructor. // ------------------------------------------------------------------------- @@ -69,7 +69,7 @@ public class PolicyMappings extends Extension.Value if (!maps.isConstructed()) throw new IOException("malformed PolicyMappings"); int len = 0; - HashMap _mappings = new HashMap(); + HashMap<OID,OID> _mappings = new HashMap<OID,OID>(); while (len < maps.getLength()) { DERValue map = der.read(); @@ -94,7 +94,7 @@ public class PolicyMappings extends Extension.Value public OID getSubjectDomainPolicy(OID issuerDomainPolicy) { - return (OID) mappings.get(issuerDomainPolicy); + return mappings.get(issuerDomainPolicy); } public String toString() |