Beispiel #1
0
        public void TestSaltCopy()
        {
            Salt s = new Salt();

            byte[] bytes = new byte[s.Length];
            s.CopyTo(bytes, 0);
            Assert.AreEqual(s.ToArray(), bytes);
            Assert.AreEqual(s.GetHashCode(), Salt.FromBytes(bytes).GetHashCode());

            Salt strcpy = Salt.FromString(s.ToString());

            Assert.AreEqual(s.ToArray(), strcpy.ToArray());
            Assert.AreEqual(s.ToString(), strcpy.ToString());
            Assert.AreEqual(s.GetHashCode(), strcpy.GetHashCode());
        }
Beispiel #2
0
        public void TestSaltFromBytes()
        {
            byte[] testValid = Encoding.ASCII.GetBytes("12345678");
            Assert.AreEqual(Salt.Size.b64, Salt.FromBytes(testValid).BitSize);
            Assert.AreEqual(testValid, Salt.FromBytes(testValid).ToArray());
            testValid = null;

            //now test with an odd number of bytes, should always hash to Sha256
            byte[] notValid = Encoding.ASCII.GetBytes("0123456789");
            Assert.AreNotEqual(Salt.Size.b64, Salt.FromBytes(notValid).BitSize);
            Assert.AreNotEqual(testValid, Salt.FromBytes(notValid).ToArray());

            Assert.AreEqual(Salt.Size.b256, Salt.FromBytes(notValid).BitSize);
            Assert.AreEqual(Hash.SHA256(notValid).ToArray(), Salt.FromBytes(notValid).ToArray());
        }
Beispiel #3
0
        public void TestEquality()
        {
            Salt s     = new Salt();
            Salt scopy = Salt.FromBytes(s.ToArray());

            Assert.AreEqual(s, scopy);
            Assert.IsTrue(s.Equals(scopy));
            Assert.IsTrue(s.Equals((object)scopy));
            Assert.IsTrue(s == scopy);
            Assert.IsFalse(s != scopy);
            Assert.AreEqual(s.GetHashCode(), scopy.GetHashCode());

            scopy = new Salt();
            Assert.AreNotEqual(s, scopy);
            Assert.IsFalse(s.Equals(scopy));
            Assert.IsFalse(s.Equals((object)scopy));
            Assert.IsFalse(s == scopy);
            Assert.IsTrue(s != scopy);
            Assert.AreNotEqual(s.GetHashCode(), scopy.GetHashCode());
        }