Permalink
Browse files

Fixing race condition in test

Minor refactoring for EncryptionSettings
  • Loading branch information...
1 parent 04e6efd commit 012e8585892cf4ab418a2a2e48b685f355d4d0d0 @ayende ayende committed Jul 28, 2012
View
2 Raven.Database/.gitignore
@@ -0,0 +1,2 @@
+
+*.DotSettings
View
29 Raven.Database/Bundles/Encryption/Settings/EncryptionSettings.cs
@@ -1,13 +1,14 @@
using System;
using System.Security.Cryptography;
+using Expression = System.Linq.Expressions.Expression;
namespace Raven.Bundles.Encryption.Settings
{
public class EncryptionSettings
{
private byte[] encryptionKey;
- private Type algorithmType;
- private Func<SymmetricAlgorithm> algorithmGenerator;
+ private readonly Type algorithmType;
+ private readonly Func<SymmetricAlgorithm> algorithmGenerator;
private readonly bool encryptIndexes;
public readonly Codec Codec;
@@ -29,15 +30,16 @@ public EncryptionSettings(byte[] encryptionKey, Type symmetricAlgorithmType)
public EncryptionSettings(byte[] encryptionKey, Type symmetricAlgorithmType, bool encryptIndexes)
{
- this.EncryptionKey = encryptionKey;
+ EncryptionKey = encryptionKey;
this.encryptIndexes = encryptIndexes;
- this.Codec = new Codec(this);
+ Codec = new Codec(this);
- typeof(EncryptionSettings)
- .GetMethod("SetSymmetricAlgorithmType", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
- .MakeGenericMethod(symmetricAlgorithmType)
- .Invoke(this, new object[0]);
+ algorithmType = symmetricAlgorithmType;
+
+ algorithmGenerator = Expression.Lambda<Func<SymmetricAlgorithm>>(
+ Expression.New(symmetricAlgorithmType)
+ ).Compile();
}
public static bool DontEncrypt(string key)
@@ -52,19 +54,14 @@ public byte[] EncryptionKey
private set
{
if (value == null)
- throw new ArgumentNullException("EncryptionKey");
+ throw new ArgumentNullException("value");
if (value.Length < Constants.MinimumAcceptableEncryptionKeyLength)
throw new ArgumentException("The EncryptionKey provided is too short. The minimum length is " + Constants.MinimumAcceptableEncryptionKeyLength + ".");
encryptionKey = value;
}
}
- private void SetSymmetricAlgorithmType<T>() where T : SymmetricAlgorithm, new()
- {
- algorithmGenerator = () => new T();
- algorithmType = typeof(T);
- }
public Type SymmetricAlgorithmType
{
@@ -88,8 +85,8 @@ public static byte[] GenerateRandomEncryptionKey()
public static byte[] GenerateRandomEncryptionKey(int length)
{
- byte[] result = new byte[length];
- RNGCryptoServiceProvider.Create().GetBytes(result);
+ var result = new byte[length];
+ RandomNumberGenerator.Create().GetBytes(result);
return result;
}
}
View
3 Raven.Tests/MailingList/spokeypokey/spokeypokey.cs
@@ -80,7 +80,8 @@ where b.Households.Any(h => h.Members.Any(m => m.Name == "Joe"))
// Query using BarnIndex
var result2 = from b in session.Query<Barn, BarnIndex>()
- .Statistics(out statistics)
+ .Customize(x => x.WaitForNonStaleResults())
+ .Statistics(out statistics)
where b.Name == "Barn1"
select b;
var result2List = result2.ToList();

0 comments on commit 012e858

Please sign in to comment.