示例#1
0
 /// <exception cref="ArgumentNullException"><paramref name="safeByte" /> is <see langword="null" />.</exception>
 private void Append(ISafeByte safeByte)
 {
     if (safeByte == null)
     {
         throw new ArgumentNullException(nameof(safeByte));
     }
     _safeByteCollection.Append(safeByte);
     AddArbitraryByte();
 }
示例#2
0
        public void Append_WhenArgumentIsNull_throwsArgumentNullException()
        {
            //Arrange
            var       sut          = GetSut();
            ISafeByte nullInstance = null;
            //Act
            TestDelegate appendingNull = () => sut.Append(nullInstance);

            //Act
            Assert.That(appendingNull, Throws.TypeOf <ArgumentNullException>());
        }
示例#3
0
        /// <inheritdoc cref="DisposableBase.ThrowIfDisposed"/>
        /// <exception cref="ArgumentNullException"><paramref name="safeByte" /> is <see langword="null" />.</exception>
        private async Task AppendAsync(ISafeByte safeByte)
        {
            ThrowIfDisposed();
            if (safeByte == null)
            {
                throw new ArgumentNullException(nameof(safeByte));
            }
            await _safeByteCollection.AppendAsync(safeByte)
            .ConfigureAwait(false);

            UpdateHashCode(safeByte);
        }
        public void AppendAsync_ArgumentIsNull_ThrowsArgumentNullException()
        {
            // Arrange
            var       sut          = GetSut();
            ISafeByte nullInstance = null;

            // Act
            Task AppendNull() => sut.AppendAsync(nullInstance);

            // Assert
            Assert.ThrowsAsync <ArgumentNullException>(AppendNull);
        }
示例#5
0
        private async Task <ISafeByte[]> GetAllSafeBytesAsync()
        {
            const int totalBytes = 256;
            var       safeBytes  = new ISafeByte[totalBytes];

            for (var i = 0; i < totalBytes; i++)
            {
                var @byte    = (byte)i;
                var safeByte = _safeByteFactory.Create();
                await safeByte.SetAsync(@byte).ConfigureAwait(false);

                safeBytes[i] = safeByte;
            }
            return(safeBytes);
        }
示例#6
0
 public bool Equals(ISafeByte other)
 {
     if (other == null)
     {
         return(false);
     }
     if (!IsByteSet && !other.IsByteSet)
     {
         return(true);
     }
     if (IsByteSet && other.IsByteSet)
     {
         return(_id == other.GetHashCode());
     }
     return(false);
 }
示例#7
0
        /// <summary>
        ///     Appends the specified <see cref="ISafeByte" /> instance to the inner encrypted collection.
        /// </summary>
        /// <param name="safeByte">The safe byte.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="safeByte" /> is <see langword="null" />.</exception>
        /// <exception cref="ObjectDisposedException">Throws if the <see cref="EncryptedSafeByteCollection" /> instance is disposed</exception>
        /// <seealso cref="ISafeByte" />
        public void Append(ISafeByte safeByte)
        {
            EnsureNotDisposed();
            if (safeByte == null)
            {
                throw new ArgumentNullException(nameof(safeByte));
            }
            _memoryProtector.Unprotect(_encryptionKey);
            var list = DecryptAndDeserialize(_encryptedCollection, _encryptionKey);

            list.Add(safeByte.Id);
            _encryptedCollection = SerializeAndEncrypt(list, _encryptionKey);
            list.Clear();
            _memoryProtector.Protect(_encryptionKey);
            Length++;
        }
        private IEnumerable <ISafeByte> GetAllSafeBytes()
        {
            var safeBytes = new ISafeByte[256];

            for (var i = 0; i < 256; i++)
            {
                var @byte = (byte)i;
                safeBytes[i] = _safeByteFactory.Create();
                safeBytes[i].Set(@byte);
            }
            //Fast.For(0, 256, i =>
            //{
            //    var @byte = (byte)i;
            //    safeBytes[i] = _safeByteFactory.Create();
            //    safeBytes[i].Set(@byte);
            //});
            return(safeBytes);
        }