unpad method

Iterable<int> unpad(
  1. int blockSize,
  2. Iterable<int> input
)
override

Implementation

Iterable<int> unpad(int blockSize, Iterable<int> input) {
  if (input.length % blockSize != 0) {
    throw Exception(
        'Invalid message length. Must be multiple of blockSize $blockSize. Got ${input.length}');
  }

  final numBlocks = input.length ~/ blockSize;

  final out = Uint8List(numBlocks * (blockSize - 11));
  int outLen = 0;

  for (int i = 0; i < numBlocks; i++) {
    Iterable<int> block = input.take(blockSize);
    input = input.skip(blockSize);
    final unpaddedMsg = unpadBlock(blockSize, block);
    out.setAll(i * (blockSize - 11), unpaddedMsg);
    outLen += unpaddedMsg.length;
  }

  if (outLen == out.length) {
    return out;
  }

  return out.take(outLen);
}