FileDocCategorySizeDatePackage
CipherThread.javaAPI DocAndroid 1.5 API4947Wed May 06 22:41:02 BST 2009org.apache.harmony.crypto.tests.javax.crypto.func

CipherThread

public abstract class CipherThread extends Object implements Runnable

Fields Summary
private int[]
keyLengthAr
private String[]
modeAr
private String[]
paddingModeAr
private int
kCounter
private int
mCounter
private int
pCounter
private StringBuffer
errorSB
private boolean
flagTestResult
private String
data
private String
algName
private int
keyLength
private String
mode
private String
paddingMode
private int
fails
Constructors Summary
CipherThread(String name, int[] keys, String[] modes, String[] paddings)


         

            
        algName     = name;
        keyLengthAr   = keys;
        modeAr        = modes;
        paddingModeAr = paddings;
        kCounter = 0;
        mCounter = 0;
        pCounter = 0;
    
Methods Summary
public voidcheckEncodedData(byte[] original, byte[] encoded)

        for(int i = 0; i < original.length; i++) {
            if (original[i] != encoded[i]) {
                throw new Exception("Source and encoded data not match " +
                        getCipherParameters());
            }
        }
    
public abstract voidcrypt()

public java.lang.StringgetAlgName()

        return algName;
    
public java.lang.StringgetAlgorithmName()

        return algName;
    
public java.lang.StringgetCipherParameters()

        return "Alg name:" + algName + " Key:" + keyLength + " Mode:" + mode +
        " Padding:" + paddingMode;
    
public java.lang.StringgetData()

        return data;
    
public java.lang.StringgetFailureMessages()

        return (errorSB == null) ? "" : new String(errorSB);
    
public intgetKeyLength()

        return keyLength;
    
public java.lang.StringgetMode()

        return mode;
    
public intgetNextKey()

        kCounter = (hasNextKey()) ? kCounter : 0;
        return keyLengthAr[kCounter++];
    
public java.lang.StringgetNextMode()

        mCounter = (hasNextMode()) ? mCounter : 0;
        return modeAr[mCounter++];
    
public java.lang.StringgetNextPadding()

        pCounter = (hasNextPadding()) ? pCounter : 0;
        return paddingModeAr[pCounter++];
    
public java.lang.StringgetPadding()

        return paddingMode;
    
public booleangetTestStatus()

        return flagTestResult;
    
public longgetTotalCasesNumber()

        return keyLengthAr.length * modeAr.length * paddingModeAr.length;
    
public longgetTotalFailuresNumber()

        return fails;
    
public booleanhasNextKey()

        return (kCounter < keyLengthAr.length);
    
public booleanhasNextMode()

        return (mCounter < modeAr.length);
    
public booleanhasNextPadding()

        return (pCounter < paddingModeAr.length);
    
public voidlauncher()

        Thread thread = null;

        do {
            keyLength = getNextKey();
            do {
                mode = getNextMode();
                do {
                    paddingMode = getNextPadding();
                    thread = new Thread(this);
                    thread.start();
                    try {
                        thread.join();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } while (hasNextPadding());
            } while (hasNextMode());
        } while (hasNextKey());
    
public voidrun()

        try {
            crypt();
        } catch (Exception e) {
            if(errorSB == null) {
                errorSB = new StringBuffer();
            }
            errorSB.append(e.getMessage());
            errorSB.append("\n");
            errorSB.append(getCipherParameters());
            errorSB.append("\n");
            StackTraceElement[] st = e.getStackTrace();
            for (int i = 0; i < st.length; i++) {
                errorSB.append(st[i].toString());
                errorSB.append("\n");
            }
            fails++;
            return;
        }
        flagTestResult = true;