Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.crypto.test;
  
  
  public abstract class CipherTest
      extends SimpleTest
 {
     private SimpleTest[]      _tests;
     private BlockCipher _engine;
     private KeyParameter _validKey;
 
 //    protected CipherTest(
 //        SimpleTest[]  tests)
 //    {
 //        _tests = tests;
 //    }
 
     protected CipherTest(
         SimpleTest[]   tests,
         BlockCipher  engine,
         KeyParameter validKey)
     {
          = tests;
          = engine;
          = validKey;
     }
     
     public abstract String getName();
 
     public void performTest()
         throws Exception
     {
         for (int i = 0; i != .i++)
         {
             [i].performTest();
         }
 
         if ( != null)
         {
             //
             // state tests
             //
             byte[]      buf = new byte[128];
             
             try
             {   
                 .processBlock(buf, 0, buf, 0);
                 
                 fail("failed initialisation check");
             }
             catch (IllegalStateException e)
             {
                 // expected 
             }
             
             bufferSizeCheck(());
         }
     }
     
     private void bufferSizeCheck(
         BlockCipher engine)
     {
         byte[] correctBuf = new byte[engine.getBlockSize()];
         byte[] shortBuf = new byte[correctBuf.length / 2];
         
         engine.init(true);
         
         try
         {   
             engine.processBlock(shortBuf, 0, correctBuf, 0);
             
             fail("failed short input check");
         }
         catch (DataLengthException e)
         {
             // expected 
         }
         
         try
         {   
             engine.processBlock(correctBuf, 0, shortBuf, 0);
             
             fail("failed short output check");
         }
         catch (DataLengthException e)
         {
             // expected 
         }
         
         engine.init(false);
         
         try
         {   
             engine.processBlock(shortBuf, 0, correctBuf, 0);
             
             fail("failed short input check");
        }
        catch (DataLengthException e)
        {
            // expected 
        }
        
        try
        {   
            engine.processBlock(correctBuf, 0, shortBuf, 0);
            
            fail("failed short output check");
        }
        catch (DataLengthException e)
        {
            // expected 
        }
    }
New to GrepCode? Check out our FAQ X