process method

  1. @override
Uint8List process(
  1. Uint8List? data
)
override

Process a whole block of data at once, returning the result in a byte array.

This call does as many calls to processBlock as needed to process all the given data and a final one to doFinal so that the padding can do its job.

Implementation

@override
Uint8List process(Uint8List? data) {
  var inputBlocks = (data!.length + blockSize - 1) ~/ blockSize;

  int outputBlocks;
  if (_encrypting!) {
    outputBlocks = (data.length + blockSize) ~/ blockSize;
  } else {
    if ((data.length % blockSize) != 0) {
      throw ArgumentError(
          'Input data length must be a multiple of cipher\'s block size');
    }
    outputBlocks = inputBlocks;
  }

  var out = Uint8List(outputBlocks * blockSize);

  for (var i = 0; i < (inputBlocks - 1); i++) {
    var offset = i * blockSize;
    processBlock(data, offset, out, offset);
  }

  var lastBlockOffset = (inputBlocks - 1) * blockSize;
  var lastBlockSize = doFinal(data, lastBlockOffset, out, lastBlockOffset);

  return out.sublist(0, lastBlockOffset + lastBlockSize);
}