use of javax.crypto.ShortBufferException in project robovm by robovm.
the class ExemptionMechanismTest method test_genExemptionBlob$B.
public void test_genExemptionBlob$B() throws InvalidKeyException, ExemptionMechanismException, ShortBufferException {
Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
ExemptionMechanism em = new ExemptionMechanism(new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) {
};
Key key = new Mock_ExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
try {
em.genExemptionBlob(new byte[10]);
fail("IllegalStateException expected");
} catch (IllegalStateException e) {
//failed
}
em.init(key);
assertEquals(5, (em.genExemptionBlob(new byte[10])));
try {
em.genExemptionBlob(new byte[2]);
fail("ShortBufferException expected");
} catch (ShortBufferException e) {
//failed
}
byte[] b = new byte[] { 0, 0, 0, 33, 0 };
try {
em.genExemptionBlob(b);
fail("ExemptionMechanismException expected");
} catch (ExemptionMechanismException e) {
//failed
}
}
use of javax.crypto.ShortBufferException in project platform_frameworks_base by android.
the class AndroidKeyStoreCipherSpiBase method engineUpdate.
@Override
protected final int engineUpdate(ByteBuffer input, ByteBuffer output) throws ShortBufferException {
if (input == null) {
throw new NullPointerException("input == null");
}
if (output == null) {
throw new NullPointerException("output == null");
}
int inputSize = input.remaining();
byte[] outputArray;
if (input.hasArray()) {
outputArray = engineUpdate(input.array(), input.arrayOffset() + input.position(), inputSize);
input.position(input.position() + inputSize);
} else {
byte[] inputArray = new byte[inputSize];
input.get(inputArray);
outputArray = engineUpdate(inputArray, 0, inputSize);
}
int outputSize = (outputArray != null) ? outputArray.length : 0;
if (outputSize > 0) {
int outputBufferAvailable = output.remaining();
try {
output.put(outputArray);
} catch (BufferOverflowException e) {
throw new ShortBufferException("Output buffer too small. Produced: " + outputSize + ", available: " + outputBufferAvailable);
}
}
return outputSize;
}
use of javax.crypto.ShortBufferException in project android_frameworks_base by DirtyUnicorns.
the class AndroidKeyStoreCipherSpiBase method engineUpdate.
@Override
protected final int engineUpdate(ByteBuffer input, ByteBuffer output) throws ShortBufferException {
if (input == null) {
throw new NullPointerException("input == null");
}
if (output == null) {
throw new NullPointerException("output == null");
}
int inputSize = input.remaining();
byte[] outputArray;
if (input.hasArray()) {
outputArray = engineUpdate(input.array(), input.arrayOffset() + input.position(), inputSize);
input.position(input.position() + inputSize);
} else {
byte[] inputArray = new byte[inputSize];
input.get(inputArray);
outputArray = engineUpdate(inputArray, 0, inputSize);
}
int outputSize = (outputArray != null) ? outputArray.length : 0;
if (outputSize > 0) {
int outputBufferAvailable = output.remaining();
try {
output.put(outputArray);
} catch (BufferOverflowException e) {
throw new ShortBufferException("Output buffer too small. Produced: " + outputSize + ", available: " + outputBufferAvailable);
}
}
return outputSize;
}
use of javax.crypto.ShortBufferException in project android_frameworks_base by AOSPA.
the class AndroidKeyStoreCipherSpiBase method engineUpdate.
@Override
protected final int engineUpdate(ByteBuffer input, ByteBuffer output) throws ShortBufferException {
if (input == null) {
throw new NullPointerException("input == null");
}
if (output == null) {
throw new NullPointerException("output == null");
}
int inputSize = input.remaining();
byte[] outputArray;
if (input.hasArray()) {
outputArray = engineUpdate(input.array(), input.arrayOffset() + input.position(), inputSize);
input.position(input.position() + inputSize);
} else {
byte[] inputArray = new byte[inputSize];
input.get(inputArray);
outputArray = engineUpdate(inputArray, 0, inputSize);
}
int outputSize = (outputArray != null) ? outputArray.length : 0;
if (outputSize > 0) {
int outputBufferAvailable = output.remaining();
try {
output.put(outputArray);
} catch (BufferOverflowException e) {
throw new ShortBufferException("Output buffer too small. Produced: " + outputSize + ", available: " + outputBufferAvailable);
}
}
return outputSize;
}
use of javax.crypto.ShortBufferException in project robovm by robovm.
the class CipherTest method testUpdatebyteArrayintintbyteArrayint.
/*
* Class under test for int update(byte[], int, int, byte[], int)
*/
public void testUpdatebyteArrayintintbyteArrayint() throws Exception {
byte[] b = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
byte[] b1 = new byte[6];
Cipher c = Cipher.getInstance("DESede");
try {
c.update(b, 0, 10, b1, 5);
fail();
} catch (IllegalStateException expected) {
}
c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_3DES);
try {
c.update(b, 0, 10, b1, 5);
fail();
} catch (ShortBufferException expected) {
}
b1 = new byte[30];
c.update(b, 0, 10, b1, 5);
}
Aggregations