/// <inheritdoc /> /// <inheritdoc cref="DisposableBase.ThrowIfDisposed"/> /// <exception cref="ArgumentException">Throws if the argument is empty</exception> public async Task AppendAsync(ISafeBytes safeBytes) { ThrowIfDisposed(); if (safeBytes.Length == 0) { throw new ArgumentException($"{nameof(safeBytes)} is empty."); } // If it's the known SafeBytes then it reveals nothing in the memory if (safeBytes is SafeBytes asSafeBytes) { var allBytes = await asSafeBytes._safeByteCollection.GetAllAsync() .ConfigureAwait(false); await _safeByteCollection.AppendManyAsync(allBytes) .ConfigureAwait(false); foreach (var safeByte in allBytes) { UpdateHashCode(safeByte); } } // If it's not, then reveals each byte in memory. else { var plainBytes = await safeBytes.RevealDecryptedBytesAsync() .ConfigureAwait(false); var stream = new SafeMemoryStream(plainBytes); await AppendManyAsync(stream).ConfigureAwait(false); } }
public async Task AppendAsync(ISafeBytes safeBytes) { _bytes.AddRange(await safeBytes.RevealDecryptedBytesAsync()); }