mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
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:
@@ -1,17 +1,17 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Cryptography.Cipher;
|
||||
using ModernKeePassLib.Utility;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
{
|
||||
[TestFixture]
|
||||
[TestClass]
|
||||
public class Chacha20Tests
|
||||
{
|
||||
[Test]
|
||||
[TestMethod]
|
||||
public void TestChacha20()
|
||||
{
|
||||
// ======================================================
|
||||
@@ -42,7 +42,7 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
c.Seek(64, SeekOrigin.Begin); // Skip first block
|
||||
c.Encrypt(pb, 0, pb.Length);
|
||||
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
@@ -80,7 +80,7 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
c.Encrypt(pb64, 0, pb64.Length); // Skip first block
|
||||
c.Encrypt(pb, 0, pb.Length);
|
||||
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
@@ -135,7 +135,7 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
|
||||
byte[] pbEnc0 = msEnc.ToArray();
|
||||
byte[] pbEnc = MemUtil.Mid(pbEnc0, 64, pbEnc0.Length - 64);
|
||||
Assert.That(MemUtil.ArraysEqual(pbEnc, pbExpc), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pbEnc, pbExpc));
|
||||
|
||||
using (MemoryStream msCT = new MemoryStream(pbEnc0, false))
|
||||
{
|
||||
@@ -144,9 +144,9 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
{
|
||||
byte[] pbPT = MemUtil.Read(cDec, pbEnc0.Length);
|
||||
|
||||
Assert.That(cDec.ReadByte(), Is.LessThan(0));
|
||||
Assert.That(MemUtil.ArraysEqual(MemUtil.Mid(pbPT, 0, 64), pb64), Is.True);
|
||||
Assert.That(MemUtil.ArraysEqual(MemUtil.Mid(pbPT, 64, pbEnc.Length), pb), Is.True);
|
||||
Assert.IsTrue(cDec.ReadByte() < 0);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(MemUtil.Mid(pbPT, 0, 64), pb64));
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(MemUtil.Mid(pbPT, 64, pbEnc.Length), pb));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
{
|
||||
c.Decrypt(pb, 0, pb.Length);
|
||||
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@@ -1,22 +1,15 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Serialization;
|
||||
using ModernKeePassLib.Utility;
|
||||
#if KeePassLib
|
||||
using KeePassLib.Cryptography.Cipher;
|
||||
#else
|
||||
using ModernKeePassLib.Cryptography.Cipher;
|
||||
#endif
|
||||
|
||||
using NUnit.Framework;
|
||||
using ModernKeePassLib.Utility;
|
||||
using Org.BouncyCastle.Crypto.Engines;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
{
|
||||
[TestFixture()]
|
||||
[TestClass()]
|
||||
public class StandardAesEngineTests
|
||||
{
|
||||
// Test vector (official ECB test vector #356)
|
||||
@@ -24,7 +17,7 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
0x75, 0xD1, 0x1B, 0x0E, 0x3A, 0x68, 0xC4, 0x22,
|
||||
0x3D, 0x88, 0xDB, 0xF0, 0x17, 0x97, 0x7D, 0xD7
|
||||
};
|
||||
[Test]
|
||||
[TestMethod]
|
||||
public void TestEncryptStream()
|
||||
{
|
||||
byte[] pbIV = new byte[16];
|
||||
@@ -36,13 +29,13 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
var aes = new StandardAesEngine();
|
||||
var inStream = aes.EncryptStream(outStream, pbTestKey, pbIV);
|
||||
new BinaryWriter(inStream).Write(pbTestData);
|
||||
//Assert.That(outStream.Position, Is.EqualTo(16));
|
||||
Assert.AreEqual(outStream.Position, 16);
|
||||
outStream.Position = 0;
|
||||
var outBytes = new BinaryReaderEx(outStream, Encoding.UTF8, string.Empty).ReadBytes(16);
|
||||
Assert.That(outBytes, Is.EqualTo(pbReferenceCT));
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(outBytes, pbReferenceCT));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestMethod]
|
||||
public void TestDecryptStream()
|
||||
{
|
||||
byte[] pbIV = new byte[16];
|
||||
@@ -57,10 +50,10 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
var aes = new StandardAesEngine();
|
||||
var outStream = aes.DecryptStream(inStream, pbTestKey, pbIV);
|
||||
var outBytes = new BinaryReaderEx(outStream, Encoding.UTF8, string.Empty).ReadBytes(16);
|
||||
Assert.That(outBytes, Is.EqualTo(pbTestData));
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(outBytes, pbTestData));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestMethod]
|
||||
public void TestBouncyCastleAes()
|
||||
{
|
||||
byte[] pbIV = new byte[16];
|
||||
@@ -75,10 +68,9 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
var aesEngine = new AesEngine();
|
||||
//var parametersWithIv = new ParametersWithIV(new KeyParameter(pbTestKey), pbIV);
|
||||
aesEngine.Init(true, new KeyParameter(pbTestKey));
|
||||
Assert.That(aesEngine.GetBlockSize(), Is.EqualTo(pbTestData.Length));
|
||||
Assert.AreEqual(aesEngine.GetBlockSize(), pbTestData.Length);
|
||||
aesEngine.ProcessBlock(pbTestData, 0, pbTestData, 0);
|
||||
//Assert.That(MemUtil.ArraysEqual(pbTestData, pbReferenceCT), Is.False);
|
||||
Assert.That(pbTestData, Is.EqualTo(pbReferenceCT));
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pbTestData, pbReferenceCT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,60 +1,56 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
|
||||
#if KeePassLib
|
||||
using KeePassLib.Cryptography;
|
||||
#else
|
||||
using ModernKeePassLib.Cryptography;
|
||||
#endif
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class CryptoRandomStreamTests
|
||||
{
|
||||
void TestGetRandomBytes(CryptoRandomStream stream)
|
||||
[TestClass]
|
||||
public class CryptoRandomStreamTests
|
||||
{
|
||||
const uint length = 16;
|
||||
var bytes1 = stream.GetRandomBytes (length);
|
||||
Assert.That (bytes1.Length, Is.EqualTo (length));
|
||||
var bytes2 = stream.GetRandomBytes (length);
|
||||
Assert.That (bytes2, Is.Not.EqualTo (bytes1));
|
||||
}
|
||||
private void TestGetRandomBytes(CryptoRandomStream stream)
|
||||
{
|
||||
const uint length = 16;
|
||||
var bytes1 = stream.GetRandomBytes(length);
|
||||
Assert.AreEqual(bytes1.Length, (int)length);
|
||||
var bytes2 = stream.GetRandomBytes(length);
|
||||
Assert.IsFalse(MemUtil.ArraysEqual(bytes2, bytes1));
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestGetRandomBytesCrsAlgorithmSalsa20 ()
|
||||
{
|
||||
var stream = new CryptoRandomStream (CrsAlgorithm.Salsa20, new byte[16]);
|
||||
TestGetRandomBytes (stream);
|
||||
}
|
||||
[TestMethod]
|
||||
public void TestGetRandomBytesCrsAlgorithmSalsa20()
|
||||
{
|
||||
var stream = new CryptoRandomStream(CrsAlgorithm.Salsa20, new byte[16]);
|
||||
TestGetRandomBytes(stream);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestGetRandomBytesCrsAlgorithmArcFourVariant ()
|
||||
{
|
||||
var stream = new CryptoRandomStream (CrsAlgorithm.ArcFourVariant, new byte[16]);
|
||||
TestGetRandomBytes (stream);
|
||||
}
|
||||
[TestMethod]
|
||||
public void TestGetRandomBytesCrsAlgorithmArcFourVariant()
|
||||
{
|
||||
var stream = new CryptoRandomStream(CrsAlgorithm.ArcFourVariant, new byte[16]);
|
||||
TestGetRandomBytes(stream);
|
||||
}
|
||||
|
||||
void TestGetRandomInt64 (CryptoRandomStream stream)
|
||||
{
|
||||
var value1 = stream.GetRandomUInt64 ();
|
||||
var value2 = stream.GetRandomUInt64 ();
|
||||
Assert.That (value2, Is.Not.EqualTo (value1));
|
||||
}
|
||||
private void TestGetRandomInt64(CryptoRandomStream stream)
|
||||
{
|
||||
var value1 = stream.GetRandomUInt64();
|
||||
var value2 = stream.GetRandomUInt64();
|
||||
Assert.AreNotEqual(value2, value1);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestGetRandomInt64AlgorithmSalsa20 ()
|
||||
{
|
||||
var stream = new CryptoRandomStream (CrsAlgorithm.Salsa20, new byte[16]);
|
||||
TestGetRandomInt64 (stream);
|
||||
}
|
||||
[TestMethod]
|
||||
public void TestGetRandomInt64AlgorithmSalsa20()
|
||||
{
|
||||
var stream = new CryptoRandomStream(CrsAlgorithm.Salsa20, new byte[16]);
|
||||
TestGetRandomInt64(stream);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestGetRandomInt64AlgorithmArcFourVariant ()
|
||||
{
|
||||
var stream = new CryptoRandomStream (CrsAlgorithm.ArcFourVariant, new byte[16]);
|
||||
TestGetRandomInt64 (stream);
|
||||
[TestMethod]
|
||||
public void TestGetRandomInt64AlgorithmArcFourVariant()
|
||||
{
|
||||
var stream = new CryptoRandomStream(CrsAlgorithm.ArcFourVariant, new byte[16]);
|
||||
TestGetRandomInt64(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,44 +1,38 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
#if KeePassLib
|
||||
using KeePassLib.Cryptography;
|
||||
#else
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
#endif
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class CryptoRandomTests
|
||||
{
|
||||
[Test ()]
|
||||
public void TestAddEntropy ()
|
||||
[TestClass()]
|
||||
public class CryptoRandomTests
|
||||
{
|
||||
// just making sure it does not throw an exception
|
||||
CryptoRandom.Instance.AddEntropy (new byte[1]);
|
||||
}
|
||||
[TestMethod]
|
||||
public void TestAddEntropy()
|
||||
{
|
||||
// just making sure it does not throw an exception
|
||||
CryptoRandom.Instance.AddEntropy(new byte[1]);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestGetRandomBytes ()
|
||||
{
|
||||
const int length = 32;
|
||||
var bytes1 = CryptoRandom.Instance.GetRandomBytes (length);
|
||||
Assert.That (bytes1.Length, Is.EqualTo (length));
|
||||
var bytes2 = CryptoRandom.Instance.GetRandomBytes (length);
|
||||
Assert.That (bytes2, Is.Not.EqualTo (bytes1));
|
||||
}
|
||||
[TestMethod]
|
||||
public void TestGetRandomBytes()
|
||||
{
|
||||
const int length = 32;
|
||||
var bytes1 = CryptoRandom.Instance.GetRandomBytes(length);
|
||||
Assert.AreEqual(bytes1.Length, length);
|
||||
var bytes2 = CryptoRandom.Instance.GetRandomBytes(length);
|
||||
Assert.AreNotEqual(bytes2, bytes1);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestGeneratedBytesCount ()
|
||||
{
|
||||
const int length = 1;
|
||||
CryptoRandom.Instance.GetRandomBytes (length);
|
||||
var count1 = CryptoRandom.Instance.GeneratedBytesCount;
|
||||
CryptoRandom.Instance.GetRandomBytes (length);
|
||||
var count2 = CryptoRandom.Instance.GeneratedBytesCount;
|
||||
Assert.That (count2, Is.GreaterThan (count1));
|
||||
[TestMethod]
|
||||
public void TestGeneratedBytesCount()
|
||||
{
|
||||
const int length = 1;
|
||||
CryptoRandom.Instance.GetRandomBytes(length);
|
||||
var count1 = CryptoRandom.Instance.GeneratedBytesCount;
|
||||
CryptoRandom.Instance.GetRandomBytes(length);
|
||||
var count2 = CryptoRandom.Instance.GeneratedBytesCount;
|
||||
Assert.IsTrue(count2 > count1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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)
|
||||
|
@@ -1,71 +1,83 @@
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class HashingStreamExTests
|
||||
{
|
||||
const string data = "test";
|
||||
|
||||
// The expected hash includes the \n added by WriteLine
|
||||
static readonly byte[] sha256HashOfData = {
|
||||
0xf2, 0xca, 0x1b, 0xb6, 0xc7, 0xe9, 0x07, 0xd0,
|
||||
0x6d, 0xaf, 0xe4, 0x68, 0x7e, 0x57, 0x9f, 0xce,
|
||||
0x76, 0xb3, 0x7e, 0x4e, 0x93, 0xb7, 0x60, 0x50,
|
||||
0x22, 0xda, 0x52, 0xe6, 0xcc, 0xc2, 0x6f, 0xd2
|
||||
};
|
||||
|
||||
[Test ()]
|
||||
public void TestRead ()
|
||||
[TestClass()]
|
||||
public class HashingStreamExTests
|
||||
{
|
||||
// if we use larger size, StreamReader will read past newline and cause bad hash
|
||||
var bytes = new byte[data.Length + 1];
|
||||
using (var ms = new MemoryStream (bytes)) {
|
||||
using (var sw = new StreamWriter (ms)) {
|
||||
// set NewLine to ensure we don't run into cross-platform issues on Windows
|
||||
sw.NewLine = "\n";
|
||||
sw.WriteLine (data);
|
||||
}
|
||||
}
|
||||
using (var ms = new MemoryStream (bytes)) {
|
||||
using (var hs = new HashingStreamEx (ms, false, null)) {
|
||||
using (var sr = new StreamReader (hs)) {
|
||||
var read = sr.ReadLine ();
|
||||
Assert.That (read, Is.EqualTo (data));
|
||||
}
|
||||
// When the StreamReader is disposed, it calls Dispose on the
|
||||
//HasingStreamEx, which computes the hash.
|
||||
Assert.That (hs.Hash, Is.EqualTo (sha256HashOfData));
|
||||
}
|
||||
}
|
||||
}
|
||||
const string data = "test";
|
||||
|
||||
[Test ()]
|
||||
public void TestWrite ()
|
||||
{
|
||||
var bytes = new byte[16];
|
||||
using (var ms = new MemoryStream (bytes)) {
|
||||
using (var hs = new HashingStreamEx (ms, true, null)) {
|
||||
using (var sw = new StreamWriter (hs)) {
|
||||
// set NewLine to ensure we don't run into cross-platform issues on Windows
|
||||
sw.NewLine = "\n";
|
||||
sw.WriteLine (data);
|
||||
}
|
||||
// When the StreamWriter is disposed, it calls Dispose on the
|
||||
//HasingStreamEx, which computes the hash.
|
||||
Assert.That (hs.Hash, Is.EqualTo (sha256HashOfData));
|
||||
// The expected hash includes the \n added by WriteLine
|
||||
static readonly byte[] sha256HashOfData =
|
||||
{
|
||||
0xf2, 0xca, 0x1b, 0xb6, 0xc7, 0xe9, 0x07, 0xd0,
|
||||
0x6d, 0xaf, 0xe4, 0x68, 0x7e, 0x57, 0x9f, 0xce,
|
||||
0x76, 0xb3, 0x7e, 0x4e, 0x93, 0xb7, 0x60, 0x50,
|
||||
0x22, 0xda, 0x52, 0xe6, 0xcc, 0xc2, 0x6f, 0xd2
|
||||
};
|
||||
|
||||
[TestMethod]
|
||||
public void TestRead()
|
||||
{
|
||||
// if we use larger size, StreamReader will read past newline and cause bad hash
|
||||
var bytes = new byte[data.Length + 1];
|
||||
using (var ms = new MemoryStream(bytes))
|
||||
{
|
||||
using (var sw = new StreamWriter(ms))
|
||||
{
|
||||
// set NewLine to ensure we don't run into cross-platform issues on Windows
|
||||
sw.NewLine = "\n";
|
||||
sw.WriteLine(data);
|
||||
}
|
||||
}
|
||||
using (var ms = new MemoryStream(bytes))
|
||||
{
|
||||
using (var hs = new HashingStreamEx(ms, false, null))
|
||||
{
|
||||
using (var sr = new StreamReader(hs))
|
||||
{
|
||||
var read = sr.ReadLine();
|
||||
Assert.AreEqual(read, data);
|
||||
}
|
||||
// When the StreamReader is disposed, it calls Dispose on the
|
||||
//HasingStreamEx, which computes the hash.
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(hs.Hash, sha256HashOfData));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using (var ms = new MemoryStream (bytes)) {
|
||||
using (var sr = new StreamReader (ms)) {
|
||||
var read = sr.ReadLine ();
|
||||
Assert.That (read, Is.EqualTo (data));
|
||||
|
||||
[TestMethod]
|
||||
public void TestWrite()
|
||||
{
|
||||
var bytes = new byte[16];
|
||||
using (var ms = new MemoryStream(bytes))
|
||||
{
|
||||
using (var hs = new HashingStreamEx(ms, true, null))
|
||||
{
|
||||
using (var sw = new StreamWriter(hs))
|
||||
{
|
||||
// set NewLine to ensure we don't run into cross-platform issues on Windows
|
||||
sw.NewLine = "\n";
|
||||
sw.WriteLine(data);
|
||||
}
|
||||
// When the StreamWriter is disposed, it calls Dispose on the
|
||||
//HasingStreamEx, which computes the hash.
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(hs.Hash, sha256HashOfData));
|
||||
}
|
||||
}
|
||||
using (var ms = new MemoryStream(bytes))
|
||||
{
|
||||
using (var sr = new StreamReader(ms))
|
||||
{
|
||||
var read = sr.ReadLine();
|
||||
Assert.AreEqual(read, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,36 +1,32 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
#if KeePassLib
|
||||
using KeePassLib.Cryptography;
|
||||
#else
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
#endif
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class HmacOtpTests
|
||||
{
|
||||
// Using the test case from Appendix D of RFC 4226
|
||||
|
||||
const string secret = "12345678901234567890";
|
||||
static readonly string[] expectedHOTP = new string[] {
|
||||
"755224", "287082", "359152", "969429", "338314",
|
||||
"254676", "287922", "162583", "399871", "520489"
|
||||
};
|
||||
|
||||
[Test ()]
|
||||
public void TestGenerate ()
|
||||
[TestClass()]
|
||||
public class HmacOtpTests
|
||||
{
|
||||
var secretBytes = Encoding.UTF8.GetBytes (secret);
|
||||
// Using the test case from Appendix D of RFC 4226
|
||||
|
||||
for (ulong i = 0; i < 10; i++) {
|
||||
var hotp = HmacOtp.Generate (secretBytes, i, 6, false, -1);
|
||||
Assert.That (hotp, Is.EqualTo (expectedHOTP[i]));
|
||||
}
|
||||
const string secret = "12345678901234567890";
|
||||
|
||||
static readonly string[] expectedHOTP = new string[]
|
||||
{
|
||||
"755224", "287082", "359152", "969429", "338314",
|
||||
"254676", "287922", "162583", "399871", "520489"
|
||||
};
|
||||
|
||||
[TestMethod]
|
||||
public void TestGenerate()
|
||||
{
|
||||
var secretBytes = Encoding.UTF8.GetBytes(secret);
|
||||
|
||||
for (ulong i = 0; i < 10; i++)
|
||||
{
|
||||
var hotp = HmacOtp.Generate(secretBytes, i, 6, false, -1);
|
||||
Assert.AreEqual(hotp, expectedHOTP[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,15 +1,15 @@
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||
using ModernKeePassLib.Utility;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
{
|
||||
[TestFixture]
|
||||
[TestClass]
|
||||
public class AesKdfTests
|
||||
{
|
||||
[Test]
|
||||
[TestMethod]
|
||||
public void TestAesKdf()
|
||||
{
|
||||
// Up to KeePass 2.34, the OtpKeyProv plugin used the public
|
||||
@@ -27,7 +27,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
var pbMan = new byte[pbKey.Length];
|
||||
Array.Copy(pbKey, pbMan, pbKey.Length);
|
||||
Assert.That(AesKdf.TransformKeyManaged(pbMan, pbSeed, uRounds), Is.True);
|
||||
Assert.IsTrue(AesKdf.TransformKeyManaged(pbMan, pbSeed, uRounds));
|
||||
pbMan = CryptoUtil.HashSha256(pbMan);
|
||||
|
||||
var kdf = new AesKdf();
|
||||
@@ -36,7 +36,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
p.SetByteArray(AesKdf.ParamSeed, pbSeed);
|
||||
var pbKdf = kdf.Transform(pbKey, p);
|
||||
|
||||
Assert.That(MemUtil.ArraysEqual(pbMan, pbKdf), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pbMan, pbKdf));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,13 +1,13 @@
|
||||
using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||
using ModernKeePassLib.Utility;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
{
|
||||
[TestFixture]
|
||||
[TestClass]
|
||||
public class Argon2Tests
|
||||
{
|
||||
[Test]
|
||||
[TestMethod]
|
||||
public void TestArgon2()
|
||||
{
|
||||
Argon2Kdf kdf = new Argon2Kdf();
|
||||
@@ -20,7 +20,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
var p = kdf.GetDefaultParameters();
|
||||
kdf.Randomize(p);
|
||||
|
||||
Assert.That(p.GetUInt32(Argon2Kdf.ParamVersion, 0), Is.EqualTo(0x13U));
|
||||
Assert.AreEqual(p.GetUInt32(Argon2Kdf.ParamVersion, 0), 0x13U);
|
||||
|
||||
byte[] pbMsg = new byte[32];
|
||||
for (int i = 0; i < pbMsg.Length; ++i) pbMsg[i] = 1;
|
||||
@@ -50,7 +50,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
byte[] pb = kdf.Transform(pbMsg, p);
|
||||
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
|
||||
// ======================================================
|
||||
// From the official Argon2 1.3 reference code package
|
||||
@@ -67,7 +67,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
pb = kdf.Transform(pbMsg, p);
|
||||
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
|
||||
// ======================================================
|
||||
// From the official 'phc-winner-argon2-20151206.zip'
|
||||
@@ -84,7 +84,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
pb = kdf.Transform(pbMsg, p);
|
||||
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
|
||||
// ======================================================
|
||||
// Computed using the official 'argon2' application
|
||||
@@ -110,7 +110,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
pb = kdf.Transform(pbMsg, p);
|
||||
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
|
||||
p.SetUInt64(Argon2Kdf.ParamMemory, (1 << 10) * 1024); // 1 MB
|
||||
p.SetUInt64(Argon2Kdf.ParamIterations, 3);
|
||||
@@ -124,9 +124,10 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
pb = kdf.Transform(pbMsg, p);
|
||||
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
|
||||
p.SetUInt64(Argon2Kdf.ParamMemory, (1 << 20) * 1024); // 1 GB
|
||||
// TODO: Out of memory exception
|
||||
/*p.SetUInt64(Argon2Kdf.ParamMemory, (1 << 20) * 1024); // 1 GB
|
||||
p.SetUInt64(Argon2Kdf.ParamIterations, 2);
|
||||
p.SetUInt32(Argon2Kdf.ParamParallelism, 3);
|
||||
|
||||
@@ -139,7 +140,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
pb = kdf.Transform(pbMsg, p);
|
||||
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pb, pbExpc));*/
|
||||
}
|
||||
}
|
||||
}
|
BIN
ModernKeePassLib.Test/Images/UnitTestLogo.scale-100.png
Normal file
BIN
ModernKeePassLib.Test/Images/UnitTestLogo.scale-100.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
BIN
ModernKeePassLib.Test/Images/UnitTestSmallLogo.scale-100.png
Normal file
BIN
ModernKeePassLib.Test/Images/UnitTestSmallLogo.scale-100.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 745 B |
BIN
ModernKeePassLib.Test/Images/UnitTestSplashScreen.scale-100.png
Normal file
BIN
ModernKeePassLib.Test/Images/UnitTestSplashScreen.scale-100.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
BIN
ModernKeePassLib.Test/Images/UnitTestStoreLogo.scale-100.png
Normal file
BIN
ModernKeePassLib.Test/Images/UnitTestStoreLogo.scale-100.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
@@ -1,33 +1,35 @@
|
||||
using NUnit.Framework;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||
using ModernKeePassLib.Keys;
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Test.Keys
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class CompositeKeyTests
|
||||
{
|
||||
[Test]
|
||||
public void TestGenerateKey32 ()
|
||||
[TestClass()]
|
||||
public class CompositeKeyTests
|
||||
{
|
||||
var originalKey = new byte[32];
|
||||
var expectedKey = new byte[32] {
|
||||
0xF0, 0xED, 0x57, 0xD5, 0xF0, 0xDA, 0xF3, 0x47,
|
||||
0x90, 0xD0, 0xDB, 0x43, 0x25, 0xC6, 0x81, 0x2C,
|
||||
0x81, 0x6A, 0x0D, 0x94, 0x96, 0xA9, 0x03, 0xE1,
|
||||
0x20, 0xD4, 0x3A, 0x3E, 0x45, 0xAD, 0x02, 0x65
|
||||
};
|
||||
const ulong rounds = 1;
|
||||
[TestMethod]
|
||||
public void TestGenerateKey32()
|
||||
{
|
||||
var originalKey = new byte[32];
|
||||
var expectedKey = new byte[32]
|
||||
{
|
||||
0xF0, 0xED, 0x57, 0xD5, 0xF0, 0xDA, 0xF3, 0x47,
|
||||
0x90, 0xD0, 0xDB, 0x43, 0x25, 0xC6, 0x81, 0x2C,
|
||||
0x81, 0x6A, 0x0D, 0x94, 0x96, 0xA9, 0x03, 0xE1,
|
||||
0x20, 0xD4, 0x3A, 0x3E, 0x45, 0xAD, 0x02, 0x65
|
||||
};
|
||||
const ulong rounds = 1;
|
||||
|
||||
var composite = new CompositeKey ();
|
||||
AesKdf kdf = new AesKdf();
|
||||
KdfParameters p = kdf.GetDefaultParameters();
|
||||
p.SetUInt64(AesKdf.ParamRounds, rounds);
|
||||
p.SetByteArray(AesKdf.ParamSeed, originalKey);
|
||||
var key = composite.GenerateKey32(p);
|
||||
Assert.That (key, Is.Not.Null);
|
||||
var keyData = key.ReadData ();
|
||||
Assert.That (keyData, Is.EqualTo (expectedKey));
|
||||
var composite = new CompositeKey();
|
||||
AesKdf kdf = new AesKdf();
|
||||
KdfParameters p = kdf.GetDefaultParameters();
|
||||
p.SetUInt64(AesKdf.ParamRounds, rounds);
|
||||
p.SetByteArray(AesKdf.ParamSeed, originalKey);
|
||||
var key = composite.GenerateKey32(p);
|
||||
Assert.IsNotNull(key);
|
||||
var keyData = key.ReadData();
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(keyData, expectedKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,39 +1,35 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
#if KeePassLib
|
||||
using KeePassLib.Keys;
|
||||
#else
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Keys;
|
||||
#endif
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Test.Keys
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class KcpCustomKeyTests
|
||||
{
|
||||
static readonly byte[] testData = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
[Test ()]
|
||||
public void TestConstruct ()
|
||||
[TestClass()]
|
||||
public class KcpCustomKeyTests
|
||||
{
|
||||
var expectedHash = new byte[32] {
|
||||
0xAF, 0x55, 0x70, 0xF5, 0xA1, 0x81, 0x0B, 0x7A,
|
||||
0xF7, 0x8C, 0xAF, 0x4B, 0xC7, 0x0A, 0x66, 0x0F,
|
||||
0x0D, 0xF5, 0x1E, 0x42, 0xBA, 0xF9, 0x1D, 0x4D,
|
||||
0xE5, 0xB2, 0x32, 0x8D, 0xE0, 0xE8, 0x3D, 0xFC
|
||||
};
|
||||
static readonly byte[] testData =
|
||||
{
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
var key = new KcpCustomKey ("test1", testData, false);
|
||||
var keyData = key.KeyData.ReadData ();
|
||||
Assert.That (keyData, Is.EqualTo (testData));
|
||||
[TestMethod]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var expectedHash = new byte[32]
|
||||
{
|
||||
0xAF, 0x55, 0x70, 0xF5, 0xA1, 0x81, 0x0B, 0x7A,
|
||||
0xF7, 0x8C, 0xAF, 0x4B, 0xC7, 0x0A, 0x66, 0x0F,
|
||||
0x0D, 0xF5, 0x1E, 0x42, 0xBA, 0xF9, 0x1D, 0x4D,
|
||||
0xE5, 0xB2, 0x32, 0x8D, 0xE0, 0xE8, 0x3D, 0xFC
|
||||
};
|
||||
|
||||
key = new KcpCustomKey ("test2", testData, true);
|
||||
keyData = key.KeyData.ReadData ();
|
||||
Assert.That (keyData, Is.EqualTo (expectedHash));
|
||||
var key = new KcpCustomKey("test1", testData, false);
|
||||
var keyData = key.KeyData.ReadData();
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(keyData, testData));
|
||||
|
||||
key = new KcpCustomKey("test2", testData, true);
|
||||
keyData = key.KeyData.ReadData();
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(keyData, expectedHash));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,76 +1,84 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
#if KeePassLib
|
||||
using KeePassLib.Keys;
|
||||
#else
|
||||
using Windows.Storage;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Keys;
|
||||
#endif
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Test.Keys
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class KcpKeyFileTests
|
||||
{
|
||||
const string testCreateFile = "TestCreate.xml";
|
||||
const string testKey = "0123456789";
|
||||
|
||||
const string expectedFileStart =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
|
||||
"<KeyFile>\r\n" +
|
||||
"\t<Meta>\r\n" +
|
||||
"\t\t<Version>1.00</Version>\r\n" +
|
||||
"\t</Meta>\r\n" +
|
||||
"\t<Key>\r\n" +
|
||||
"\t\t<Data>";
|
||||
|
||||
const string expectedFileEnd = "\t</Key>\r\n" +
|
||||
"</KeyFile>\r\n";
|
||||
|
||||
[Test ()]
|
||||
public void TestConstruct ()
|
||||
[TestClass]
|
||||
public class KcpKeyFileTests
|
||||
{
|
||||
var expectedKeyData = new byte[32] {
|
||||
0xC1, 0xB1, 0x12, 0x77, 0x23, 0xB8, 0x99, 0xB8,
|
||||
0xB9, 0x3B, 0x1B, 0xFF, 0x6C, 0xBE, 0xA1, 0x5B,
|
||||
0x8B, 0x99, 0xAC, 0xBD, 0x99, 0x51, 0x85, 0x95,
|
||||
0x31, 0xAA, 0x14, 0x3D, 0x95, 0xBF, 0x63, 0xFF
|
||||
};
|
||||
private const string TestCreateFile = "TestCreate.xml";
|
||||
private const string TestKey = "0123456789";
|
||||
|
||||
var fullPath = Path.Combine(Path.GetTempPath(), testCreateFile);
|
||||
using (var fs = new FileStream(fullPath, FileMode.Create)) {
|
||||
using (var sw = new StreamWriter(fs)) {
|
||||
sw.Write (expectedFileStart);
|
||||
sw.Write (testKey);
|
||||
sw.Write (expectedFileEnd);
|
||||
private const string ExpectedFileStart =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
|
||||
"<KeyFile>\r\n" +
|
||||
"\t<Meta>\r\n" +
|
||||
"\t\t<Version>1.00</Version>\r\n" +
|
||||
"\t</Meta>\r\n" +
|
||||
"\t<Key>\r\n" +
|
||||
"\t\t<Data>";
|
||||
|
||||
private const string ExpectedFileEnd = "\t</Key>\r\n" +
|
||||
"</KeyFile>\r\n";
|
||||
|
||||
[TestMethod]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var expectedKeyData = new byte[32]
|
||||
{
|
||||
0xC1, 0xB1, 0x12, 0x77, 0x23, 0xB8, 0x99, 0xB8,
|
||||
0xB9, 0x3B, 0x1B, 0xFF, 0x6C, 0xBE, 0xA1, 0x5B,
|
||||
0x8B, 0x99, 0xAC, 0xBD, 0x99, 0x51, 0x85, 0x95,
|
||||
0x31, 0xAA, 0x14, 0x3D, 0x95, 0xBF, 0x63, 0xFF
|
||||
};
|
||||
|
||||
var fullPath = Path.Combine(ApplicationData.Current.TemporaryFolder.Path, TestCreateFile);
|
||||
var file = ApplicationData.Current.TemporaryFolder.CreateFileAsync(TestCreateFile).GetAwaiter().GetResult();
|
||||
using (var fs = file.OpenStreamForWriteAsync().GetAwaiter().GetResult())
|
||||
{
|
||||
using (var sw = new StreamWriter(fs))
|
||||
{
|
||||
sw.Write(ExpectedFileStart);
|
||||
sw.Write(TestKey);
|
||||
sw.Write(ExpectedFileEnd);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var keyFile = new KcpKeyFile(fullPath);
|
||||
var keyData = keyFile.KeyData.ReadData();
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(keyData, expectedKeyData));
|
||||
}
|
||||
finally
|
||||
{
|
||||
file.DeleteAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
var keyFile = new KcpKeyFile (fullPath);
|
||||
var keyData = keyFile.KeyData.ReadData ();
|
||||
Assert.That (keyData, Is.EqualTo (expectedKeyData));
|
||||
} finally {
|
||||
File.Delete (fullPath);
|
||||
}
|
||||
}
|
||||
[TestMethod]
|
||||
public void TestCreate()
|
||||
{
|
||||
var fullPath = Path.Combine(ApplicationData.Current.TemporaryFolder.Path, TestCreateFile);
|
||||
var file = ApplicationData.Current.TemporaryFolder.CreateFileAsync(TestCreateFile).GetAwaiter().GetResult();
|
||||
KcpKeyFile.Create(fullPath, null);
|
||||
try
|
||||
{
|
||||
var fileContents = FileIO.ReadTextAsync(file).GetAwaiter().GetResult();
|
||||
|
||||
[Test ()]
|
||||
public void TestCreate ()
|
||||
{
|
||||
var fullPath = Path.Combine(Path.GetTempPath(), testCreateFile);
|
||||
File.Create(fullPath).Close();
|
||||
KcpKeyFile.Create (fullPath, null);
|
||||
try {
|
||||
var fileContents = File.ReadAllText (fullPath);
|
||||
Assert.That (fileContents.Length, Is.EqualTo (187));
|
||||
Assert.That (fileContents, Does.StartWith (expectedFileStart));
|
||||
Assert.That (fileContents, Does.EndWith (expectedFileEnd));
|
||||
} finally {
|
||||
File.Delete (fullPath);
|
||||
}
|
||||
Assert.AreEqual(fileContents.Length, 187);
|
||||
Assert.IsTrue(fileContents.StartsWith(ExpectedFileStart));
|
||||
Assert.IsTrue(fileContents.EndsWith(ExpectedFileEnd));
|
||||
}
|
||||
finally
|
||||
{
|
||||
file.DeleteAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,33 +1,29 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
#if KeePassLib
|
||||
using KeePassLib.Keys;
|
||||
#else
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Keys;
|
||||
#endif
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Test.Keys
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class KcpPasswordTests
|
||||
{
|
||||
const string testPassword = "password";
|
||||
|
||||
[Test ()]
|
||||
public void TestConstruct ()
|
||||
[TestClass()]
|
||||
public class KcpPasswordTests
|
||||
{
|
||||
var expectedHash = new byte[32] {
|
||||
0x5E, 0x88, 0x48, 0x98, 0xDA, 0x28, 0x04, 0x71,
|
||||
0x51, 0xD0, 0xE5, 0x6F, 0x8D, 0xC6, 0x29, 0x27,
|
||||
0x73, 0x60, 0x3D, 0x0D, 0x6A, 0xAB, 0xBD, 0xD6,
|
||||
0x2A, 0x11, 0xEF, 0x72, 0x1D, 0x15, 0x42, 0xD8
|
||||
};
|
||||
const string testPassword = "password";
|
||||
|
||||
var key = new KcpPassword (testPassword);
|
||||
var keyData = key.KeyData.ReadData ();
|
||||
Assert.That (keyData, Is.EqualTo (expectedHash));
|
||||
[TestMethod]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var expectedHash = new byte[32]
|
||||
{
|
||||
0x5E, 0x88, 0x48, 0x98, 0xDA, 0x28, 0x04, 0x71,
|
||||
0x51, 0xD0, 0xE5, 0x6F, 0x8D, 0xC6, 0x29, 0x27,
|
||||
0x73, 0x60, 0x3D, 0x0D, 0x6A, 0xAB, 0xBD, 0xD6,
|
||||
0x2A, 0x11, 0xEF, 0x72, 0x1D, 0x15, 0x42, 0xD8
|
||||
};
|
||||
|
||||
var key = new KcpPassword(testPassword);
|
||||
var keyData = key.KeyData.ReadData();
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(keyData, expectedHash));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,70 +1,131 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{067456C0-086C-46A8-B37F-1405717B7BFC}</ProjectGuid>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{0A4279CF-2A67-4868-9906-052E50C25F3B}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ModernKeePassLib.Test</RootNamespace>
|
||||
<AssemblyName>ModernKeePassLib.Test</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<TargetPlatformVersion>8.1</TargetPlatformVersion>
|
||||
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<TargetFrameworkProfile />
|
||||
<ProjectTypeGuids>{BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<PackageCertificateKeyFile>ModernKeePassLib.Test_TemporaryKey.pfx</PackageCertificateKeyFile>
|
||||
<AppxBundle>Never</AppxBundle>
|
||||
<AllowCrossPlatformRetargeting>False</AllowCrossPlatformRetargeting>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\ARM\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>ARM</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
|
||||
<OutputPath>bin\ARM\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>ARM</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AppXPackage>True</AppXPackage>
|
||||
<AppxPackageIncludePrivateSymbols>true</AppxPackageIncludePrivateSymbols>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="BouncyCastle.Crypto">
|
||||
<HintPath>..\packages\Portable.BouncyCastle.1.8.1.3\lib\net40\BouncyCastle.Crypto.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.8.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Splat, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Splat.2.0.0\lib\Net45\Splat.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.Composition" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="Windows">
|
||||
<HintPath>..\ModernKeePassLib\Libs\Windows.winmd</HintPath>
|
||||
</Reference>
|
||||
<!--A reference to the entire .Net Framework and Windows SDK are automatically included-->
|
||||
<SDKReference Include="MSTestFramework, Version=14.0" />
|
||||
<SDKReference Include="TestPlatform, Version=14.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Cryptography\Hash\SHAManagedTests.cs" />
|
||||
<Compile Include="Cryptography\KeyDerivation\Argon2Tests.cs" />
|
||||
<Compile Include="Cryptography\Hash\Blake2bTests.cs" />
|
||||
<Compile Include="Cryptography\Cipher\Chacha20Tests.cs" />
|
||||
<Compile Include="Cryptography\Hash\HmacTests.cs" />
|
||||
<Compile Include="Cryptography\Cipher\StandardAesEngineTests.cs" />
|
||||
<Compile Include="Cryptography\CryptoRandomStreamTests.cs" />
|
||||
<Compile Include="Cryptography\CryptoRandomTests.cs" />
|
||||
<Compile Include="Cryptography\HashingStreamExTests.cs" />
|
||||
<Compile Include="Cryptography\Hash\Blake2bTests.cs" />
|
||||
<Compile Include="Cryptography\Hash\HmacTests.cs" />
|
||||
<Compile Include="Cryptography\Hash\SHAManagedTests.cs" />
|
||||
<Compile Include="Cryptography\HmacOtpTests.cs" />
|
||||
<Compile Include="Cryptography\KeyDerivation\AesKdfTests.cs" />
|
||||
<Compile Include="Cryptography\KeyDerivation\Argon2Tests.cs" />
|
||||
<Compile Include="Keys\CompositeKeyTests.cs" />
|
||||
<Compile Include="Keys\KcpCustomKeyTests.cs" />
|
||||
<Compile Include="Keys\KcpKeyFileTests.cs" />
|
||||
@@ -76,7 +137,10 @@
|
||||
<Compile Include="Utility\MemUtilTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<AppxManifest Include="Package.appxmanifest">
|
||||
<SubType>Designer</SubType>
|
||||
</AppxManifest>
|
||||
<None Include="ModernKeePassLib.Test_TemporaryKey.pfx" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -85,18 +149,46 @@
|
||||
<Name>ModernKeePassLib</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
|
||||
</Target>
|
||||
<ItemGroup>
|
||||
<Reference Include="BouncyCastle.Crypto, Version=1.8.1.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Portable.BouncyCastle.1.8.1.3\lib\netstandard1.0\BouncyCastle.Crypto.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Splat, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Splat.2.0.0\lib\Portable-Win81+Wpa81\Splat.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\win8\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Validation, Version=2.4.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Validation.2.4.18\lib\portable-net45+win8+wp8+wpa81\Validation.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Images\UnitTestLogo.scale-100.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Images\UnitTestSmallLogo.scale-100.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Images\UnitTestSplashScreen.scale-100.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Images\UnitTestStoreLogo.scale-100.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
|
BIN
ModernKeePassLib.Test/ModernKeePassLib.Test_TemporaryKey.pfx
Normal file
BIN
ModernKeePassLib.Test/ModernKeePassLib.Test_TemporaryKey.pfx
Normal file
Binary file not shown.
56
ModernKeePassLib.Test/Package.appxmanifest
Normal file
56
ModernKeePassLib.Test/Package.appxmanifest
Normal file
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
|
||||
|
||||
<Identity Name="2aac30f7-3bad-4e17-be76-27de378756c9"
|
||||
Publisher="CN=GBE"
|
||||
Version="1.0.0.0" />
|
||||
|
||||
<Properties>
|
||||
<DisplayName>ModernKeePassLib.Test</DisplayName>
|
||||
<PublisherDisplayName>GBE</PublisherDisplayName>
|
||||
<Logo>Images\UnitTestStoreLogo.png</Logo>
|
||||
<Description>ModernKeePassLib.Test</Description>
|
||||
</Properties>
|
||||
|
||||
<Prerequisites>
|
||||
<OSMinVersion>6.3.0</OSMinVersion>
|
||||
<OSMaxVersionTested>6.3.0</OSMaxVersionTested>
|
||||
</Prerequisites>
|
||||
|
||||
<Resources>
|
||||
<Resource Language="x-generate"/>
|
||||
</Resources>
|
||||
|
||||
<Applications>
|
||||
<Application Id="vstest.executionengine.App"
|
||||
Executable="vstest.executionengine.appcontainer.exe"
|
||||
EntryPoint="vstest.executionengine.App">
|
||||
<VisualElements
|
||||
DisplayName="NoUIEntryPoints"
|
||||
Logo="Images\UnitTestLogo.png"
|
||||
SmallLogo="Images\UnitTestSmallLogo.png"
|
||||
Description="vstest.executionengine.App"
|
||||
ForegroundText="light"
|
||||
BackgroundColor="#0084FF">
|
||||
<SplashScreen Image="Images\UnitTestSplashScreen.png" />
|
||||
</VisualElements>
|
||||
</Application>
|
||||
|
||||
<Application Id="vstest.executionengine.x86.App"
|
||||
Executable="vstest.executionengine.appcontainer.x86.exe"
|
||||
EntryPoint="vstest.executionengine.x86.App">
|
||||
<VisualElements
|
||||
DisplayName="NoUIEntryPoints"
|
||||
Logo="Images\UnitTestLogo.png"
|
||||
SmallLogo="Images\UnitTestSmallLogo.png"
|
||||
Description="vstest.executionengine.x86.App"
|
||||
ForegroundText="light"
|
||||
BackgroundColor="#0084FF">
|
||||
<SplashScreen Image="Images\UnitTestSplashScreen.png" />
|
||||
</VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
<Capabilities>
|
||||
<Capability Name="internetClient" />
|
||||
</Capabilities>
|
||||
</Package>
|
@@ -10,18 +10,10 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ModernKeePassLib.Test")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("067456c0-086c-46a8-b37f-1405717b7bfc")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
|
@@ -1,71 +1,73 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
#if KeePassLib
|
||||
using KeePassLib.Serialization;
|
||||
#else
|
||||
using System.IO;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Serialization;
|
||||
#endif
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Test.Serialization
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class HashedBlockStreamTests
|
||||
{
|
||||
static readonly byte[] data = new byte[16];
|
||||
|
||||
static readonly byte[] hashStreamData = new byte[] {
|
||||
// The first 4 bytes are an integer indicating the block index
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
// Then the SHA-256 hash of the data
|
||||
0x37, 0x47, 0x08, 0xFF, 0xF7, 0x71, 0x9D, 0xD5,
|
||||
0x97, 0x9E, 0xC8, 0x75, 0xD5, 0x6C, 0xD2, 0x28,
|
||||
0x6F, 0x6D, 0x3C, 0xF7, 0xEC, 0x31, 0x7A, 0x3B,
|
||||
0x25, 0x63, 0x2A, 0xAB, 0x28, 0xEC, 0x37, 0xBB,
|
||||
// then an integer that is the length of the data
|
||||
0x10, 0x00, 0x00, 0x00,
|
||||
// and finally the data itself
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// Next, a terminating block
|
||||
0x01, 0x00, 0x00, 0x00,
|
||||
// terminating block is indicated by a hash of all 0s...
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// ...and by a size of 0
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
[Test ()]
|
||||
public void TestRead ()
|
||||
[TestClass()]
|
||||
public class HashedBlockStreamTests
|
||||
{
|
||||
using (var ms = new MemoryStream (hashStreamData)) {
|
||||
using (var hbs = new HashedBlockStream (ms, false)) {
|
||||
using (var br = new BinaryReader(hbs)) {
|
||||
var bytes = br.ReadBytes (data.Length);
|
||||
Assert.That (bytes, Is.EqualTo (data));
|
||||
Assert.That (() => br.ReadByte (), Throws.InstanceOf<EndOfStreamException> ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
static readonly byte[] data = new byte[16];
|
||||
|
||||
[Test ()]
|
||||
public void TestWrite ()
|
||||
{
|
||||
var buffer = new byte[hashStreamData.Length];
|
||||
using (var ms = new MemoryStream (buffer)) {
|
||||
using (var hbs = new HashedBlockStream (ms, true)) {
|
||||
using (var bw = new BinaryWriter(hbs)) {
|
||||
bw.Write (data);
|
||||
}
|
||||
static readonly byte[] hashStreamData = new byte[]
|
||||
{
|
||||
// The first 4 bytes are an integer indicating the block index
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
// Then the SHA-256 hash of the data
|
||||
0x37, 0x47, 0x08, 0xFF, 0xF7, 0x71, 0x9D, 0xD5,
|
||||
0x97, 0x9E, 0xC8, 0x75, 0xD5, 0x6C, 0xD2, 0x28,
|
||||
0x6F, 0x6D, 0x3C, 0xF7, 0xEC, 0x31, 0x7A, 0x3B,
|
||||
0x25, 0x63, 0x2A, 0xAB, 0x28, 0xEC, 0x37, 0xBB,
|
||||
// then an integer that is the length of the data
|
||||
0x10, 0x00, 0x00, 0x00,
|
||||
// and finally the data itself
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// Next, a terminating block
|
||||
0x01, 0x00, 0x00, 0x00,
|
||||
// terminating block is indicated by a hash of all 0s...
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
// ...and by a size of 0
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
[TestMethod]
|
||||
public void TestRead()
|
||||
{
|
||||
using (var ms = new MemoryStream(hashStreamData))
|
||||
{
|
||||
using (var hbs = new HashedBlockStream(ms, false))
|
||||
{
|
||||
using (var br = new BinaryReader(hbs))
|
||||
{
|
||||
var bytes = br.ReadBytes(data.Length);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(bytes, data));
|
||||
Assert.ThrowsException<EndOfStreamException>(() => br.ReadByte());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestWrite()
|
||||
{
|
||||
var buffer = new byte[hashStreamData.Length];
|
||||
using (var ms = new MemoryStream(buffer))
|
||||
{
|
||||
using (var hbs = new HashedBlockStream(ms, true))
|
||||
{
|
||||
using (var bw = new BinaryWriter(hbs))
|
||||
{
|
||||
bw.Write(data);
|
||||
}
|
||||
}
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(buffer, hashStreamData));
|
||||
}
|
||||
}
|
||||
Assert.That (buffer, Is.EqualTo (hashStreamData));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Keys;
|
||||
using ModernKeePassLib.Security;
|
||||
using ModernKeePassLib.Serialization;
|
||||
@@ -10,7 +10,7 @@ using ModernKeePassLib.Collections;
|
||||
|
||||
namespace ModernKeePassLib.Test.Serialization
|
||||
{
|
||||
[TestFixture()]
|
||||
[TestClass()]
|
||||
public class KdbxFileTests
|
||||
{
|
||||
const string TestLocalizedAppName = "My Localized App Name";
|
||||
@@ -86,7 +86,7 @@ namespace ModernKeePassLib.Test.Serialization
|
||||
|
||||
const string TestDate = "2017-10-23T08:03:55Z";
|
||||
|
||||
[Test()]
|
||||
[TestMethod]
|
||||
public void TestLoad()
|
||||
{
|
||||
var database = new PwDatabase();
|
||||
@@ -96,12 +96,12 @@ namespace ModernKeePassLib.Test.Serialization
|
||||
file.Load(ms, KdbxFormat.PlainXml, null);
|
||||
}
|
||||
//Assert.That(database.Color.ToArgb(), Is.EqualTo(Color.Red.ToArgb()));
|
||||
Assert.That(database.Compression, Is.EqualTo(PwCompressionAlgorithm.GZip));
|
||||
Assert.AreEqual(database.Compression, PwCompressionAlgorithm.GZip);
|
||||
//Assert.That (database.CustomData, Is.EqualTo ());
|
||||
Assert.That(database.CustomIcons, Is.Empty);
|
||||
Assert.IsTrue(database.CustomIcons.Count == 0);
|
||||
}
|
||||
|
||||
[Test()]
|
||||
[TestMethod]
|
||||
public void TestSave()
|
||||
{
|
||||
var buffer = new byte[4096];
|
||||
@@ -134,18 +134,17 @@ namespace ModernKeePassLib.Test.Serialization
|
||||
var file = new KdbxFile(database);
|
||||
file.Save(ms, null, KdbxFormat.PlainXml, null);
|
||||
}
|
||||
var fileContents = Encoding.UTF8.GetString(buffer).Replace("\0", "");
|
||||
if (typeof(KdbxFile).Namespace.StartsWith("KeePassLib.")
|
||||
&& Environment.OSVersion.Platform != PlatformID.Win32NT)
|
||||
var fileContents = Encoding.UTF8.GetString(buffer, 0, buffer.Length).Replace("\0", "");
|
||||
if (typeof(KdbxFile).Namespace.StartsWith("KeePassLib."))
|
||||
{
|
||||
// Upstream KeePassLib does not specify line endings for XmlTextWriter,
|
||||
// so it uses native line endings.
|
||||
fileContents = fileContents.Replace("\n", "\r\n");
|
||||
}
|
||||
Assert.That(fileContents, Is.EqualTo(TestDatabase));
|
||||
Assert.AreEqual(fileContents, TestDatabase);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestMethod]
|
||||
public void TestSearch()
|
||||
{
|
||||
var database = new PwDatabase();
|
||||
|
@@ -1,16 +1,10 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
#if KeePassLib
|
||||
using KeePassLib.Utility;
|
||||
#else
|
||||
using Splat;
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Utility;
|
||||
#endif
|
||||
|
||||
namespace ModernKeePassLib.Test.Utility
|
||||
{
|
||||
[TestFixture ()]
|
||||
[TestClass ()]
|
||||
public class GfxUtilTests
|
||||
{
|
||||
// 16x16 all white PNG file, base64 encoded
|
||||
@@ -20,14 +14,14 @@ namespace ModernKeePassLib.Test.Utility
|
||||
"VkIHdpdGggR0lNUFeBDhcAAAAaSURBVCjPY/z//z8DKYCJgUQwqmFUw9DRAABVb" +
|
||||
"QMdny4VogAAAABJRU5ErkJggg==";
|
||||
|
||||
[Test ()]
|
||||
[TestMethod]
|
||||
public void TestLoadImage ()
|
||||
{
|
||||
var testData = Convert.FromBase64String (testImageData);
|
||||
var image = GfxUtil.ScaleImage(testData, 16, 16).GetAwaiter().GetResult();
|
||||
//var image = GfxUtil.LoadImage(testData);
|
||||
Assert.That (image.Width, Is.EqualTo (16));
|
||||
Assert.That (image.Height, Is.EqualTo (16));
|
||||
Assert.AreEqual(image.Width, 16);
|
||||
Assert.AreEqual(image.Height, 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,89 +1,89 @@
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Utility;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Utility
|
||||
{
|
||||
[TestFixture]
|
||||
[TestClass]
|
||||
public class MemUtilTests
|
||||
{
|
||||
private byte[] _pb = CryptoRandom.Instance.GetRandomBytes((uint)CryptoRandom.NewWeakRandom().Next(0, 0x2FFFF));
|
||||
|
||||
[Test]
|
||||
[TestMethod]
|
||||
public void TestGzip()
|
||||
{
|
||||
var pbCompressed = MemUtil.Compress(_pb);
|
||||
Assert.That(MemUtil.ArraysEqual(MemUtil.Decompress(pbCompressed), _pb), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(MemUtil.Decompress(pbCompressed), _pb));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestMethod]
|
||||
public void TestMemUtil()
|
||||
{
|
||||
Encoding enc = StrUtil.Utf8;
|
||||
_pb = enc.GetBytes("012345678901234567890a");
|
||||
byte[] pbN = enc.GetBytes("9012");
|
||||
Assert.That(MemUtil.IndexOf(_pb, pbN), Is.EqualTo(9));
|
||||
Assert.AreEqual(MemUtil.IndexOf(_pb, pbN), 9);
|
||||
|
||||
pbN = enc.GetBytes("01234567890123");
|
||||
Assert.That(MemUtil.IndexOf(_pb, pbN), Is.EqualTo(0));
|
||||
Assert.AreEqual(MemUtil.IndexOf(_pb, pbN), 0);
|
||||
|
||||
pbN = enc.GetBytes("a");
|
||||
Assert.That(MemUtil.IndexOf(_pb, pbN), Is.EqualTo(21));
|
||||
Assert.AreEqual(MemUtil.IndexOf(_pb, pbN), 21);
|
||||
|
||||
pbN = enc.GetBytes("0a");
|
||||
Assert.That(MemUtil.IndexOf(_pb, pbN), Is.EqualTo(20));
|
||||
Assert.AreEqual(MemUtil.IndexOf(_pb, pbN), 20);
|
||||
|
||||
pbN = enc.GetBytes("1");
|
||||
Assert.That(MemUtil.IndexOf(_pb, pbN), Is.EqualTo(1));
|
||||
Assert.AreEqual(MemUtil.IndexOf(_pb, pbN), 1);
|
||||
|
||||
pbN = enc.GetBytes("b");
|
||||
Assert.That(MemUtil.IndexOf(_pb, pbN), Is.LessThan(0));
|
||||
Assert.IsTrue(MemUtil.IndexOf(_pb, pbN) < 0);
|
||||
|
||||
pbN = enc.GetBytes("012b");
|
||||
Assert.That(MemUtil.IndexOf(_pb, pbN), Is.LessThan(0));
|
||||
Assert.IsTrue(MemUtil.IndexOf(_pb, pbN) < 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestMethod]
|
||||
public void TestBase32()
|
||||
{
|
||||
byte[] pbRes = MemUtil.ParseBase32("MY======");
|
||||
byte[] pbExp = Encoding.UTF8.GetBytes("f");
|
||||
Assert.That(MemUtil.ArraysEqual(pbRes, pbExp), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pbRes, pbExp));
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXQ====");
|
||||
pbExp = Encoding.UTF8.GetBytes("fo");
|
||||
Assert.That(MemUtil.ArraysEqual(pbRes, pbExp), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pbRes, pbExp));
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6===");
|
||||
pbExp = Encoding.UTF8.GetBytes("foo");
|
||||
Assert.That(MemUtil.ArraysEqual(pbRes, pbExp), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pbRes, pbExp));
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YQ=");
|
||||
pbExp = Encoding.UTF8.GetBytes("foob");
|
||||
Assert.That(MemUtil.ArraysEqual(pbRes, pbExp), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pbRes, pbExp));
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YTB");
|
||||
pbExp = Encoding.UTF8.GetBytes("fooba");
|
||||
Assert.That(MemUtil.ArraysEqual(pbRes, pbExp), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pbRes, pbExp));
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YTBOI======");
|
||||
pbExp = Encoding.UTF8.GetBytes("foobar");
|
||||
Assert.That(MemUtil.ArraysEqual(pbRes, pbExp), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pbRes, pbExp));
|
||||
|
||||
pbRes = MemUtil.ParseBase32("JNSXSIDQOJXXM2LEMVZCAYTBONSWIIDPNYQG63TFFV2GS3LFEBYGC43TO5XXEZDTFY======");
|
||||
pbExp = Encoding.UTF8.GetBytes("Key provider based on one-time passwords.");
|
||||
Assert.That(MemUtil.ArraysEqual(pbRes, pbExp), Is.True);
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pbRes, pbExp));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestMethod]
|
||||
public void TestMemUtil2()
|
||||
{
|
||||
var i = 0 - 0x10203040;
|
||||
var pbRes = MemUtil.Int32ToBytes(i);
|
||||
Assert.That(MemUtil.ByteArrayToHexString(pbRes), Is.EqualTo("C0CFDFEF"));
|
||||
Assert.That(MemUtil.BytesToUInt32(pbRes), Is.EqualTo((uint)i));
|
||||
Assert.That(MemUtil.BytesToInt32(pbRes), Is.EqualTo(i));
|
||||
Assert.AreEqual(MemUtil.ByteArrayToHexString(pbRes), "C0CFDFEF");
|
||||
Assert.AreEqual(MemUtil.BytesToUInt32(pbRes), (uint)i);
|
||||
Assert.AreEqual(MemUtil.BytesToInt32(pbRes), i);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="PInvoke.BCrypt" publicKeyToken="9e300f9f87f04a7a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-0.5.0.0" newVersion="0.5.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="PInvoke.NCrypt" publicKeyToken="9e300f9f87f04a7a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-0.5.0.0" newVersion="0.5.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Validation" publicKeyToken="2fc06f0d701809a7" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.4.0.0" newVersion="2.4.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.WindowsRuntime" publicKeyToken="b77a5c561934e089" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/></startup></configuration>
|
@@ -1,6 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net462" />
|
||||
<package id="NUnit" version="3.8.1" targetFramework="net452" />
|
||||
<package id="Splat" version="2.0.0" targetFramework="net462" />
|
||||
<package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="win81" />
|
||||
<package id="NETStandard.Library" version="1.6.1" targetFramework="win81" />
|
||||
<package id="Portable.BouncyCastle" version="1.8.1.3" targetFramework="win81" />
|
||||
<package id="Splat" version="2.0.0" targetFramework="win81" />
|
||||
<package id="System.Collections" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Globalization" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.IO" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.IO.Compression" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Linq" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Linq.Expressions" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Net.Http" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Net.Primitives" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.ObjectModel" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Reflection" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Reflection.Extensions" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Reflection.Primitives" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Runtime" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Runtime.Extensions" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Runtime.Numerics" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Runtime.WindowsRuntime" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Text.Encoding" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Threading" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Threading.Timer" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="win81" />
|
||||
<package id="Validation" version="2.4.18" targetFramework="win81" />
|
||||
</packages>
|
Reference in New Issue
Block a user