processBytes method
Process len
bytes from inp
starting at offset inpOff
and output the
result to out
at offset outOff
.
Returns the number of bytes written to the output.
Implementation
@override
int processBytes(
Uint8List inp, int inpOff, int len, Uint8List out, int outOff) {
if (len == 0) return 0;
if (forEncryption) {
// all bytes are plain text bytes
return _processCipherBytes(inp, inpOff, len, out, outOff);
}
// last macSize bytes are possibly mac bytes and not cipher text bytes
// -> keep them in buffer
var cipherLen = _lastMacSizeBytesOff + len - macSize;
var resultLen = 0;
if (cipherLen > 0 && _lastMacSizeBytesOff > 0) {
// at least part of the buffer are actually cipher text bytes
// process them and update the buffer
var l = min(_lastMacSizeBytesOff, cipherLen);
resultLen += _processCipherBytes(_lastMacSizeBytes!, 0,
min(_lastMacSizeBytesOff, cipherLen), out, outOff);
outOff += resultLen;
cipherLen -= l;
_lastMacSizeBytes!.setRange(0, macSize - l, _lastMacSizeBytes!.skip(l));
_lastMacSizeBytesOff -= l;
}
if (cipherLen > 0) {
// part of the input are cipher text bytes
resultLen += _processCipherBytes(inp, inpOff, cipherLen, out, outOff);
}
_lastMacSizeBytes!.setRange(_lastMacSizeBytesOff,
_lastMacSizeBytesOff + len - cipherLen, inp.skip(inpOff + cipherLen));
_lastMacSizeBytesOff += len - cipherLen;
return resultLen;
}