add method
Adds data
to the sink.
Must not be called after a call to close.
Implementation
@override
void add(List<int> data) {
final bs = _cipher.blockSize;
// Deal with any pending bytes
var fromPos = 0;
{
final total = _lastPlaintextPos + data.length;
if (total < bs) {
_lastPlaintext.setRange(_lastPlaintextPos, total, data);
_lastPlaintextPos = total;
return;
}
_lastPlaintext.setRange(_lastPlaintextPos, bs, data);
_emit(_lastPlaintext, 0, bs);
fromPos = bs - _lastPlaintextPos;
}
if (fromPos == data.length) {
_lastPlaintextPos = 0;
return; // No more to do
}
final toEmit = ((data.length - fromPos) ~/ bs) * bs;
_emit(data, fromPos, toEmit);
fromPos += toEmit;
_lastPlaintextPos = data.length - fromPos;
if (_lastPlaintextPos > 0) {
_lastPlaintext.setRange(0, _lastPlaintextPos,
data.getRange(fromPos, fromPos + _lastPlaintextPos));
} else {
// Keep the last block of plaintext around, in case we need it
// to generate the padding. See Padding.addPadding() in Pointycastle.
_lastPlaintext.setRange(
0, bs, data.getRange(data.length - bs, data.length));
}
}