public void TestMinimumGuaranteeV2KeyWrapIterations() { DateTime now = DateTime.UtcNow; int callCounter = -1; bool shouldTerminate = false; ((FakeNow)New <INow>()).TimeFunction = () => { if (shouldTerminate) { throw new InvalidOperationException("There should be no more calls at this point."); } if (callCounter++ == 0) { return(now); } if (callCounter < 5) { return(now.AddMilliseconds(callCounter * 50)); } shouldTerminate = true; return(now.AddMilliseconds(500)); }; long keyWrapIterations = new IterationCalculator().KeyWrapIterations(new V2Aes256CryptoFactory().CryptoId); Assert.That(keyWrapIterations, Is.EqualTo(5000), "The minimum guarantee should hold."); }
public static void TestKeyWrapIterationCalculator() { IterationCalculator calculator = Mock.Of <IterationCalculator>(c => c.KeyWrapIterations(It.Is <Guid>(g => g == new V1Aes128CryptoFactory().CryptoId)) == 666); UserSettings settings = new UserSettings(new SettingsStore(New <IDataStore>(@"C:\Folder\UserSettings.txt")), calculator); Assert.That(settings.GetKeyWrapIterations(new V1Aes128CryptoFactory().CryptoId), Is.EqualTo(666)); }
public UserSettings(ISettingsStore settingsStore, IterationCalculator keyWrapIterationCalculator) { if (settingsStore == null) { throw new ArgumentNullException(nameof(settingsStore)); } _settingsStore = settingsStore; _keyWrapIterationCalculator = keyWrapIterationCalculator; if (_settingsStore[nameof(SettingsVersion)].Length == 0) { _settingsStore[nameof(SettingsVersion)] = Convert.ToString(New <UserSettingsVersion>().Current, CultureInfo.InvariantCulture); } }
public void TestCalculatedV1KeyWrapIterations() { DateTime now = DateTime.UtcNow; int callCounter = -1; bool shouldTerminate = false; ((FakeNow)New <INow>()).TimeFunction = () => { if (shouldTerminate) { throw new InvalidOperationException("There should be no more calls at this point."); } if (callCounter++ == 0) { return(now); } return(now.AddMilliseconds(callCounter * 4)); }; long keyWrapIterations = new IterationCalculator().KeyWrapIterations(new V1Aes128CryptoFactory().CryptoId); Assert.That(keyWrapIterations, Is.EqualTo(12500), "If we do 125000 iterations in 500ms, the result should be 12500 as default iterations (1/20s)."); }
public FakeUserSettings(IterationCalculator keyWrapIterationCalculator) : base(New <ISettingsStore>(), keyWrapIterationCalculator) { }