-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Aggregrated Value and add related unit tests
- Loading branch information
Showing
18 changed files
with
244 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace Leosac.KeyManager.Library.Tests | ||
{ | ||
[TestClass] | ||
public class KeyGenerationTests | ||
{ | ||
[TestMethod] | ||
[DataRow(8)] | ||
[DataRow(16)] | ||
[DataRow(32)] | ||
public void Test_Random(int keySize) | ||
{ | ||
var key1 = KeyGeneration.Random(keySize); | ||
Assert.AreEqual(keySize * 2, key1.Length); | ||
|
||
var key2 = KeyGeneration.Random(keySize); | ||
Assert.AreNotEqual(key1, key2); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(8)] | ||
[DataRow(16)] | ||
[DataRow(32)] | ||
public void Test_FromPassword(int keySize) | ||
{ | ||
var key = KeyGeneration.FromPassword("test", "Security Freedom", keySize); | ||
var rkey = "E088566240571EAD486818BE1199F53EB407411014BA1E36101C242FC34DEBAF"[..(keySize * 2)]; | ||
Assert.AreEqual(rkey, key, true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
namespace Leosac.KeyManager.Library.Tests | ||
{ | ||
[TestClass] | ||
public class KeyTests | ||
{ | ||
[TestMethod] | ||
public void OneMaterial_GetAggregatedValue_HexString() | ||
{ | ||
var key = new Key(null, "00112233445566778899AABBCCDDEEFF"); | ||
var v = key.GetAggregatedValueString(); | ||
Assert.AreEqual("00112233445566778899AABBCCDDEEFF", v, true); | ||
} | ||
|
||
[TestMethod] | ||
public void OneMaterial_SetAggregatedValue_HexString() | ||
{ | ||
var key = new Key(); | ||
key.SetAggregatedValueString("00112233445566778899AABBCCDDEEFF"); | ||
Assert.AreEqual("00112233445566778899AABBCCDDEEFF", key.Materials[0].Value, true); | ||
} | ||
|
||
[TestMethod] | ||
public void OneMaterial_GetAggregatedValue_Binary() | ||
{ | ||
var key = new Key(null, "00112233445566778899AABBCCDDEEFF"); | ||
var v = key.GetAggregatedValueBinary(); | ||
Assert.IsNotNull(v); | ||
Assert.AreEqual("00112233445566778899AABBCCDDEEFF", Convert.ToHexString(v), true); | ||
} | ||
|
||
[TestMethod] | ||
public void OneMaterial_GetAggregatedValue_HexStringWithSpace() | ||
{ | ||
var key = new Key(null, "00112233445566778899AABBCCDDEEFF"); | ||
var v = key.GetAggregatedValueString(KeyValueStringFormat.HexStringWithSpace); | ||
Assert.AreEqual("00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF", v, true); | ||
} | ||
|
||
[TestMethod] | ||
public void OneMaterial_SetAggregatedValue_HexStringWithSpace() | ||
{ | ||
var key = new Key(); | ||
key.SetAggregatedValueString("00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF", KeyValueStringFormat.HexStringWithSpace); | ||
Assert.AreEqual("00112233445566778899AABBCCDDEEFF", key.Materials[0].Value, true); | ||
} | ||
|
||
[TestMethod] | ||
public void TwoMaterials_GetAggregatedValue_HexString() | ||
{ | ||
var key = new Key(null, 8, new KeyMaterial("0011223344556677"), new KeyMaterial("8899AABBCCDDEEFF")); | ||
var v = key.GetAggregatedValueString(); | ||
Assert.AreEqual("00112233445566778899AABBCCDDEEFF", v, true); | ||
} | ||
|
||
[TestMethod] | ||
public void TwoMaterials_SetAggregatedValue_HexString() | ||
{ | ||
var key = new Key(null, 8, 2); | ||
key.SetAggregatedValueString("00112233445566778899AABBCCDDEEFF"); | ||
Assert.AreEqual("0011223344556677", key.Materials[0].Value, true); | ||
Assert.AreEqual("8899AABBCCDDEEFF", key.Materials[1].Value, true); | ||
} | ||
|
||
[TestMethod] | ||
public void TwoMaterials_GetAggregatedValue_Binary() | ||
{ | ||
var key = new Key(null, 8, new KeyMaterial("0011223344556677"), new KeyMaterial("8899AABBCCDDEEFF")); | ||
var v = key.GetAggregatedValueBinary(); | ||
Assert.IsNotNull(v); | ||
Assert.AreEqual("00112233445566778899AABBCCDDEEFF", Convert.ToHexString(v), true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.