Esempio n. 1
0
        public void VerifyNullArray2()
        {
            Md5Sum sum = new Md5Sum();

            Assert.IsNotNull(sum);

            bool match = sum.Verify(new byte[1], (byte[])null);
        }
Esempio n. 2
0
        public void CalculateBytesFromNull()
        {
            Md5Sum sum = new Md5Sum();

            Assert.IsNotNull(sum);

            byte[] check = sum.Calculate((byte[])null);
        }
Esempio n. 3
0
        public void VerifyFromTestFile1()
        {
            Md5Sum sum = new Md5Sum();

            Assert.IsNotNull(sum);

            byte[] array = File.ReadAllBytes("../../TestData/TextFile1.txt");
            bool   match = sum.Verify(array, File1Sum);

            Assert.IsTrue(match);
        }
Esempio n. 4
0
        public void CalculateBytesFromEmpty()
        {
            Md5Sum sum = new Md5Sum();

            Assert.IsNotNull(sum);

            byte[] data  = new byte[0];
            byte[] check = sum.Calculate(data);
            Assert.IsNotNull(check);
            Assert.AreEqual(16, check.Length);
        }
Esempio n. 5
0
        public void VerifyFromTestFile1Stream()
        {
            Md5Sum sum = new Md5Sum();

            Assert.IsNotNull(sum);

            FileStream file = new FileStream("../../TestData/TextFile1.txt",
                                             FileMode.Open);
            bool match = sum.Verify(file, File1Sum);

            file.Close();
            Assert.IsTrue(match);
        }
Esempio n. 6
0
        public void VerifyFromTestFile1Fail()
        {
            Md5Sum sum = new Md5Sum();

            Assert.IsNotNull(sum);

            // Create invalid checksum
            byte[] invalidSum = new byte[16];
            Array.Copy(File1Sum, invalidSum, 16);
            invalidSum[3] = 0x00;

            byte[] array = File.ReadAllBytes("../../TestData/TextFile1.txt");
            bool   match = sum.Verify(array, invalidSum);

            Assert.IsFalse(match);
        }
Esempio n. 7
0
        public void VerifyFromTestFile1StreamFail()
        {
            Md5Sum sum = new Md5Sum();

            Assert.IsNotNull(sum);

            // Create invalid checksum
            byte[] invalidSum = new byte[16];
            Array.Copy(File1Sum, invalidSum, 16);
            invalidSum[3] = 0x00;

            FileStream file = new FileStream("../../TestData/TextFile1.txt",
                                             FileMode.Open);
            bool match = sum.Verify(file, invalidSum);

            file.Close();
            Assert.IsFalse(match);
        }
Esempio n. 8
0
        public void CalculateFromTestFile1()
        {
            Md5Sum sum = new Md5Sum();

            Assert.IsNotNull(sum);

            byte[] array = File.ReadAllBytes("../../TestData/TextFile1.txt");
            byte[] check = sum.Calculate(array);

            Assert.IsNotNull(check);
            Assert.AreEqual(16, check.Length);
            for (int i = 0; i < File1Sum.Length; i++)
            {
                if (check[i] != File1Sum[i])
                {
                    Assert.Fail("Result byte {0} does not match! Was {1}, expected {2}",
                                i, check[i], File1Sum[i]);
                }
            }
        }
Esempio n. 9
0
        public void CalculateFromTestFile1Stream()
        {
            Md5Sum sum = new Md5Sum();

            Assert.IsNotNull(sum);

            FileStream file = new FileStream("../../TestData/TextFile1.txt",
                                             FileMode.Open);

            byte[] check = sum.Calculate(file);
            file.Close();

            Assert.IsNotNull(check);
            Assert.AreEqual(16, check.Length);
            for (int i = 0; i < File1Sum.Length; i++)
            {
                if (check[i] != File1Sum[i])
                {
                    Assert.Fail("Result byte {0} does not match! Was {1}, expected {2}",
                                i, check[i], File1Sum[i]);
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Get checksum calculator for given checksum type.
        /// </summary>
        /// <param name="impl">Checksum type.</param>
        /// <returns>Checksum calculator.</returns>
        public static ICheckSum GetImplementation(CheckSumType impl)
        {
            ICheckSum sum;

            switch (impl)
            {
            case CheckSumType.SHA1:
                sum = new Sha1Sum();
                break;

            case CheckSumType.MD5:
                sum = new Md5Sum();
                break;

            case CheckSumType.CRC32:
                sum = new CRC32Sum();
                break;

            case CheckSumType.CRC64_ECMA:
                sum = new CRC64ECMASum();
                break;

            case CheckSumType.CRC64_ISO:
                sum = new CRC64ISOSum();
                break;

            default:
                sum = new Sha1Sum();
#if DEBUG
                throw new ApplicationException("Unknown Sum type!");
#else
                break;
#endif
            }

            return(sum);
        }
Esempio n. 11
0
 /// <summary>
 /// Get checksum calculator for given checksum type.
 /// </summary>
 /// <param name="impl">Checksum type.</param>
 /// <returns>Checksum calculator.</returns>
 public static ICheckSum GetImplementation(CheckSumType impl)
 {
     ICheckSum sum;
     switch (impl)
     {
         case CheckSumType.SHA1:
             sum = new Sha1Sum();
             break;
         case CheckSumType.MD5:
             sum = new Md5Sum();
             break;
         case CheckSumType.CRC32:
             sum = new CRC32Sum();
             break;
         default:
             sum = new Sha1Sum();
     #if DEBUG
             throw new ApplicationException("Unknown Sum type!");
     #else
             break;
     #endif
     }
     return sum;
 }
Esempio n. 12
0
        public void VerifyFromTestFile1Stream()
        {
            Md5Sum sum = new Md5Sum();
            Assert.IsNotNull(sum);

            FileStream file = new FileStream("../../TestData/TextFile1.txt",
                FileMode.Open);
            bool match = sum.Verify(file, File1Sum);
            file.Close();
            Assert.IsTrue(match);
        }
Esempio n. 13
0
        public void VerifyFromTestFile1StreamFail()
        {
            Md5Sum sum = new Md5Sum();
            Assert.IsNotNull(sum);

            // Create invalid checksum
            byte[] invalidSum = new byte[16];
            Array.Copy(File1Sum, invalidSum, 16);
            invalidSum[3] = 0x00;

            FileStream file = new FileStream("../../TestData/TextFile1.txt",
                FileMode.Open);
            bool match = sum.Verify(file, invalidSum);
            file.Close();
            Assert.IsFalse(match);
        }
Esempio n. 14
0
        public void VerifyFromTestFile1()
        {
            Md5Sum sum = new Md5Sum();
            Assert.IsNotNull(sum);

            byte[] array = File.ReadAllBytes("../../TestData/TextFile1.txt");
            bool match = sum.Verify(array, File1Sum);
            Assert.IsTrue(match);
        }
Esempio n. 15
0
        public void VerifyFromTestFile1Fail()
        {
            Md5Sum sum = new Md5Sum();
            Assert.IsNotNull(sum);

            // Create invalid checksum
            byte[] invalidSum = new byte[16];
            Array.Copy(File1Sum, invalidSum, 16);
            invalidSum[3] = 0x00;

            byte[] array = File.ReadAllBytes("../../TestData/TextFile1.txt");
            bool match = sum.Verify(array, invalidSum);
            Assert.IsFalse(match);
        }
Esempio n. 16
0
 public void Create()
 {
     Md5Sum sum = new Md5Sum();
     Assert.IsNotNull(sum);
 }
Esempio n. 17
0
        public void CalculateFromTestFile1Stream()
        {
            Md5Sum sum = new Md5Sum();
            Assert.IsNotNull(sum);

            FileStream file = new FileStream("../../TestData/TextFile1.txt",
                FileMode.Open);
            byte[] check = sum.Calculate(file);
            file.Close();

            Assert.IsNotNull(check);
            Assert.AreEqual(16, check.Length);
            for (int i = 0; i < File1Sum.Length; i++)
            {
                if (check[i] != File1Sum[i])
                {
                    Assert.Fail("Result byte {0} does not match! Was {1}, expected {2}",
                        i, check[i], File1Sum[i]);
                }
            }
        }
Esempio n. 18
0
        public void CalculateFromTestFile1()
        {
            Md5Sum sum = new Md5Sum();
            Assert.IsNotNull(sum);

            byte[] array = File.ReadAllBytes("../../TestData/TextFile1.txt");
            byte[] check = sum.Calculate(array);

            Assert.IsNotNull(check);
            Assert.AreEqual(16, check.Length);
            for (int i = 0; i < File1Sum.Length; i++)
            {
                if (check[i] != File1Sum[i])
                {
                    Assert.Fail("Result byte {0} does not match! Was {1}, expected {2}",
                        i, check[i], File1Sum[i]);
                }
            }
        }
Esempio n. 19
0
        public void CalculateBytesFromNull()
        {
            Md5Sum sum = new Md5Sum();
            Assert.IsNotNull(sum);

            byte[] check = sum.Calculate((byte[])null);
        }
Esempio n. 20
0
        public void VerifyNullArray2()
        {
            Md5Sum sum = new Md5Sum();
            Assert.IsNotNull(sum);

            bool match = sum.Verify(new byte[1], (byte[])null);
        }
Esempio n. 21
0
        public void CalculateBytesFromEmpty()
        {
            Md5Sum sum = new Md5Sum();
            Assert.IsNotNull(sum);

            byte[] data = new byte[0];
            byte[] check = sum.Calculate(data);
            Assert.IsNotNull(check);
            Assert.AreEqual(16, check.Length);
        }
Esempio n. 22
0
        public void Create()
        {
            Md5Sum sum = new Md5Sum();

            Assert.IsNotNull(sum);
        }