Search in sources :

Example 36 with ShortBufferException

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;
}
Also used : ShortBufferException(javax.crypto.ShortBufferException) BufferOverflowException(java.nio.BufferOverflowException)

Example 37 with ShortBufferException

use of javax.crypto.ShortBufferException in project wildfly by wildfly.

the class CipherAdapter method engineDoFinal.

@Override
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException {
    int result = engineGetOutputSize(inputLen);
    if ((output.length - outputOffset) < result)
        throw new ShortBufferException();
    byte[] buf = engineDoFinal(input, inputOffset, inputLen);
    result = buf.length;
    if ((output.length - outputOffset) < result)
        throw new ShortBufferException();
    System.arraycopy(buf, 0, output, outputOffset, result);
    return result;
}
Also used : ShortBufferException(javax.crypto.ShortBufferException)

Example 38 with ShortBufferException

use of javax.crypto.ShortBufferException in project wildfly by wildfly.

the class CipherAdapter method engineUpdate.

@Override
protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException {
    int result = engineGetOutputSize(inputLen);
    if ((output.length - outputOffset) < result)
        throw new ShortBufferException();
    byte[] buf = engineUpdate(input, inputOffset, inputLen);
    result = buf.length;
    if ((output.length - outputOffset) < result)
        throw new ShortBufferException();
    System.arraycopy(buf, 0, output, outputOffset, result);
    return result;
}
Also used : ShortBufferException(javax.crypto.ShortBufferException)

Example 39 with ShortBufferException

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;
}
Also used : ShortBufferException(javax.crypto.ShortBufferException) BufferOverflowException(java.nio.BufferOverflowException)

Example 40 with ShortBufferException

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;
}
Also used : ShortBufferException(javax.crypto.ShortBufferException) BufferOverflowException(java.nio.BufferOverflowException)

Aggregations

ShortBufferException (javax.crypto.ShortBufferException)48 Cipher (javax.crypto.Cipher)15 BadPaddingException (javax.crypto.BadPaddingException)14 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)14 BufferOverflowException (java.nio.BufferOverflowException)10 ByteBuffer (java.nio.ByteBuffer)10 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)9 IvParameterSpec (javax.crypto.spec.IvParameterSpec)9 InvalidKeyException (java.security.InvalidKeyException)7 MyCipher (org.apache.harmony.crypto.tests.support.MyCipher)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)6 SecretKey (javax.crypto.SecretKey)6 NoSuchProviderException (java.security.NoSuchProviderException)5 Random (java.util.Random)5 KeyGenerator (javax.crypto.KeyGenerator)5 SecretKeySpec (javax.crypto.spec.SecretKeySpec)5 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)4 IOException (java.io.IOException)3 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)2