padBlock method

void padBlock(
  1. int blockSize,
  2. Iterable<int> block,
  3. ByteData output
)
override

Pads a single block

Implementation

void padBlock(int blockSize, Iterable<int> block, ByteData output) {
  if (output.lengthInBytes != blockSize) {
    throw Exception('Invalid buffer size');
  }

  if (block.length > blockSize - 11) {
    throw Exception('block too long');
  }

  output.setUint8(0, 0);
  output.setUint8(1, 2);

  int i = 2;
  final psLen = blockSize - block.length - 3;
  for (int j = 0; j < psLen; j++) {
    int r = rand.nextInt(256);
    while (r == 0) {
      r = rand.nextInt(256);
    }
    output.setUint8(i++, r);
  }

  output.setUint8(i++, 0);

  for (int byte in block) {
    output.setUint8(i++, byte);
  }
}