예제 #1
0
        public void VerifyNullArray2()
        {
            Md5Sum sum = new Md5Sum();

            Assert.IsNotNull(sum);

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

            Assert.IsNotNull(sum);

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

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

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

            Assert.IsNotNull(sum);
        }