From 90a73c7c1dd0846c4f250a5fc5f01379239338ce Mon Sep 17 00:00:00 2001 From: Jason Pierce Date: Tue, 31 Jan 2017 15:34:20 -0800 Subject: [PATCH 1/3] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 1280002..ecf7a42 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,9 @@ The *Settings* object is a collection of mutable defaults used throughout the li // with Rijndael.Encrypt being just one of them. After making this change, // any future calls to Rijndael.Encrypt will make use of this new value Settings.HashIterations = 25000; + +// To reset all the settings to their default values +Settings.Reset(); ``` ## Appendix From 40aebe3e38f5f18186d41ce1589cba17731f410b Mon Sep 17 00:00:00 2001 From: Jason Pierce Date: Tue, 31 Jan 2017 16:19:20 -0800 Subject: [PATCH 2/3] Add Reset method to Settings --- Rijndael256/Settings.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Rijndael256/Settings.cs b/Rijndael256/Settings.cs index 45b8ae2..ff710a2 100644 --- a/Rijndael256/Settings.cs +++ b/Rijndael256/Settings.cs @@ -13,10 +13,26 @@ namespace Rijndael256 /// public static class Settings { + static Settings() + { + // Set defaults during initialization + Reset(); + } + + /// + /// Resets all the settings to their default values + /// + public static void Reset() + { + HashIterations = _hashIterations; + } + /// /// The number of iterations used to derive hashes. /// Default is 10000. /// - public static int HashIterations = 10000; + public static int HashIterations; + + private const int _hashIterations = 10000; } } From c95b524c875227903608c1f9acd7634af4581ddf Mon Sep 17 00:00:00 2001 From: Jason Pierce Date: Tue, 31 Jan 2017 16:19:33 -0800 Subject: [PATCH 3/3] Update unit tests --- Rijndael256.Tests/SettingsTests.cs | 31 ++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/Rijndael256.Tests/SettingsTests.cs b/Rijndael256.Tests/SettingsTests.cs index 3d56ee5..9cb3636 100644 --- a/Rijndael256.Tests/SettingsTests.cs +++ b/Rijndael256.Tests/SettingsTests.cs @@ -10,6 +10,11 @@ using System.Linq; using Xunit; +// WARNING: HERE BE DRAGONS! +// We must disable xUnit's asyncrhonous test excution because the Settings +// object's default values are required by the other unit tests +[assembly: CollectionBehavior(DisableTestParallelization = true)] + namespace Rijndael256.Tests { public class SettingsTests @@ -17,6 +22,19 @@ public class SettingsTests const string Plaintext = "A secret phrase to test hashing."; const string Salt = "0A9FDB669FA44FF1BEC484A1BE6B6E2A"; + [Fact] + public void Reset() + { + var defaultHashIterations = Settings.HashIterations; + + Settings.HashIterations = 777; + Assert.Equal(Settings.HashIterations, 777); + Assert.NotEqual(Settings.HashIterations, defaultHashIterations); + + Settings.Reset(); + Assert.Equal(Settings.HashIterations, defaultHashIterations); + } + [Fact] public void HashIterations() { @@ -30,16 +48,9 @@ public void HashIterations() var hashChanged = Hash.Pbkdf2(Plaintext, Salt, Settings.HashIterations); Assert.False(hashChanged.SequenceEqual(proofDefault)); - RestoreDefaults(); - } - - /// - /// Settings is global, so we need to restore defaults before the other - /// unit tests, which depend on said defaults, are run. - /// - private void RestoreDefaults() - { - Settings.HashIterations = 10000; + // Settings is global, so we need to restore defaults before the other + // unit tests, which depend on said defaults, are run + Settings.Reset(); } } }