update method

  1. @override
SerializableHash<HashState> update(
  1. List<int> data, {
  2. int? length,
})
override

Updates the hash computation with the given data.

This method updates the hash computation with the provided data bytes. It appends the data to the internal buffer and processes it to update the hash state.

If the hash has already been finished using the finish method, calling this method will result in an error.

Parameters:

  • data: The List

Returns this Hash object for method chaining.

Implementation

@override
SerializableHash update(List<int> data, {int? length}) {
  if (_finished) {
    throw const MessageException(
        "SHA512: can't update because hash was finished.");
  }
  int dataPos = 0;
  int dataLength = length ?? data.length;
  _bytesHashed += dataLength;

  if (_bufferLength > 0) {
    while (_bufferLength < getBlockSize && dataLength > 0) {
      _buffer[_bufferLength++] = data[dataPos++] & mask8;
      dataLength--;
    }

    if (_bufferLength == getBlockSize) {
      _hashBlocks(
          _tempHi, _tempLo, _stateHi, _stateLo, _buffer, 0, getBlockSize);
      _bufferLength = 0;
    }
  }

  if (dataLength >= getBlockSize) {
    dataPos = _hashBlocks(
        _tempHi, _tempLo, _stateHi, _stateLo, data, dataPos, dataLength);
    dataLength %= getBlockSize;
  }

  while (dataLength > 0) {
    _buffer[_bufferLength++] = data[dataPos++] & mask8;
    dataLength--;
  }

  return this;
}