Changed test project type to WIndows 8.1

Changed test project framework from Nunit to MSTest
Changed HashAlgorithm from BouncyCastle to WinRT crypto
WIP progress bar in opendatabaseusercontrol
TextBox with button made generic
WIP implement copy on button click in Entry Page
This commit is contained in:
2017-11-06 19:01:01 +01:00
committed by BONNEVILLE Geoffroy
parent 53a54252e3
commit 8e690747e2
85 changed files with 2836 additions and 672 deletions

View File

@@ -1,17 +1,17 @@
using System;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Cryptography.Hash;
using ModernKeePassLib.Utility;
using NUnit.Framework;
namespace ModernKeePassLib.Test.Cryptography.Hash
{
[TestFixture]
[TestClass]
public class Blake2bTests
{
[Test]
public void TestBlake2b()
[TestMethod]
public void TestBlake2bUtf8()
{
Blake2b h = new Blake2b();
@@ -19,7 +19,8 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
// From https://tools.ietf.org/html/rfc7693
byte[] pbData = StrUtil.Utf8.GetBytes("abc");
byte[] pbExpc = new byte[64] {
byte[] pbExpc = new byte[64]
{
0xBA, 0x80, 0xA5, 0x3F, 0x98, 0x1C, 0x4D, 0x0D,
0x6A, 0x27, 0x97, 0xB6, 0x9F, 0x12, 0xF6, 0xE9,
0x4C, 0x21, 0x2F, 0x14, 0x68, 0x5A, 0xC4, 0xB7,
@@ -31,12 +32,18 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
};
byte[] pbC = h.ComputeHash(pbData);
Assert.That(MemUtil.ArraysEqual(pbC, pbExpc), Is.True);
Assert.IsTrue(MemUtil.ArraysEqual(pbC, pbExpc));
}
[TestMethod]
public void TestBlake2bEmpty()
{
// ======================================================
// Computed using the official b2sum tool
Blake2b h = new Blake2b();
pbExpc = new byte[64] {
var pbExpc = new byte[64]
{
0x78, 0x6A, 0x02, 0xF7, 0x42, 0x01, 0x59, 0x03,
0xC6, 0xC6, 0xFD, 0x85, 0x25, 0x52, 0xD2, 0x72,
0x91, 0x2F, 0x47, 0x40, 0xE1, 0x58, 0x47, 0x61,
@@ -47,18 +54,23 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
0xD5, 0x6F, 0x70, 0x1A, 0xFE, 0x9B, 0xE2, 0xCE
};
pbC = h.ComputeHash(MemUtil.EmptyByteArray);
Assert.That(MemUtil.ArraysEqual(pbC, pbExpc), Is.True);
var pbC = h.ComputeHash(MemUtil.EmptyByteArray);
Assert.IsTrue(MemUtil.ArraysEqual(pbC, pbExpc));
}
// ======================================================
[TestMethod]
public void TestBlake2bString()
{
// ======================================================
// Computed using the official b2sum tool
Blake2b h = new Blake2b();
string strS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:,;_-\r\n";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 1000; ++i) sb.Append(strS);
pbData = StrUtil.Utf8.GetBytes(sb.ToString());
var pbData = StrUtil.Utf8.GetBytes(sb.ToString());
pbExpc = new byte[64] {
var pbExpc = new byte[64] {
0x59, 0x69, 0x8D, 0x3B, 0x83, 0xF4, 0x02, 0x4E,
0xD8, 0x99, 0x26, 0x0E, 0xF4, 0xE5, 0x9F, 0x20,
0xDC, 0x31, 0xEE, 0x5B, 0x45, 0xEA, 0xBB, 0xFC,
@@ -77,11 +89,11 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
h.TransformBlock(pbData, p, cb, pbData, p);
p += cb;
}
Assert.That(p, Is.EqualTo(pbData.Length));
Assert.AreEqual(p, pbData.Length);
h.TransformFinalBlock(MemUtil.EmptyByteArray, 0, 0);
Assert.That(MemUtil.ArraysEqual(h.Hash, pbExpc), Is.True);
Assert.IsTrue(MemUtil.ArraysEqual(h.Hash, pbExpc));
h.Clear();
}

View File

@@ -1,14 +1,14 @@
using ModernKeePassLib.Cryptography;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using ModernKeePassLib.Cryptography;
using ModernKeePassLib.Cryptography.Hash;
using ModernKeePassLib.Utility;
using NUnit.Framework;
namespace ModernKeePassLib.Test.Cryptography.Hash
{
[TestFixture]
[TestClass]
public class HmacTests
{
[Test]
[TestMethod]
public void TestHmac1()
{
// Test vectors from RFC 4231
@@ -26,7 +26,7 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
HmacEval(pbKey, pbMsg, pbExpc);
}
[Test]
[TestMethod]
public void TestHmac2()
{
var pbKey = new byte[131];
@@ -44,7 +44,7 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
HmacEval(pbKey, pbMsg, pbExpc);
}
[Test]
[TestMethod]
public void TestHmacSha1ComputeHash()
{
var expectedHash = "AC2C2E614882CE7158F69B7E3B12114465945D01";
@@ -52,11 +52,11 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
var key = StrUtil.Utf8.GetBytes("hello");
using (var result = new HMACSHA1(key))
{
Assert.That(ByteToString(result.ComputeHash(message)), Is.EqualTo(expectedHash));
Assert.AreEqual(ByteToString(result.ComputeHash(message)), expectedHash);
}
}
[Test]
[TestMethod]
public void TestHmacSha256ComputeHash()
{
var expectedHash = "09C1BD2DE4E5659C0EFAF9E6AE4723E9CF96B69609B4E562F6AFF1745D7BF4E0";
@@ -64,7 +64,7 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
var key = StrUtil.Utf8.GetBytes("hello");
using (var result = new HMACSHA256(key))
{
Assert.That(ByteToString(result.ComputeHash(message)), Is.EqualTo(expectedHash));
Assert.AreEqual(ByteToString(result.ComputeHash(message)), expectedHash);
}
}
@@ -79,7 +79,7 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
return (sbinary);
}
[Test]
[TestMethod]
public void TestHmacOtp()
{
var pbSecret = StrUtil.Utf8.GetBytes("12345678901234567890");
@@ -89,7 +89,7 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
for (var i = 0; i < vExp.Length; ++i)
{
Assert.That(HmacOtp.Generate(pbSecret, (ulong)i, 6, false, -1), Is.EqualTo(vExp[i]));
Assert.AreEqual(HmacOtp.Generate(pbSecret, (ulong)i, 6, false, -1), vExp[i]);
}
}
@@ -102,7 +102,7 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
h.TransformFinalBlock(MemUtil.EmptyByteArray, 0, 0);
byte[] pbHash = h.Hash;
Assert.That(MemUtil.ArraysEqual(pbHash, pbExpc), Is.True);
Assert.IsTrue(MemUtil.ArraysEqual(pbHash, pbExpc));
// Reuse the object
h.Initialize();
@@ -110,7 +110,7 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
h.TransformFinalBlock(MemUtil.EmptyByteArray, 0, 0);
pbHash = h.Hash;
Assert.That(MemUtil.ArraysEqual(pbHash, pbExpc), Is.True);
Assert.IsTrue(MemUtil.ArraysEqual(pbHash, pbExpc));
}
}
}

View File

@@ -1,31 +1,31 @@
using ModernKeePassLib.Cryptography.Hash;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using ModernKeePassLib.Cryptography.Hash;
using ModernKeePassLib.Utility;
using NUnit.Framework;
namespace ModernKeePassLib.Test.Cryptography.Hash
{
[TestFixture]
[TestClass]
public class SHAManagedTests
{
[Test]
[TestMethod]
public void TestSha256ComputeHash()
{
var expectedHash = "B822F1CD2DCFC685B47E83E3980289FD5D8E3FF3A82DEF24D7D1D68BB272EB32";
var message = StrUtil.Utf8.GetBytes("testing123");
using (var result = new SHA256Managed())
{
Assert.That(ByteToString(result.ComputeHash(message)), Is.EqualTo(expectedHash));
Assert.AreEqual(ByteToString(result.ComputeHash(message)), expectedHash);
}
}
[Test]
[TestMethod]
public void TestSha512ComputeHash()
{
var expectedHash = "4120117B3190BA5E24044732B0B09AA9ED50EB1567705ABCBFA78431A4E0A96B1152ED7F4925966B1C82325E186A8100E692E6D2FCB6702572765820D25C7E9E";
var message = StrUtil.Utf8.GetBytes("testing123");
using (var result = new SHA512Managed())
{
Assert.That(ByteToString(result.ComputeHash(message)), Is.EqualTo(expectedHash));
Assert.AreEqual(ByteToString(result.ComputeHash(message)), expectedHash);
}
}
private static string ByteToString(byte[] buff)