Merge "Custom engineUpdate/engineDoFinal(ByteBuffer, ByteBuffer)."
am: e766e399c5
* commit 'e766e399c59669156284c330ae3f38f79230d930':
Custom engineUpdate/engineDoFinal(ByteBuffer, ByteBuffer).
This commit is contained in:
@ -28,6 +28,7 @@ import android.security.keymaster.OperationResult;
|
|||||||
|
|
||||||
import libcore.util.EmptyArray;
|
import libcore.util.EmptyArray;
|
||||||
|
|
||||||
|
import java.nio.BufferOverflowException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.security.AlgorithmParameters;
|
import java.security.AlgorithmParameters;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
@ -385,7 +386,38 @@ abstract class AndroidKeyStoreCipherSpiBase extends CipherSpi implements KeyStor
|
|||||||
@Override
|
@Override
|
||||||
protected final int engineUpdate(ByteBuffer input, ByteBuffer output)
|
protected final int engineUpdate(ByteBuffer input, ByteBuffer output)
|
||||||
throws ShortBufferException {
|
throws ShortBufferException {
|
||||||
return super.engineUpdate(input, output);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -511,7 +543,38 @@ abstract class AndroidKeyStoreCipherSpiBase extends CipherSpi implements KeyStor
|
|||||||
@Override
|
@Override
|
||||||
protected final int engineDoFinal(ByteBuffer input, ByteBuffer output)
|
protected final int engineDoFinal(ByteBuffer input, ByteBuffer output)
|
||||||
throws ShortBufferException, IllegalBlockSizeException, BadPaddingException {
|
throws ShortBufferException, IllegalBlockSizeException, BadPaddingException {
|
||||||
return super.engineDoFinal(input, output);
|
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 =
|
||||||
|
engineDoFinal(
|
||||||
|
input.array(), input.arrayOffset() + input.position(), inputSize);
|
||||||
|
input.position(input.position() + inputSize);
|
||||||
|
} else {
|
||||||
|
byte[] inputArray = new byte[inputSize];
|
||||||
|
input.get(inputArray);
|
||||||
|
outputArray = engineDoFinal(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user