예제 #1
0
 internal SafeByte(
     IFastEncryptor encryptor,
     IFastRandom fastRandom,
     IByteIdGenerator byteIdGenerator,
     IByteArrayProtector memoryProtector)
 {
     if (encryptor == null)
     {
         throw new ArgumentNullException(nameof(encryptor));
     }
     if (fastRandom == null)
     {
         throw new ArgumentNullException(nameof(fastRandom));
     }
     if (byteIdGenerator == null)
     {
         throw new ArgumentNullException(nameof(fastRandom));
     }
     if (memoryProtector == null)
     {
         throw new ArgumentNullException(nameof(memoryProtector));
     }
     _encryptor       = encryptor;
     _fastRandom      = fastRandom;
     _byteIdGenerator = byteIdGenerator;
     _memoryProtector = memoryProtector;
 }
예제 #2
0
 internal HashedByteIdGenerator(IFastHasher fastHasher, ISafeRandom safeRandom,
                                IByteArrayProtector memoryProtector)
 {
     if (fastHasher == null)
     {
         throw new ArgumentNullException(nameof(fastHasher));
     }
     if (safeRandom == null)
     {
         throw new ArgumentNullException(nameof(safeRandom));
     }
     if (memoryProtector == null)
     {
         throw new ArgumentNullException(nameof(memoryProtector));
     }
     _fastHasher      = fastHasher;
     _safeRandom      = safeRandom;
     _memoryProtector = memoryProtector;
 }
예제 #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
 /// <summary>
 ///     Private constructor for creating identical instance of the <see cref="SafeByte" />.
 /// </summary>
 private SafeByte(
     int id, int realBytePosition,
     int encryptedByteLength, byte[] encryptionKey, byte[] encryptedByte,
     IFastEncryptor encryptor,
     IFastRandom fastRandom,
     IByteIdGenerator byteIdGenerator,
     IByteArrayProtector memoryProtector)
 {
     _encryptor       = encryptor;
     _fastRandom      = fastRandom;
     _byteIdGenerator = byteIdGenerator;
     _memoryProtector = memoryProtector;
     //Deep copy
     _id = id;
     _realBytePosition = realBytePosition;
     _encryptedByte    = new byte[encryptedByte.Length];
     _encryptionKey    = new byte[encryptionKey.Length];
     Buffer.BlockCopy(encryptedByte, 0, _encryptedByte, 0, encryptedByte.Length);
     Buffer.BlockCopy(encryptionKey, 0, _encryptionKey, 0, encryptionKey.Length);
     _memoryProtector.Protect(_encryptionKey);
     _memoryProtector.Protect(_encryptedByte);
     _encryptedByteLength = encryptedByteLength;
     IsByteSet            = true;
 }
 private HashedByteIdGenerator GetSut(IFastHasher hasher = null, ISafeRandom random = null, IByteArrayProtector protector = null)
 {
     if (hasher == null)
     {
         var mockHasher = new Mock <IFastHasher>();
         mockHasher.Setup(m => m.ComputeFast(It.IsAny <byte[]>())).Returns((byte[] b) => b[b.Length - 1]);
         hasher = mockHasher.Object;
     }
     return(new HashedByteIdGenerator(hasher, random ?? Stubs.Get <ISafeRandom>(), protector ?? Mock.Of <IByteArrayProtector>()));
 }
예제 #6
0
 private MemoryProtectedBytes(IByteArrayProtector protector, byte[] encryptedBytes)
     : this(protector)
 {
     _encryptedBytes = encryptedBytes;
 }
예제 #7
0
 internal MemoryProtectedBytes(IByteArrayProtector protector)
 {
     _protector = protector ?? throw new ArgumentNullException(nameof(protector));
 }
예제 #8
0
 private static IMemoryProtectedBytes GetSut(IByteArrayProtector protector)
 => new MemoryProtectedBytes(protector ?? Stubs.Get <IByteArrayProtector>());