Exemple #1
0
        public void GetById_Takes_Less_Than_2ms()
        {
            const double expectedMax = 50;
            var          idGenerator = SafeOrbitCore.Current.Factory.Get <IByteIdGenerator>();
            var          id          = idGenerator.Generate(5);
            var          actual      = base.Measure(() => _sut.GetById(id));

            Assert.That(actual, Is.LessThan(expectedMax));
        }
Exemple #2
0
        /// <summary>
        ///     Gets the byte as <see cref="ISafeByte" /> for the specified index.
        /// </summary>
        /// <param name="index">The position of the byte.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     <paramref name="index" /> is lower than zero or higher/equals to the
        ///     <see cref="Length" />.
        /// </exception>
        /// <exception cref="InvalidOperationException"><see cref="EncryptedSafeByteCollection" /> instance is empty.</exception>
        /// <exception cref="ObjectDisposedException"><see cref="EncryptedSafeByteCollection" /> instance is disposed</exception>
        /// <seealso cref="ISafeByte" />
        public ISafeByte Get(int index)
        {
            if ((index < 0) && (index >= Length))
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }
            EnsureNotDisposed();
            EnsureNotEmpty();
            _memoryProtector.Unprotect(_encryptionKey);
            var list = DecryptAndDeserialize(_encryptedCollection, _encryptionKey);

            _memoryProtector.Protect(_encryptionKey);
            var id       = list.ElementAt(index);
            var safeByte = _safeByteFactory.GetById(id);

            list.Clear();
            return(safeByte);
        }