use of javax.crypto.ShortBufferException in project robovm by robovm.
the class myMac method testMac10.
/**
* Test for <code>doFinal(byte[] output, int outOffset)</code> method
* Assertion:
* throws ShotBufferException when outOffset is negative or
* outOffset >= output.length or when given buffer is small
*/
public void testMac10() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException, IllegalStateException, InvalidKeyException {
if (!DEFSupported) {
fail(NotSupportedMsg);
return;
}
Mac[] macs = createMacs();
assertNotNull("Mac objects were not created", macs);
byte[] b = { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 };
byte[] byteA = new byte[b.length];
SecretKeySpec sks = new SecretKeySpec(b, "SHA1");
for (int i = 0; i < macs.length; i++) {
macs[i].init(sks);
try {
macs[i].doFinal(null, 10);
fail("ShortBufferException must be thrown");
} catch (ShortBufferException e) {
}
try {
macs[i].doFinal(byteA, -4);
fail("ShortBufferException must be thrown");
} catch (ShortBufferException e) {
}
try {
macs[i].doFinal(byteA, 10);
fail("ShortBufferException must be thrown");
} catch (ShortBufferException e) {
}
try {
macs[i].doFinal(new byte[1], 0);
fail("ShortBufferException must be thrown");
} catch (ShortBufferException e) {
}
byte[] res = macs[i].doFinal();
try {
macs[i].doFinal(new byte[res.length - 1], 0);
fail("ShortBufferException must be thrown");
} catch (ShortBufferException e) {
}
}
}
use of javax.crypto.ShortBufferException in project robovm by robovm.
the class CipherTest method test_doFinal$BI.
public void test_doFinal$BI() throws Exception {
byte[] b = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
byte[] b1 = new byte[30];
AlgorithmParameterSpec ap = new IvParameterSpec(IV);
Cipher c = Cipher.getInstance("DES/CBC/NoPadding");
c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_DES, ap);
c.update(b, 0, 10);
try {
c.doFinal(b1, 5);
fail();
} catch (IllegalBlockSizeException expected) {
}
c = Cipher.getInstance("DES/CBC/NoPadding");
try {
c.doFinal(b1, 5);
fail();
} catch (IllegalStateException expected) {
}
c = Cipher.getInstance("DES/CBC/NoPadding");
c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_DES, ap);
c.update(b, 3, 8);
int len = c.doFinal(b1, 0);
assertEquals(0, len);
c = Cipher.getInstance("DES/CBC/PKCS5Padding");
c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_DES, ap);
c.update(b1, 0, 24);
try {
c.doFinal(b, 0);
fail();
} catch (BadPaddingException expected) {
}
b1 = new byte[6];
c = Cipher.getInstance("DESede");
c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_3DES);
c.update(b, 3, 6);
try {
c.doFinal(b1, 5);
fail();
} catch (ShortBufferException expected) {
}
}
use of javax.crypto.ShortBufferException in project robovm by robovm.
the class CipherTest method test_doFinal$BII$B.
public void test_doFinal$BII$B() throws Exception {
byte[] b = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
byte[] b1 = new byte[30];
AlgorithmParameterSpec ap = new IvParameterSpec(IV);
Cipher c = Cipher.getInstance("DES/CBC/NoPadding");
c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_DES, ap);
try {
c.doFinal(b, 0, 10, b1);
fail();
} catch (IllegalBlockSizeException expected) {
}
c = Cipher.getInstance("DES/CBC/NoPadding");
try {
c.doFinal(b, 0, 10, b1);
fail();
} catch (IllegalStateException expected) {
}
c = Cipher.getInstance("DES/CBC/NoPadding");
c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_DES, ap);
int len = c.doFinal(b, 0, 16, b1);
assertEquals(16, len);
c = Cipher.getInstance("DES/CBC/PKCS5Padding");
c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_DES, ap);
try {
c.doFinal(b1, 0, 24, new byte[42]);
fail();
} catch (BadPaddingException expected) {
}
b1 = new byte[6];
c = Cipher.getInstance("DESede");
c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_3DES);
try {
c.doFinal(b, 3, 6, b1);
fail();
} catch (ShortBufferException expected) {
}
}
use of javax.crypto.ShortBufferException in project robovm by robovm.
the class ShortBufferExceptionTest method testShortBufferException02.
/**
* Test for <code>ShortBufferException(String)</code> constructor
* Assertion: constructs ShortBufferException with detail message msg.
* Parameter <code>msg</code> is not null.
*/
public void testShortBufferException02() {
ShortBufferException tE;
for (int i = 0; i < msgs.length; i++) {
tE = new ShortBufferException(msgs[i]);
assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
assertNull("getCause() must return null", tE.getCause());
}
}
use of javax.crypto.ShortBufferException in project robovm by robovm.
the class ShortBufferExceptionTest method testShortBufferException03.
/**
* Test for <code>ShortBufferException(String)</code> constructor
* Assertion: constructs ShortBufferException when <code>msg</code> is
* null
*/
public void testShortBufferException03() {
String msg = null;
ShortBufferException tE = new ShortBufferException(msg);
assertNull("getMessage() must return null.", tE.getMessage());
assertNull("getCause() must return null", tE.getCause());
}
Aggregations