doFinal method

  1. @override
int doFinal(
  1. Uint8List out,
  2. int outOff
)
override

Calculates, caches and if used as decrypter also verifies this mac, calls reset and returns the number of bytes written.

Implementation

@override
int doFinal(Uint8List out, int outOff) {
  _cMac.doFinal(_cipherMac, 0);
  _calculateMac();

  if (_forEncryption) {
    if (out.length < outOff + _macSize) {
      throw ArgumentError(
          'actual length: ${out.length}, '
              'min: ${outOff + _macSize}',
          'out');
    }
    out.setAll(outOff, mac);

    reset();
    return _macSize;
  } else {
    if (!_bufFull) {
      throw StateError('Did not process enough data '
          'for MAC to be collected from input.');
    }
    if (!_verifyMac(_inMac, 0)) {
      throw StateError('MAC does not match.');
    }

    reset();
    return 0;
  }
}