pad function

Uint8List pad(
  1. Uint8List plaintext
)

Implementation

Uint8List pad(Uint8List plaintext) {
  int unpaddedLen = plaintext.length;
  if (unpaddedLen < 1 || unpaddedLen > 65535) {
    throw Exception('Invalid plaintext length');
  }

  int paddedLen = calcPaddedLen(unpaddedLen);
  Uint8List padded = Uint8List(paddedLen + 2);

  // First two bytes are the length in big-endian
  padded[0] = (unpaddedLen >> 8) & 0xFF;
  padded[1] = unpaddedLen & 0xFF;

  padded.setRange(2, 2 + unpaddedLen, plaintext);

  // The rest is zeros by default
  return padded;
}