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(
        "SHA256: can't update because hash was finished.");
  }
  int dataLength = length ?? data.length;
  int dataPos = 0;
  _bytesHashed += dataLength;

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

    if (_bufferLength == getBlockSize) {
      _hashBlocks(_temp, _state, _buffer, 0, getBlockSize);

      _bufferLength = 0;
    }
  }

  if (dataLength >= getBlockSize) {
    dataPos = _hashBlocks(_temp, _state, data, dataPos, dataLength);

    dataLength %= getBlockSize;
  }

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