/// <summary> /// Append <paramref name="count"/> bytes of <paramref name="data"/>, starting at <paramref name="offset"/>, /// to the data already processed in the hash or HMAC. /// </summary> /// <param name="data">The data to process.</param> /// <param name="offset">The offset into the byte array from which to begin using data.</param> /// <param name="count">The number of bytes in the array to use as data.</param> /// <exception cref="ArgumentNullException"><paramref name="data"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="offset"/> is out of range. This parameter requires a non-negative number. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="count"/> is out of range. This parameter requires a non-negative number less than /// the <see cref="Array.Length"/> value of <paramref name="data"/>. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="count"/> is greater than /// <paramref name="data"/>.<see cref="Array.Length"/> - <paramref name="offset"/>. /// </exception> /// <exception cref="ObjectDisposedException">The object has already been disposed.</exception> public void AppendData(byte[] data, int offset, int count) { if (data == null) { throw new ArgumentNullException("data"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset", SR.ArgumentOutOfRange_NeedNonNegNum); } if (count < 0 || (count > data.Length)) { throw new ArgumentOutOfRangeException("count"); } if ((data.Length - count) < offset) { throw new ArgumentException(SR.Argument_InvalidOffLen); } if (_disposed) { throw new ObjectDisposedException(typeof(IncrementalHash).Name); } if (_hash != null) { _hash.AppendHashDataCore(data, offset, count); } else { Debug.Assert(_hmac != null, "Both _hash and _hmac were null"); _hmac.AppendHashData(data, offset, count); } }
public void AppendData(ReadOnlySpan <byte> data) { if (_disposed) { throw new ObjectDisposedException(typeof(IncrementalHash).Name); } Debug.Assert((_hash != null) ^ (_hmac != null)); if (_hash != null) { _hash.AppendHashData(data); } else { _hmac.AppendHashData(data); } }