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; }
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; }
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); }
/// <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>())); }
private MemoryProtectedBytes(IByteArrayProtector protector, byte[] encryptedBytes) : this(protector) { _encryptedBytes = encryptedBytes; }
internal MemoryProtectedBytes(IByteArrayProtector protector) { _protector = protector ?? throw new ArgumentNullException(nameof(protector)); }
private static IMemoryProtectedBytes GetSut(IByteArrayProtector protector) => new MemoryProtectedBytes(protector ?? Stubs.Get <IByteArrayProtector>());