Пример #1
0
        /// <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);
            }
        }
Пример #2
0
 public async Task AppendAsync(ISafeBytes safeBytes)
 {
     _bytes.AddRange(await safeBytes.RevealDecryptedBytesAsync());
 }