unpad method

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

Implementation

Iterable<int> unpad(int blockSize, Iterable<int> data) {
  if (blockSize > 255) {
    throw Exception('PKCS #7 only supports block sizes less than 256');
  }

  if (data.length % blockSize != 0) {
    throw ArgumentError('Data size must be multiple of $blockSize!');
  }

  if (data.last > blockSize) {
    throw ArgumentError.value(data, 'data', 'Invalid PKCS7 padding!');
  }

  final int pads = data.last;

  if (pads == blockSize) {
    if (data.length <= blockSize) {
      throw ArgumentError('Invalid PKCS7 padding!');
    }
  }

  return data.take(data.length - pads);
}