use of javax.crypto.NullCipher in project robovm by robovm.
the class CipherInputStreamTest method testReadBII.
/**
* javax.crypto.CipherInputStream#read(byte[] b, int off, int len)
*/
public void testReadBII() throws Exception {
// Regression for HARMONY-1080
CipherInputStream stream = new CipherInputStream(null, new NullCipher());
try {
stream.read(new byte[1], 1, 0);
fail("NullPointerException expected");
} catch (NullPointerException e) {
// expected
}
}
use of javax.crypto.NullCipher in project robovm by robovm.
the class CipherOutputStream1Test method testWrite3.
/**
* write(byte[] b, int off, int len) method testing.
*/
public void testWrite3() throws Exception {
byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 };
TestOutputStream tos = new TestOutputStream();
CipherOutputStream cos = new CipherOutputStream(tos, new NullCipher());
for (int i = 0; i < data.length; i++) {
cos.write(data, i, 1);
}
cos.flush();
byte[] result = tos.toByteArray();
if (!Arrays.equals(result, data)) {
fail("CipherOutputStream wrote incorrect data.");
}
}
use of javax.crypto.NullCipher in project robovm by robovm.
the class CipherInputStream1Test method testSkip.
/**
* skip(long n) method testing. Tests that the method correctly skips the
* bytes.
*/
public void testSkip() 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];
int skipped = (int) cis.skip(2);
int ind = skipped;
// the number of got bytes
int got = skipped + cis.read(result, 0, 1);
while (true) {
for (int j = 0; j < got - ind; j++) {
if (result[j] != data[ind + j]) {
fail("read(byte[] b, int off, int len) " + "returned incorrect data: Expected " + data[ind + j] + ", got: " + result[j]);
}
}
if (got == expected) {
break;
} else if (got > expected) {
fail("The data returned by " + "read(byte[] b, int off, int len) " + "is larger than expected.");
} else {
ind = got;
got += cis.read(result, 0, 1);
}
}
if ((got = cis.read(result, 0, 1)) != -1) {
fail("read() should return -1 at the end of the stream. " + "Output is: " + got + ".");
}
}
use of javax.crypto.NullCipher in project robovm by robovm.
the class CipherInputStream1Test method testRead3.
/**
* read(byte[] b, int off, int len) method testing. Tests that method
* returns the correct value (related to the InputStream), that it discards
* bytes in the case of null buffer, and that it returns -1 at the end of
* stream.
*/
public void testRead3() 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];
int skip = 2;
// index into the data array (to check the got data)
int ind = skip;
// should read and discard bytes;
cis.read(null, 0, skip);
// the number of got bytes
int got = skip + cis.read(result, 0, 1);
while (true) {
for (int j = 0; j < got - ind; j++) {
assertEquals("read(byte[] b, int off, int len) " + "returned incorrect data.", result[j], data[ind + j]);
}
if (got == expected) {
break;
} else if (got > expected) {
fail("The data returned by " + "read(byte[] b, int off, int len) " + "is larger than expected.");
} else {
ind = got;
got += cis.read(result, 0, 3);
}
}
if (cis.read(result, 0, 1) != -1) {
fail("read() should return -1 at the end of the stream.");
}
}
use of javax.crypto.NullCipher in project robovm by robovm.
the class SealedObjectTest method testSealedObject2.
/**
* SealedObject(SealedObject so) method testing. Tests if the
* NullPointerException is thrown in the case of null SealedObject.
*/
public void testSealedObject2() throws Exception {
try {
new SealedObject(null) {
};
fail("NullPointerException should be thrown in the case " + "of null SealedObject.");
} catch (NullPointerException e) {
}
String secret = "secret string";
Cipher cipher = new NullCipher();
SealedObject so1 = new SealedObject(secret, cipher);
SealedObject so2 = new SealedObject(so1) {
};
assertEquals("The secret content of the object should equals " + "to the secret content of initial object.", secret, so2.getObject(cipher));
assertEquals("The algorithm which was used to seal the object " + "should be the same as the algorithm used to seal the " + "initial object", so1.getAlgorithm(), so2.getAlgorithm());
}
Aggregations