Пример #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 MemoryCachedSafeByteFactory(IByteIdGenerator byteIdGenerator, IFactory <ISafeByte> safeByteFactory,
                                      ISafeObjectFactory safeObjectFactory, SafeObjectProtectionMode protectionMode)
 {
     _byteIdGenerator               = byteIdGenerator ?? throw new ArgumentNullException(nameof(byteIdGenerator));
     _safeByteFactory               = safeByteFactory ?? throw new ArgumentNullException(nameof(safeByteFactory));
     _safeObjectFactory             = safeObjectFactory;
     _innerDictionaryProtectionMode = protectionMode;
 }
Пример #3
0
 internal SafeByte(
     IFastEncryptor encryptor,
     IFastRandom fastRandom,
     IByteIdGenerator byteIdGenerator,
     IMemoryProtectedBytes encryptedByte,
     IMemoryProtectedBytes encryptionKey)
 {
     _encryptor       = encryptor ?? throw new ArgumentNullException(nameof(encryptor));
     _fastRandom      = fastRandom ?? throw new ArgumentNullException(nameof(fastRandom));
     _byteIdGenerator = byteIdGenerator ?? throw new ArgumentNullException(nameof(fastRandom));
     _encryptedByte   = encryptedByte ?? throw new ArgumentNullException(nameof(encryptedByte));
     _encryptionKey   = encryptionKey ?? throw new ArgumentNullException(nameof(encryptionKey));
 }
 private static ISafeByteFactory GetSut(
     SafeObjectProtectionMode innerDictionaryProtectionMode =
     MemoryCachedSafeByteFactory.DefaultInnerDictionaryProtection,
     ISafeObjectFactory factory       = null,
     IByteIdGenerator byteIdGenerator = null)
 {
     return(new MemoryCachedSafeByteFactory(
                byteIdGenerator ?? Stubs.Get <IByteIdGenerator>(),
                Stubs.GetFactory <ISafeByte>(),
                factory ?? Stubs.Get <ISafeObjectFactory>(),
                innerDictionaryProtectionMode
                ));
 }
Пример #5
0
 /// <summary>
 ///     Private constructor for creating identical instance of the <see cref="SafeByte" />.
 /// </summary>
 private SafeByte(
     int id, int realBytePosition,
     int encryptedByteLength,
     IFastEncryptor encryptor,
     IFastRandom fastRandom,
     IByteIdGenerator byteIdGenerator,
     IMemoryProtectedBytes encryptedByte,
     IMemoryProtectedBytes encryptionKey)
 {
     _encryptor       = encryptor;
     _fastRandom      = fastRandom;
     _byteIdGenerator = byteIdGenerator;
     //Deep copy
     _id = id;
     _realBytePosition    = realBytePosition;
     _encryptedByte       = encryptedByte.DeepClone();
     _encryptionKey       = encryptionKey.DeepClone();
     _encryptedByteLength = encryptedByteLength;
     IsByteSet            = true;
 }
Пример #6
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;
 }