pad method

Uint8List pad(
  1. int blockSize,
  2. Iterable<int> input, {
  3. dynamic label = const <int>[],
})
override

Implementation

Uint8List pad(int blockSize, Iterable<int> input,
    {/* String | List<int> */ label = const <int>[]}) {
  if (label is! List<int>) {
    label = utf8.encode(label);
  }
  final labelHash = hasher.convert(label).bytes;

  int messageBlockSize = blockSize - (2 * labelHash.length) - 2;
  final int numMessageBlocks = (input.length / messageBlockSize).ceil();
  final output = Uint8List(numMessageBlocks * blockSize);

  for (int i = 0; i < numMessageBlocks; i++) {
    Iterable<int> block;
    if (i == numMessageBlocks - 1) {
      block = input;
    } else {
      block = input.take(messageBlockSize);
      input = input.skip(messageBlockSize);
    }
    padBlock(
        blockSize, block, output.buffer.asByteData(i * blockSize, blockSize));
  }

  return output;
}