Search in sources :

Example 11 with NullCipher

use of javax.crypto.NullCipher in project robovm by robovm.

the class CipherInputStream1Test method testAvailable.

/**
     * available() method testing. Tests that the method always return 0.
     */
public void testAvailable() throws Exception {
    byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 };
    TestInputStream tis = new TestInputStream(data);
    CipherInputStream cis = new CipherInputStream(tis, new NullCipher());
    assertEquals("The returned by available() method value " + "should be 0.", cis.available(), 0);
}
Also used : CipherInputStream(javax.crypto.CipherInputStream) NullCipher(javax.crypto.NullCipher)

Example 12 with NullCipher

use of javax.crypto.NullCipher in project robovm by robovm.

the class CipherInputStream1Test method testRead1.

/**
     * read() method testing. Tests that method returns the correct value
     * (related to the InputStream) and that it returns -1 at the end of stream.
     */
public void testRead1() throws Exception {
    byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 };
    TestInputStream tis = new TestInputStream(data);
    CipherInputStream cis = new CipherInputStream(tis, new NullCipher());
    byte res;
    for (int i = 0; i < data.length; i++) {
        if ((res = (byte) cis.read()) != data[i]) {
            fail("read() returned the incorrect value. " + "Expected: " + data[i] + ", Got: " + res + ".");
        }
    }
    if (cis.read() != -1) {
        fail("read() should return -1 at the end of the stream.");
    }
}
Also used : CipherInputStream(javax.crypto.CipherInputStream) NullCipher(javax.crypto.NullCipher)

Example 13 with NullCipher

use of javax.crypto.NullCipher in project robovm by robovm.

the class CipherInputStream1Test method testRead2.

/**
     * read(byte[] b) method testing. Tests that method returns the correct
     * value (related to the InputStream) and that it returns -1 at the end of
     * stream.
     */
public void testRead2() throws Exception {
    byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 };
    TestInputStream tis = new TestInputStream(data);
    CipherInputStream cis = new CipherInputStream(tis, new NullCipher());
    int expected = data.length;
    byte[] result = new byte[expected];
    // index into the data array (to check the got data)
    int ind = 0;
    // the number of got bytes
    int got = cis.read(result);
    while (true) {
        for (int j = 0; j < got - ind; j++) {
            if (result[j] != data[ind + j]) {
                fail("read(byte[] b) returned incorrect data.");
            }
        }
        if (got == expected) {
            break;
        } else if (got > expected) {
            fail("The data returned by read(byte[] b) " + "is larger than expected.");
        } else {
            ind = got;
            got += cis.read(result);
        }
    }
    if (cis.read(result) != -1) {
        fail("read(byte[] b) should return -1 " + "at the end of the stream.");
    }
}
Also used : CipherInputStream(javax.crypto.CipherInputStream) NullCipher(javax.crypto.NullCipher)

Example 14 with NullCipher

use of javax.crypto.NullCipher in project robovm by robovm.

the class CipherInputStream1Test method testClose.

/**
     * close() method testing. Tests that the method calls the close()
     * method of the underlying input stream.
     */
public void testClose() throws Exception {
    byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 };
    TestInputStream tis = new TestInputStream(data);
    CipherInputStream cis = new CipherInputStream(tis, new NullCipher());
    cis.close();
    assertTrue("The close() method should call the close() method " + "of its underlying input stream.", tis.wasClosed());
}
Also used : CipherInputStream(javax.crypto.CipherInputStream) NullCipher(javax.crypto.NullCipher)

Example 15 with NullCipher

use of javax.crypto.NullCipher in project robovm by robovm.

the class CipherInputStream1Test method testMarkSupported.

/**
     * markSupported() method testing. Tests that mark is not supported.
     */
public void testMarkSupported() {
    byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 };
    TestInputStream tis = new TestInputStream(data);
    CipherInputStream cis = new CipherInputStream(tis, new NullCipher());
    assertFalse("The returned by markSupported() method value " + "should be false.", cis.markSupported());
}
Also used : CipherInputStream(javax.crypto.CipherInputStream) NullCipher(javax.crypto.NullCipher)

Aggregations

NullCipher (javax.crypto.NullCipher)25 CipherInputStream (javax.crypto.CipherInputStream)9 Cipher (javax.crypto.Cipher)6 SealedObject (javax.crypto.SealedObject)5 CipherOutputStream (javax.crypto.CipherOutputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Key (java.security.Key)2 KeyGenerator (javax.crypto.KeyGenerator)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 FilterInputStream (java.io.FilterInputStream)1 InputStream (java.io.InputStream)1 LineNumberInputStream (java.io.LineNumberInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1 PushbackInputStream (java.io.PushbackInputStream)1 DigestInputStream (java.security.DigestInputStream)1