提交 af9d07b8 编写于 作者: S smarks

7012003: diamond conversion for ssl

Reviewed-by: wetmore
上级 1c541e4b
...@@ -393,7 +393,7 @@ final class CipherSuite implements Comparable { ...@@ -393,7 +393,7 @@ final class CipherSuite implements Comparable {
// Map BulkCipher -> Boolean(available) // Map BulkCipher -> Boolean(available)
private final static Map<BulkCipher,Boolean> availableCache = private final static Map<BulkCipher,Boolean> availableCache =
new HashMap<BulkCipher,Boolean>(8); new HashMap<>(8);
// descriptive name including key size, e.g. AES/128 // descriptive name including key size, e.g. AES/128
final String description; final String description;
......
...@@ -221,7 +221,7 @@ final class CipherSuiteList { ...@@ -221,7 +221,7 @@ final class CipherSuiteList {
private static CipherSuiteList buildAvailableCache(int minPriority) { private static CipherSuiteList buildAvailableCache(int minPriority) {
// SortedSet automatically arranges ciphersuites in default // SortedSet automatically arranges ciphersuites in default
// preference order // preference order
Set<CipherSuite> cipherSuites = new TreeSet<CipherSuite>(); Set<CipherSuite> cipherSuites = new TreeSet<>();
Collection<CipherSuite> allowedCipherSuites = Collection<CipherSuite> allowedCipherSuites =
CipherSuite.allowedCipherSuites(); CipherSuite.allowedCipherSuites();
for (CipherSuite c : allowedCipherSuites) { for (CipherSuite c : allowedCipherSuites) {
......
...@@ -655,7 +655,7 @@ final class ClientHandshaker extends Handshaker { ...@@ -655,7 +655,7 @@ final class ClientHandshaker extends Handshaker {
if (certRequest != null) { if (certRequest != null) {
X509ExtendedKeyManager km = sslContext.getX509KeyManager(); X509ExtendedKeyManager km = sslContext.getX509KeyManager();
ArrayList<String> keytypesTmp = new ArrayList<String>(4); ArrayList<String> keytypesTmp = new ArrayList<>(4);
for (int i = 0; i < certRequest.types.length; i++) { for (int i = 0; i < certRequest.types.length; i++) {
String typeName; String typeName;
...@@ -1174,8 +1174,7 @@ final class ClientHandshaker extends Handshaker { ...@@ -1174,8 +1174,7 @@ final class ClientHandshaker extends Handshaker {
"Can't reuse existing SSL client session"); "Can't reuse existing SSL client session");
} }
Collection<CipherSuite> cipherList = Collection<CipherSuite> cipherList = new ArrayList<>(2);
new ArrayList<CipherSuite>(2);
cipherList.add(sessionSuite); cipherList.add(sessionSuite);
if (!secureRenegotiation && if (!secureRenegotiation &&
cipherSuites.contains(CipherSuite.C_SCSV)) { cipherSuites.contains(CipherSuite.C_SCSV)) {
...@@ -1193,7 +1192,7 @@ final class ClientHandshaker extends Handshaker { ...@@ -1193,7 +1192,7 @@ final class ClientHandshaker extends Handshaker {
// exclude SCSV for secure renegotiation // exclude SCSV for secure renegotiation
if (secureRenegotiation && cipherSuites.contains(CipherSuite.C_SCSV)) { if (secureRenegotiation && cipherSuites.contains(CipherSuite.C_SCSV)) {
Collection<CipherSuite> cipherList = Collection<CipherSuite> cipherList =
new ArrayList<CipherSuite>(cipherSuites.size() - 1); new ArrayList<>(cipherSuites.size() - 1);
for (CipherSuite suite : cipherSuites.collection()) { for (CipherSuite suite : cipherSuites.collection()) {
if (suite != CipherSuite.C_SCSV) { if (suite != CipherSuite.C_SCSV) {
cipherList.add(suite); cipherList.add(suite);
......
...@@ -98,7 +98,7 @@ public final class DefaultSSLContextImpl extends SSLContextImpl { ...@@ -98,7 +98,7 @@ public final class DefaultSSLContextImpl extends SSLContextImpl {
return defaultKeyManagers; return defaultKeyManagers;
} }
final Map<String,String> props = new HashMap<String,String>(); final Map<String,String> props = new HashMap<>();
AccessController.doPrivileged( AccessController.doPrivileged(
new PrivilegedExceptionAction<Object>() { new PrivilegedExceptionAction<Object>() {
public Object run() throws Exception { public Object run() throws Exception {
......
...@@ -258,7 +258,7 @@ static final class ClientHello extends HandshakeMessage { ...@@ -258,7 +258,7 @@ static final class ClientHello extends HandshakeMessage {
// add server_name extension // add server_name extension
void addServerNameIndicationExtension(String hostname) { void addServerNameIndicationExtension(String hostname) {
// We would have checked that the hostname ia a FQDN. // We would have checked that the hostname ia a FQDN.
ArrayList<String> hostnames = new ArrayList<String>(1); ArrayList<String> hostnames = new ArrayList<>(1);
hostnames.add(hostname); hostnames.add(hostname);
try { try {
...@@ -434,7 +434,7 @@ class CertificateMsg extends HandshakeMessage ...@@ -434,7 +434,7 @@ class CertificateMsg extends HandshakeMessage
CertificateMsg(HandshakeInStream input) throws IOException { CertificateMsg(HandshakeInStream input) throws IOException {
int chainLen = input.getInt24(); int chainLen = input.getInt24();
List<Certificate> v = new ArrayList<Certificate>(4); List<Certificate> v = new ArrayList<>(4);
CertificateFactory cf = null; CertificateFactory cf = null;
while (chainLen > 0) { while (chainLen > 0) {
...@@ -1328,7 +1328,7 @@ class CertificateRequest extends HandshakeMessage ...@@ -1328,7 +1328,7 @@ class CertificateRequest extends HandshakeMessage
// read the certificate_authorities // read the certificate_authorities
int len = input.getInt16(); int len = input.getInt16();
ArrayList<DistinguishedName> v = new ArrayList<DistinguishedName>(); ArrayList<DistinguishedName> v = new ArrayList<>();
while (len >= 3) { while (len >= 3) {
DistinguishedName dn = new DistinguishedName(input); DistinguishedName dn = new DistinguishedName(input);
v.add(dn); v.add(dn);
...@@ -1719,7 +1719,7 @@ static final class CertificateVerify extends HandshakeMessage { ...@@ -1719,7 +1719,7 @@ static final class CertificateVerify extends HandshakeMessage {
// Note that this will prevent the Spi classes from being GC'd. We assume // Note that this will prevent the Spi classes from being GC'd. We assume
// that is not a problem. // that is not a problem.
private final static Map<Class,Object> methodCache = private final static Map<Class,Object> methodCache =
new ConcurrentHashMap<Class,Object>(); new ConcurrentHashMap<>();
private static void digestKey(MessageDigest md, SecretKey key) { private static void digestKey(MessageDigest md, SecretKey key) {
try { try {
......
...@@ -569,7 +569,7 @@ abstract class Handshaker { ...@@ -569,7 +569,7 @@ abstract class Handshaker {
activeProtocols = getActiveProtocols(); activeProtocols = getActiveProtocols();
} }
ArrayList<CipherSuite> suites = new ArrayList<CipherSuite>(); ArrayList<CipherSuite> suites = new ArrayList<>();
if (!(activeProtocols.collection().isEmpty()) && if (!(activeProtocols.collection().isEmpty()) &&
activeProtocols.min.v != ProtocolVersion.NONE.v) { activeProtocols.min.v != ProtocolVersion.NONE.v) {
for (CipherSuite suite : enabledCipherSuites.collection()) { for (CipherSuite suite : enabledCipherSuites.collection()) {
...@@ -614,8 +614,7 @@ abstract class Handshaker { ...@@ -614,8 +614,7 @@ abstract class Handshaker {
*/ */
ProtocolList getActiveProtocols() { ProtocolList getActiveProtocols() {
if (activeProtocols == null) { if (activeProtocols == null) {
ArrayList<ProtocolVersion> protocols = ArrayList<ProtocolVersion> protocols = new ArrayList<>(4);
new ArrayList<ProtocolVersion>(4);
for (ProtocolVersion protocol : enabledProtocols.collection()) { for (ProtocolVersion protocol : enabledProtocols.collection()) {
boolean found = false; boolean found = false;
for (CipherSuite suite : enabledCipherSuites.collection()) { for (CipherSuite suite : enabledCipherSuites.collection()) {
......
...@@ -169,8 +169,7 @@ final class ExtensionType { ...@@ -169,8 +169,7 @@ final class ExtensionType {
return name; return name;
} }
static List<ExtensionType> knownExtensions = static List<ExtensionType> knownExtensions = new ArrayList<>(9);
new ArrayList<ExtensionType>(9);
static ExtensionType get(int id) { static ExtensionType get(int id) {
for (ExtensionType ext : knownExtensions) { for (ExtensionType ext : knownExtensions) {
...@@ -674,7 +673,7 @@ final class SupportedEllipticPointFormatsExtension extends HelloExtension { ...@@ -674,7 +673,7 @@ final class SupportedEllipticPointFormatsExtension extends HelloExtension {
} }
public String toString() { public String toString() {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<>();
for (byte format : formats) { for (byte format : formats) {
list.add(toString(format)); list.add(toString(format));
} }
......
...@@ -83,7 +83,7 @@ final class ProtocolList { ...@@ -83,7 +83,7 @@ final class ProtocolList {
throw new IllegalArgumentException("Protocols may not be null"); throw new IllegalArgumentException("Protocols may not be null");
} }
ArrayList<ProtocolVersion> versions = new ArrayList<ProtocolVersion>(3); ArrayList<ProtocolVersion> versions = new ArrayList<>(3);
for (int i = 0; i < names.length; i++ ) { for (int i = 0; i < names.length; i++ ) {
ProtocolVersion version = ProtocolVersion.valueOf(names[i]); ProtocolVersion version = ProtocolVersion.valueOf(names[i]);
if (versions.contains(version) == false) { if (versions.contains(version) == false) {
......
...@@ -261,7 +261,7 @@ final class SSLAlgorithmConstraints implements AlgorithmConstraints { ...@@ -261,7 +261,7 @@ final class SSLAlgorithmConstraints implements AlgorithmConstraints {
protected Set<String> decomposes(KeyExchange keyExchange, protected Set<String> decomposes(KeyExchange keyExchange,
boolean forCertPathOnly) { boolean forCertPathOnly) {
Set<String> components = new HashSet<String>(); Set<String> components = new HashSet<>();
switch (keyExchange) { switch (keyExchange) {
case K_NULL: case K_NULL:
if (!forCertPathOnly) { if (!forCertPathOnly) {
...@@ -356,7 +356,7 @@ final class SSLAlgorithmConstraints implements AlgorithmConstraints { ...@@ -356,7 +356,7 @@ final class SSLAlgorithmConstraints implements AlgorithmConstraints {
} }
protected Set<String> decomposes(BulkCipher bulkCipher) { protected Set<String> decomposes(BulkCipher bulkCipher) {
Set<String> components = new HashSet<String>(); Set<String> components = new HashSet<>();
if (bulkCipher.transformation != null) { if (bulkCipher.transformation != null) {
components.addAll(super.decomposes(bulkCipher.transformation)); components.addAll(super.decomposes(bulkCipher.transformation));
...@@ -366,7 +366,7 @@ final class SSLAlgorithmConstraints implements AlgorithmConstraints { ...@@ -366,7 +366,7 @@ final class SSLAlgorithmConstraints implements AlgorithmConstraints {
} }
protected Set<String> decomposes(MacAlg macAlg) { protected Set<String> decomposes(MacAlg macAlg) {
Set<String> components = new HashSet<String>(); Set<String> components = new HashSet<>();
if (macAlg == CipherSuite.M_MD5) { if (macAlg == CipherSuite.M_MD5) {
components.add("MD5"); components.add("MD5");
...@@ -407,7 +407,7 @@ final class SSLAlgorithmConstraints implements AlgorithmConstraints { ...@@ -407,7 +407,7 @@ final class SSLAlgorithmConstraints implements AlgorithmConstraints {
} }
if (cipherSuite != null) { if (cipherSuite != null) {
Set<String> components = new HashSet<String>(); Set<String> components = new HashSet<>();
if(cipherSuite.keyExchange != null) { if(cipherSuite.keyExchange != null) {
components.addAll( components.addAll(
...@@ -448,7 +448,7 @@ final class SSLAlgorithmConstraints implements AlgorithmConstraints { ...@@ -448,7 +448,7 @@ final class SSLAlgorithmConstraints implements AlgorithmConstraints {
} }
if (cipherSuite != null) { if (cipherSuite != null) {
Set<String> components = new HashSet<String>(); Set<String> components = new HashSet<>();
if(cipherSuite.keyExchange != null) { if(cipherSuite.keyExchange != null) {
components.addAll( components.addAll(
......
...@@ -618,8 +618,7 @@ final class SSLSessionImpl extends ExtendedSSLSession { ...@@ -618,8 +618,7 @@ final class SSLSessionImpl extends ExtendedSSLSession {
* key and the calling security context. This is important since * key and the calling security context. This is important since
* sessions can be shared across different protection domains. * sessions can be shared across different protection domains.
*/ */
private Hashtable<SecureKey, Object> table = private Hashtable<SecureKey, Object> table = new Hashtable<>();
new Hashtable<SecureKey, Object>();
/** /**
* Assigns a session value. Session change events are given if * Assigns a session value. Session change events are given if
...@@ -687,7 +686,7 @@ final class SSLSessionImpl extends ExtendedSSLSession { ...@@ -687,7 +686,7 @@ final class SSLSessionImpl extends ExtendedSSLSession {
*/ */
public String[] getValueNames() { public String[] getValueNames() {
Enumeration<SecureKey> e; Enumeration<SecureKey> e;
Vector<Object> v = new Vector<Object>(); Vector<Object> v = new Vector<>();
SecureKey key; SecureKey key;
Object securityCtx = SecureKey.getCurrentSecurityContext(); Object securityCtx = SecureKey.getCurrentSecurityContext();
......
...@@ -153,8 +153,7 @@ final class SignatureAndHashAlgorithm { ...@@ -153,8 +153,7 @@ final class SignatureAndHashAlgorithm {
static Collection<SignatureAndHashAlgorithm> static Collection<SignatureAndHashAlgorithm>
getSupportedAlgorithms(AlgorithmConstraints constraints) { getSupportedAlgorithms(AlgorithmConstraints constraints) {
Collection<SignatureAndHashAlgorithm> supported = Collection<SignatureAndHashAlgorithm> supported = new ArrayList<>();
new ArrayList<SignatureAndHashAlgorithm>();
synchronized (priorityMap) { synchronized (priorityMap) {
for (SignatureAndHashAlgorithm sigAlg : priorityMap.values()) { for (SignatureAndHashAlgorithm sigAlg : priorityMap.values()) {
if (sigAlg.priority <= SUPPORTED_ALG_PRIORITY_MAX_NUM && if (sigAlg.priority <= SUPPORTED_ALG_PRIORITY_MAX_NUM &&
...@@ -171,8 +170,7 @@ final class SignatureAndHashAlgorithm { ...@@ -171,8 +170,7 @@ final class SignatureAndHashAlgorithm {
// Get supported algorithm collection from an untrusted collection // Get supported algorithm collection from an untrusted collection
static Collection<SignatureAndHashAlgorithm> getSupportedAlgorithms( static Collection<SignatureAndHashAlgorithm> getSupportedAlgorithms(
Collection<SignatureAndHashAlgorithm> algorithms ) { Collection<SignatureAndHashAlgorithm> algorithms ) {
Collection<SignatureAndHashAlgorithm> supported = Collection<SignatureAndHashAlgorithm> supported = new ArrayList<>();
new ArrayList<SignatureAndHashAlgorithm>();
for (SignatureAndHashAlgorithm sigAlg : algorithms) { for (SignatureAndHashAlgorithm sigAlg : algorithms) {
if (sigAlg.priority <= SUPPORTED_ALG_PRIORITY_MAX_NUM) { if (sigAlg.priority <= SUPPORTED_ALG_PRIORITY_MAX_NUM) {
supported.add(sigAlg); supported.add(sigAlg);
...@@ -184,7 +182,7 @@ final class SignatureAndHashAlgorithm { ...@@ -184,7 +182,7 @@ final class SignatureAndHashAlgorithm {
static String[] getAlgorithmNames( static String[] getAlgorithmNames(
Collection<SignatureAndHashAlgorithm> algorithms) { Collection<SignatureAndHashAlgorithm> algorithms) {
ArrayList<String> algorithmNames = new ArrayList<String>(); ArrayList<String> algorithmNames = new ArrayList<>();
if (algorithms != null) { if (algorithms != null) {
for (SignatureAndHashAlgorithm sigAlg : algorithms) { for (SignatureAndHashAlgorithm sigAlg : algorithms) {
algorithmNames.add(sigAlg.algorithm); algorithmNames.add(sigAlg.algorithm);
...@@ -197,7 +195,7 @@ final class SignatureAndHashAlgorithm { ...@@ -197,7 +195,7 @@ final class SignatureAndHashAlgorithm {
static Set<String> getHashAlgorithmNames( static Set<String> getHashAlgorithmNames(
Collection<SignatureAndHashAlgorithm> algorithms) { Collection<SignatureAndHashAlgorithm> algorithms) {
Set<String> algorithmNames = new HashSet<String>(); Set<String> algorithmNames = new HashSet<>();
if (algorithms != null) { if (algorithms != null) {
for (SignatureAndHashAlgorithm sigAlg : algorithms) { for (SignatureAndHashAlgorithm sigAlg : algorithms) {
if (sigAlg.hash.value > 0) { if (sigAlg.hash.value > 0) {
......
...@@ -337,7 +337,7 @@ final class SunX509KeyManagerImpl extends X509ExtendedKeyManager { ...@@ -337,7 +337,7 @@ final class SunX509KeyManagerImpl extends X509ExtendedKeyManager {
X500Principal[] x500Issuers = (X500Principal[])issuers; X500Principal[] x500Issuers = (X500Principal[])issuers;
// the algorithm below does not produce duplicates, so avoid Set // the algorithm below does not produce duplicates, so avoid Set
List<String> aliases = new ArrayList<String>(); List<String> aliases = new ArrayList<>();
for (Map.Entry<String,X509Credentials> entry : for (Map.Entry<String,X509Credentials> entry :
credentialsMap.entrySet()) { credentialsMap.entrySet()) {
...@@ -397,7 +397,7 @@ final class SunX509KeyManagerImpl extends X509ExtendedKeyManager { ...@@ -397,7 +397,7 @@ final class SunX509KeyManagerImpl extends X509ExtendedKeyManager {
* possible. Principals that cannot be converted are ignored. * possible. Principals that cannot be converted are ignored.
*/ */
private static X500Principal[] convertPrincipals(Principal[] principals) { private static X500Principal[] convertPrincipals(Principal[] principals) {
List<X500Principal> list = new ArrayList<X500Principal>(principals.length); List<X500Principal> list = new ArrayList<>(principals.length);
for (int i = 0; i < principals.length; i++) { for (int i = 0; i < principals.length; i++) {
Principal p = principals[i]; Principal p = principals[i];
if (p instanceof X500Principal) { if (p instanceof X500Principal) {
......
...@@ -134,7 +134,7 @@ abstract class TrustManagerFactoryImpl extends TrustManagerFactorySpi { ...@@ -134,7 +134,7 @@ abstract class TrustManagerFactoryImpl extends TrustManagerFactorySpi {
FileInputStream fis = null; FileInputStream fis = null;
String defaultTrustStoreType; String defaultTrustStoreType;
String defaultTrustStoreProvider; String defaultTrustStoreProvider;
final HashMap<String,String> props = new HashMap<String,String>(); final HashMap<String,String> props = new HashMap<>();
final String sep = File.separator; final String sep = File.separator;
KeyStore ks = null; KeyStore ks = null;
......
...@@ -307,7 +307,7 @@ final class X509KeyManagerImpl extends X509ExtendedKeyManager ...@@ -307,7 +307,7 @@ final class X509KeyManagerImpl extends X509ExtendedKeyManager
(keyTypes.length == 0) || (keyTypes[0] == null)) { (keyTypes.length == 0) || (keyTypes[0] == null)) {
return null; return null;
} }
List<KeyType> list = new ArrayList<KeyType>(keyTypes.length); List<KeyType> list = new ArrayList<>(keyTypes.length);
for (String keyType : keyTypes) { for (String keyType : keyTypes) {
list.add(new KeyType(keyType)); list.add(new KeyType(keyType));
} }
...@@ -429,7 +429,7 @@ final class X509KeyManagerImpl extends X509ExtendedKeyManager ...@@ -429,7 +429,7 @@ final class X509KeyManagerImpl extends X509ExtendedKeyManager
// make a Set out of the array // make a Set out of the array
private Set<Principal> getIssuerSet(Principal[] issuers) { private Set<Principal> getIssuerSet(Principal[] issuers) {
if ((issuers != null) && (issuers.length != 0)) { if ((issuers != null) && (issuers.length != 0)) {
return new HashSet<Principal>(Arrays.asList(issuers)); return new HashSet<>(Arrays.asList(issuers));
} else { } else {
return null; return null;
} }
......
...@@ -300,8 +300,8 @@ public class CookieHandlerTest { ...@@ -300,8 +300,8 @@ public class CookieHandlerTest {
getCalled = true; getCalled = true;
// returns cookies[0] // returns cookies[0]
// they will be include in request // they will be include in request
Map<String,List<String>> map = new HashMap<String,List<String>>(); Map<String,List<String>> map = new HashMap<>();
List<String> l = new ArrayList<String>(); List<String> l = new ArrayList<>();
l.add(cookies.get("Cookie")); l.add(cookies.get("Cookie"));
map.put("Cookie",l); map.put("Cookie",l);
return Collections.unmodifiableMap(map); return Collections.unmodifiableMap(map);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册