Ejemplo n.º 1
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.º 2
0
 public void VerifyNullSumData()
 {
     byte[] fileArray = File.ReadAllBytes("../../TestData/TextFile1.txt");
     CRC32Sum sum = new CRC32Sum();
     bool correct = sum.Verify(fileArray, null);
 }
Ejemplo n.º 3
0
 public void VerifyNullSumStream()
 {
     FileStream file = new FileStream("../../TestData/TextFile1.txt",
         FileMode.Open);
     CRC32Sum sum = new CRC32Sum();
     try
     {
         bool correct = sum.Verify(file, null);
     }
     catch
     {
         throw;
     }
     finally
     {
         // Make sure stream is closed.
         file.Close();
     }
 }
Ejemplo n.º 4
0
 public void VerifyNullByteData()
 {
     CRC32Sum sum = new CRC32Sum();
     bool correct = sum.Verify((byte[])null, new byte[4]);
 }
Ejemplo n.º 5
0
 public void VerifyNullStream()
 {
     CRC32Sum sum = new CRC32Sum();
     bool correct = sum.Verify((Stream)null, new byte[4]);
 }
Ejemplo n.º 6
0
 public void VerifyFile1Stream()
 {
     FileStream file = new FileStream("../../TestData/TextFile1.txt",
         FileMode.Open);
     CRC32Sum sum = new CRC32Sum();
     bool correct = sum.Verify(file, File1Sum);
     file.Close();
     Assert.IsTrue(correct);
 }
Ejemplo n.º 7
0
        public void VerifyFile1StreamFail()
        {
            FileStream file = new FileStream("../../TestData/TextFile1.txt",
                FileMode.Open);
            CRC32Sum sum = new CRC32Sum();

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

            bool correct = sum.Verify(file, invalidSum);
            file.Close();
            Assert.IsFalse(correct);
        }
Ejemplo n.º 8
0
 public void VerifyFile1ByteArray()
 {
     byte[] fileArray = File.ReadAllBytes("../../TestData/TextFile1.txt");
     CRC32Sum sum = new CRC32Sum();
     bool correct = sum.Verify(fileArray, File1Sum);
     Assert.IsTrue(correct);
 }
Ejemplo n.º 9
0
 public void CalculateNullStream()
 {
     CRC32Sum sum = new CRC32Sum();
     byte[] check = sum.Calculate((Stream)null);
 }
Ejemplo n.º 10
0
 public void CalculateNullArray()
 {
     CRC32Sum sum = new CRC32Sum();
     byte[] check = sum.Calculate((byte[])null);
 }
Ejemplo n.º 11
0
        public void CalculateFile1Stream()
        {
            FileStream file = new FileStream("../../TestData/TextFile1.txt",
                FileMode.Open);

            CRC32Sum sum = new CRC32Sum();
            byte[] check = sum.Calculate(file);
            file.Close();
            Assert.IsNotNull(check);
            Assert.AreEqual(4, 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:x2}, expected {2:x2}",
                        i, check[i], File1Sum[i]);
                }
            }
        }
Ejemplo n.º 12
0
        public void CalculateFile1ByteArray()
        {
            CRC32Sum sum = new CRC32Sum();
            byte[] array = File.ReadAllBytes("../../TestData/TextFile1.txt");
            byte[] check = sum.Calculate(array);

            Assert.IsNotNull(check);
            Assert.AreEqual(4, 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]);
                }
            }
        }