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

            Assert.IsNotNull(sum);

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

            Assert.IsNotNull(sum);

            byte[] check = sum.Calculate((byte[])null);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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]);
                }
            }
        }
Ejemplo 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]);
                }
            }
        }
Ejemplo 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);
        }
Ejemplo 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;
 }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo n.º 16
0
 public void Create()
 {
     Md5Sum sum = new Md5Sum();
     Assert.IsNotNull(sum);
 }
Ejemplo 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]);
                }
            }
        }
Ejemplo 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]);
                }
            }
        }
Ejemplo n.º 19
0
        public void CalculateBytesFromNull()
        {
            Md5Sum sum = new Md5Sum();
            Assert.IsNotNull(sum);

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

            bool match = sum.Verify(new byte[1], (byte[])null);
        }
Ejemplo 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);
        }
Ejemplo n.º 22
0
        public void Create()
        {
            Md5Sum sum = new Md5Sum();

            Assert.IsNotNull(sum);
        }