finish method

  1. @override
SerializableHash<HashState> finish(
  1. List<int> out
)
override

Finalizes the hash computation and stores the hash state in the provided List<int> out.

This function completes the hash computation, finalizes the state, and stores the resulting hash in the provided out List<int>. If the hash has already been finished, this method will return the existing state without re-computing.

Parameters:

  • out: The List<int> in which the hash digest is stored.

Returns the current instance of the hash algorithm.

Implementation

@override
SerializableHash finish(List<int> out) {
  if (!_finished) {
    final bytesHashed = _bytesHashed;
    final left = _bufferLength;
    final bitLenHi = (bytesHashed ~/ 0x20000000).toInt();
    final bitLenLo = bytesHashed << 3;
    final padLength = (bytesHashed % 128 < 112) ? 128 : 256;

    _buffer[left] = 0x80;
    for (var i = left + 1; i < padLength - 8; i++) {
      _buffer[i] = 0;
    }

    writeUint32BE(bitLenHi, _buffer, padLength - 8);
    writeUint32BE(bitLenLo, _buffer, padLength - 4);

    _hashBlocks(_tempHi, _tempLo, _stateHi, _stateLo, _buffer, 0, padLength);

    _finished = true;
  }

  for (var i = 0; i < getDigestLength ~/ 8; i++) {
    writeUint32BE(_stateHi[i], out, i * 8);
    writeUint32BE(_stateLo[i], out, i * 8 + 4);
  }

  return this;
}