diff src/ch/ethz/ssh2/crypto/cipher/BlockCipherFactory.java @ 307:071eccdff8ea ganymed

fix java formatting
author Carl Byington <carl@five-ten-sg.com>
date Wed, 30 Jul 2014 14:16:58 -0700
parents 91a31873c42a
children 8c1451f51a5e
line wrap: on
line diff
--- a/src/ch/ethz/ssh2/crypto/cipher/BlockCipherFactory.java	Wed Jul 30 12:09:51 2014 -0700
+++ b/src/ch/ethz/ssh2/crypto/cipher/BlockCipherFactory.java	Wed Jul 30 14:16:58 2014 -0700
@@ -14,117 +14,99 @@
  * @author Christian Plattner
  * @version $Id: BlockCipherFactory.java 86 2014-04-07 14:15:18Z dkocher@sudo.ch $
  */
-public class BlockCipherFactory
-{
-	private static final class CipherEntry
-	{
-		String type;
-		int blocksize;
-		int keysize;
-		String cipherClass;
+public class BlockCipherFactory {
+    private static final class CipherEntry {
+        String type;
+        int blocksize;
+        int keysize;
+        String cipherClass;
 
-		public CipherEntry(String type, int blockSize, int keySize, String cipherClass)
-		{
-			this.type = type;
-			this.blocksize = blockSize;
-			this.keysize = keySize;
-			this.cipherClass = cipherClass;
-		}
-	}
+        public CipherEntry(String type, int blockSize, int keySize, String cipherClass) {
+            this.type = type;
+            this.blocksize = blockSize;
+            this.keysize = keySize;
+            this.cipherClass = cipherClass;
+        }
+    }
 
-	private static final List<CipherEntry> ciphers = new ArrayList<CipherEntry>();
+    private static final List<CipherEntry> ciphers = new ArrayList<CipherEntry>();
 
-	static
-	{
-		/* Higher Priority First */
-		ciphers.add(new CipherEntry("aes128-ctr", 16, 16, "ch.ethz.ssh2.crypto.cipher.AES"));
-		ciphers.add(new CipherEntry("aes192-ctr", 16, 24, "ch.ethz.ssh2.crypto.cipher.AES"));
-		ciphers.add(new CipherEntry("aes256-ctr", 16, 32, "ch.ethz.ssh2.crypto.cipher.AES"));
-		ciphers.add(new CipherEntry("blowfish-ctr", 8, 16, "ch.ethz.ssh2.crypto.cipher.BlowFish"));
-
-		ciphers.add(new CipherEntry("aes128-cbc", 16, 16, "ch.ethz.ssh2.crypto.cipher.AES"));
-		ciphers.add(new CipherEntry("aes192-cbc", 16, 24, "ch.ethz.ssh2.crypto.cipher.AES"));
-		ciphers.add(new CipherEntry("aes256-cbc", 16, 32, "ch.ethz.ssh2.crypto.cipher.AES"));
-		ciphers.add(new CipherEntry("blowfish-cbc", 8, 16, "ch.ethz.ssh2.crypto.cipher.BlowFish"));
-
-		ciphers.add(new CipherEntry("3des-ctr", 8, 24, "ch.ethz.ssh2.crypto.cipher.DESede"));
-		ciphers.add(new CipherEntry("3des-cbc", 8, 24, "ch.ethz.ssh2.crypto.cipher.DESede"));
-	}
+    static {
+        /* Higher Priority First */
+        ciphers.add(new CipherEntry("aes128-ctr", 16, 16, "ch.ethz.ssh2.crypto.cipher.AES"));
+        ciphers.add(new CipherEntry("aes192-ctr", 16, 24, "ch.ethz.ssh2.crypto.cipher.AES"));
+        ciphers.add(new CipherEntry("aes256-ctr", 16, 32, "ch.ethz.ssh2.crypto.cipher.AES"));
+        ciphers.add(new CipherEntry("blowfish-ctr", 8, 16, "ch.ethz.ssh2.crypto.cipher.BlowFish"));
+        ciphers.add(new CipherEntry("aes128-cbc", 16, 16, "ch.ethz.ssh2.crypto.cipher.AES"));
+        ciphers.add(new CipherEntry("aes192-cbc", 16, 24, "ch.ethz.ssh2.crypto.cipher.AES"));
+        ciphers.add(new CipherEntry("aes256-cbc", 16, 32, "ch.ethz.ssh2.crypto.cipher.AES"));
+        ciphers.add(new CipherEntry("blowfish-cbc", 8, 16, "ch.ethz.ssh2.crypto.cipher.BlowFish"));
+        ciphers.add(new CipherEntry("3des-ctr", 8, 24, "ch.ethz.ssh2.crypto.cipher.DESede"));
+        ciphers.add(new CipherEntry("3des-cbc", 8, 24, "ch.ethz.ssh2.crypto.cipher.DESede"));
+    }
 
-	public static String[] getDefaultCipherList()
-	{
-		List<String> list = new ArrayList<String>(ciphers.size());
-		for (CipherEntry ce : ciphers)
-		{
-			list.add(ce.type);
-		}
-		return list.toArray(new String[ciphers.size()]);
-	}
+    public static String[] getDefaultCipherList() {
+        List<String> list = new ArrayList<String>(ciphers.size());
+
+        for (CipherEntry ce : ciphers) {
+            list.add(ce.type);
+        }
 
-	public static void checkCipherList(String[] cipherCandidates)
-	{
-		for (String cipherCandidate : cipherCandidates)
-		{
-			getEntry(cipherCandidate);
-		}
-	}
+        return list.toArray(new String[ciphers.size()]);
+    }
+
+    public static void checkCipherList(String[] cipherCandidates) {
+        for (String cipherCandidate : cipherCandidates) {
+            getEntry(cipherCandidate);
+        }
+    }
 
-	//	@SuppressWarnings("rawtypes")
-	public static BlockCipher createCipher(String type, boolean encrypt, byte[] key, byte[] iv)
-	{
-		try
-		{
-			CipherEntry ce = getEntry(type);
-			Class<?> cc = Class.forName(ce.cipherClass);
-			BlockCipher bc = (BlockCipher) cc.newInstance();
+    //  @SuppressWarnings("rawtypes")
+    public static BlockCipher createCipher(String type, boolean encrypt, byte[] key, byte[] iv) {
+        try {
+            CipherEntry ce = getEntry(type);
+            Class<?> cc = Class.forName(ce.cipherClass);
+            BlockCipher bc = (BlockCipher) cc.newInstance();
+
+            if (type.endsWith("-cbc")) {
+                bc.init(encrypt, key);
+                return new CBCMode(bc, iv, encrypt);
+            }
+            else if (type.endsWith("-ctr")) {
+                bc.init(true, key);
+                return new CTRMode(bc, iv, encrypt);
+            }
 
-			if (type.endsWith("-cbc"))
-			{
-				bc.init(encrypt, key);
-				return new CBCMode(bc, iv, encrypt);
-			}
-			else if (type.endsWith("-ctr"))
-			{
-				bc.init(true, key);
-				return new CTRMode(bc, iv, encrypt);
-			}
-			throw new IllegalArgumentException("Cannot instantiate " + type);
-		}
-		catch (ClassNotFoundException e)
-		{
-			throw new IllegalArgumentException("Cannot instantiate " + type, e);
-		}
-		catch (InstantiationException e)
-		{
-			throw new IllegalArgumentException("Cannot instantiate " + type, e);
-		}
-		catch (IllegalAccessException e)
-		{
-			throw new IllegalArgumentException("Cannot instantiate " + type, e);
-		}
-	}
+            throw new IllegalArgumentException("Cannot instantiate " + type);
+        }
+        catch (ClassNotFoundException e) {
+            throw new IllegalArgumentException("Cannot instantiate " + type, e);
+        }
+        catch (InstantiationException e) {
+            throw new IllegalArgumentException("Cannot instantiate " + type, e);
+        }
+        catch (IllegalAccessException e) {
+            throw new IllegalArgumentException("Cannot instantiate " + type, e);
+        }
+    }
 
-	private static CipherEntry getEntry(String type)
-	{
-		for (CipherEntry ce : ciphers)
-		{
-			if (ce.type.equals(type))
-			{
-				return ce;
-			}
-		}
-		throw new IllegalArgumentException("Unkown algorithm " + type);
-	}
+    private static CipherEntry getEntry(String type) {
+        for (CipherEntry ce : ciphers) {
+            if (ce.type.equals(type)) {
+                return ce;
+            }
+        }
+
+        throw new IllegalArgumentException("Unkown algorithm " + type);
+    }
 
-	public static int getBlockSize(String type)
-	{
-		CipherEntry ce = getEntry(type);
-		return ce.blocksize;
-	}
+    public static int getBlockSize(String type) {
+        CipherEntry ce = getEntry(type);
+        return ce.blocksize;
+    }
 
-	public static int getKeySize(String type)
-	{
-		CipherEntry ce = getEntry(type);
-		return ce.keysize;
-	}
+    public static int getKeySize(String type) {
+        CipherEntry ce = getEntry(type);
+        return ce.keysize;
+    }
 }