Package org.apache.harmony.crypto.internal

Examples of org.apache.harmony.crypto.internal.NullCipherSpi


    /**
     * Creates a new {@code NullCipher} instance.
     */
    public NullCipher() {
        super(new NullCipherSpi(), null, null);
        try {
            this.init(Cipher.ENCRYPT_MODE, (Key)null, (SecureRandom)null);   
        } catch (InvalidKeyException e) {       
        }
    }
View Full Code Here


    /**
     * Creates a new {@code NullCipher} instance.
     */
    public NullCipher() {
        super(new NullCipherSpi(), null, null);
        try {
            this.init(Cipher.ENCRYPT_MODE, (Key)null, (SecureRandom)null);   
        } catch (InvalidKeyException e) {       
        }
    }
View Full Code Here

* Tests for NullCipher implementation
*/
public class NullCipherSpiTest extends TestCase {

  public void testEngineGetBlockSize() {
    NullCipherSpi spi = new NullCipherSpi();
        assertEquals("incorrect block size", 1, spi.engineGetBlockSize());
  }
View Full Code Here

    NullCipherSpi spi = new NullCipherSpi();
        assertEquals("incorrect block size", 1, spi.engineGetBlockSize());
  }

  public void testEngineGetOutputSize() {
    NullCipherSpi spi = new NullCipherSpi();
        assertEquals("incorrect output size", 100, spi.engineGetOutputSize(100));
  }
View Full Code Here

    NullCipherSpi spi = new NullCipherSpi();
        assertEquals("incorrect output size", 100, spi.engineGetOutputSize(100));
  }

  public void testEngineGetIV() {
    NullCipherSpi spi = new NullCipherSpi();
        assertTrue("Incorrect IV", Arrays.equals(spi.engineGetIV() , new byte[8]));
  }
View Full Code Here

  /*
   * Class under test for byte[] engineUpdate(byte[], int, int)
   */
  public void testEngineUpdatebyteArrayintint() {
    NullCipherSpi spi = new NullCipherSpi();
    byte[] b = {1,2,3,4,5,6,7,8,9};
    byte[] b1 =  spi.engineUpdate(b, 3, 4);
    for (int i = 0; i < 4; i++) {
            assertEquals("incorrect update result", b[3+i], b1[i]);
    }
  }
View Full Code Here

  /*
   * Class under test for int engineUpdate(byte[], int, int, byte[], int)
   */
  public void testEngineUpdatebyteArrayintintbyteArrayint() throws Exception {
    NullCipherSpi spi = new NullCipherSpi();
    byte[] b = {1,2,3,4,5,6,7,8,9};
    byte[] b1 =  new byte[10];
    assertEquals("incorrect update result", 4, spi.engineUpdate(b, 3, 4, b1, 5));
    for (int i = 0; i < 4; i++) {
            assertEquals("incorrect update result", b[3+i], b1[5+i]);
   
  }
View Full Code Here

  /*
   * Class under test for byte[] engineDoFinal(byte[], int, int)
   */
  public void testEngineDoFinalbyteArrayintint() throws Exception {
    NullCipherSpi spi = new NullCipherSpi();
    byte[] b = {1,2,3,4,5,6,7,8,9};
    byte[] b1 = null;
    b1 = spi.engineDoFinal(b, 3, 4);
    for (int i = 0; i < 4; i++) {
            assertEquals("incorrect doFinal result", b[3+i], b1[i]);
    }
  }
View Full Code Here

  /*
   * Class under test for int engineDoFinal(byte[], int, int, byte[], int)
   */
  public void testEngineDoFinalbyteArrayintintbyteArrayint() throws Exception {
    NullCipherSpi spi = new NullCipherSpi();
    byte[] b = {1,2,3,4,5,6,7,8,9};
    byte[] b1 =  new byte[10];
        assertEquals("incorrect doFinal result", 4, spi.engineDoFinal(b, 3, 4, b1, 5));
    for (int i = 0; i < 4; i++) {
            assertEquals("incorrect doFinal result", b[3+i], b1[5+i]);
    }
   
  }
View Full Code Here

  /*
   * Class under test for int engineUpdate(ByteBuffer, ByteBuffer)
   */
  public void testEngineUpdateByteBufferByteBuffer() throws Exception {
    NullCipherSpi spi = new NullCipherSpi();
    byte[] b = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

    ByteBuffer inbuf = ByteBuffer.wrap(b,0,b.length);
    ByteBuffer outbuf = ByteBuffer.allocate(6);
   
    try {
      spi.engineUpdate(null, outbuf);
      fail("No expected NullPointerException");
    } catch (NullPointerException e) { 
    }
   
    try {
      spi.engineUpdate(inbuf, null);
      fail("No expected NullPointerException");
    } catch (NullPointerException e) { 
    }
   
    inbuf.get();
    inbuf.get();
    inbuf.get();
    inbuf.get();
    int result = spi.engineUpdate(inbuf, outbuf);
        assertEquals("incorrect result", b.length - 4, result);
    for (int i = 0; i < result; i++) {
            assertEquals("incorrect outbuf", i + 4, outbuf.get(i));
    }
   
    inbuf = ByteBuffer.wrap(b,0,b.length);
    outbuf = ByteBuffer.allocate(5);
    inbuf.get();
    inbuf.get();
    inbuf.get();
    inbuf.get();
    try {
      spi.engineUpdate(inbuf, outbuf);
      fail("No expected ShortBufferException");
    } catch (ShortBufferException e) {
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.harmony.crypto.internal.NullCipherSpi

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.