예제 #1
0
        /// <inheritdoc />
        /// <inheritdoc cref="DisposableBase.ThrowIfDisposed" />
        /// <exception cref="ArgumentNullException"><paramref name="safeBytes" /> is <see langword="null" />.</exception>
        public async Task AppendManyAsync(IEnumerable <ISafeByte> safeBytes)
        {
            ThrowIfDisposed();
            if (safeBytes == null)
            {
                throw new ArgumentNullException(nameof(safeBytes));
            }
            var bytes = safeBytes as ISafeByte[] ?? safeBytes.ToArray();

            if (!bytes.Any())
            {
                return;
            }
            if (bytes.Any(b => b == null))
            {
                throw new ArgumentNullException(nameof(safeBytes), "List has null object");
            }

            using (var key = await _encryptionKey.RevealDecryptedBytesAsync().ConfigureAwait(false))
            {
                var list = await DecryptAndDeserializeAsync(_encryptedCollection, key.PlainBytes)
                           .ConfigureAwait(false);

                foreach (var @byte in bytes)
                {
                    list.Add(@byte.Id);
                    Length++;
                }
                _encryptedCollection = await SerializeAndEncryptAsync(list.ToArray(), key.PlainBytes)
                                       .ConfigureAwait(false);

                list.Clear();
            }
        }
예제 #2
0
 /// <inheritdoc />
 public async Task <int> GenerateAsync(byte @byte)
 {
     using (var salt = await _sessionSalt.RevealDecryptedBytesAsync().ConfigureAwait(false))
     {
         return(Generate(@byte, salt.PlainBytes));
     }
 }