unpadBlock method

Iterable<int> unpadBlock(
  1. int blockSize,
  2. Iterable<int> block
)
override

Implementation

Iterable<int> unpadBlock(int blockSize, Iterable<int> block) {
  if (block.length != blockSize) {
    throw Exception('Invalid blocksize');
  }

  if (block.elementAt(0) != 0) {
    throw Exception('Invalid block. First byte not 0');
  }

  if (block.elementAt(1) != 2) {
    throw Exception('Invalid block. Second byte not 2');
  }

  block = block.skip(2);

  block = block.skipWhile((v) => v != 0);

  if (block.isEmpty) {
    throw Exception('Invalid block. No Message delimiter found');
  }

  block = block.skip(1);

  // TODO is this an error?
  if (block.isEmpty) {
    throw Exception('Invalid block. No Message');
  }

  return block;
}