예제 #1
0
 private static ISafeBytes GetSut(ISafeByteCollection collection = null,
                                  ISafeByteFactory factory       = null, IFactory <ISafeBytes> safeBytesFactory = null)
 {
     return(new SafeBytes(
                factory ?? Stubs.Get <ISafeByteFactory>(),
                safeBytesFactory ?? Stubs.GetFactory <ISafeBytes>(),
                Stubs.GetFactory(collection)));
 }
예제 #2
0
 internal SafeBytes(
     ISafeByteFactory safeByteFactory,
     IFactory <ISafeBytes> safeBytesFactory,
     IFactory <ISafeByteCollection> safeByteCollectionFactory)
 {
     _safeByteFactory    = safeByteFactory ?? throw new ArgumentNullException(nameof(safeByteFactory));
     _safeBytesFactory   = safeBytesFactory ?? throw new ArgumentNullException(nameof(safeBytesFactory));
     _safeByteCollection = safeByteCollectionFactory.Create();
 }
예제 #3
0
 internal EncryptedSafeByteCollection(IFastEncryptor encryptor, IByteArrayProtector memoryProtector,
                                      IFastRandom fastRandom, ISafeByteFactory safeByteFactory)
 {
     if (encryptor == null)
     {
         throw new ArgumentNullException(nameof(encryptor));
     }
     if (memoryProtector == null)
     {
         throw new ArgumentNullException(nameof(memoryProtector));
     }
     if (safeByteFactory == null)
     {
         throw new ArgumentNullException(nameof(safeByteFactory));
     }
     _encryptor       = encryptor;
     _memoryProtector = memoryProtector;
     _safeByteFactory = safeByteFactory;
     _encryptionKey   = fastRandom.GetBytes(_memoryProtector.BlockSizeInBytes);
     _memoryProtector.Protect(_encryptionKey);
 }
예제 #4
0
 internal EncryptedSafeByteCollection(
     IFastEncryptor encryptor,
     IMemoryProtectedBytes encryptionKey,
     ICryptoRandom fastRandom,
     ISafeByteFactory safeByteFactory,
     IByteIdListSerializer <int> serializer)
 {
     if (fastRandom == null)
     {
         throw new ArgumentNullException(nameof(fastRandom));
     }
     _encryptionKey = new AsyncLazy <IMemoryProtectedBytes>(async() =>
     {
         await encryptionKey.InitializeAsync(fastRandom.GetBytes(encryptionKey.BlockSizeInBytes))
         .ConfigureAwait(false);
         return(encryptionKey);
     });
     _encryptor       = encryptor ?? throw new ArgumentNullException(nameof(encryptor));
     _safeByteFactory = safeByteFactory ?? throw new ArgumentNullException(nameof(safeByteFactory));
     _serializer      = serializer;
     _salt            = fastRandom.GetBytes(encryptor.BlockSizeInBits / 8);
 }
예제 #5
0
 internal SafeBytes(
     IFastRandom fastRandom,
     ISafeByteFactory safeByteFactory,
     IFactory <ISafeBytes> safeBytesFactory,
     IFactory <ISafeByteCollection> safeByteCollectionFactory)
 {
     if (fastRandom == null)
     {
         throw new ArgumentNullException(nameof(fastRandom));
     }
     if (safeByteFactory == null)
     {
         throw new ArgumentNullException(nameof(safeByteFactory));
     }
     if (safeBytesFactory == null)
     {
         throw new ArgumentNullException(nameof(safeBytesFactory));
     }
     _fastRandom            = fastRandom;
     _safeByteFactory       = safeByteFactory;
     _safeBytesInstantiator = safeBytesFactory;
     _safeByteCollection    = safeByteCollectionFactory.Create();
 }
예제 #6
0
 public async Task Init()
 {
     _sut = new MemoryCachedSafeByteFactory();
     await _sut.InitializeAsync();
 }
 public void Init()
 {
     _sut = GetSut();
 }
예제 #8
0
 public void Init()
 {
     _sut = new MemoryCachedSafeByteFactory();
     _sut.Initialize();
 }