Ejemplo n.º 1
0
        public void ChecksummRoundtip()
        {
            var b = new byte[255];
            var r = new Random();

            r.NextBytes(b);

            var c = new Checksum();

            b[254] = 0;
            c.CalcAndApply(b);

            Assert.IsTrue(c.Check(b, 0, b.Length));
        }
Ejemplo n.º 2
0
        public JobTypeResult GetJob()
        {
            Assembly jobAssembly = null;

            using (WebClient wc = new WebClient()
            {
                BaseAddress = this.BaseAddress
            })
            {
                byte[] binary   = wc.DownloadData(string.Format("{0}/job", MatchersPath));
                string checksum = wc.ResponseHeaders["X-Matcher-Job-Checksum"];
                logger.Debug("Downloaded matcher job binary with checksum: {0}", checksum);

                if (!Checksum.Check(checksum, binary))
                {
                    throw new InvalidJobException("Checksum is different.");
                }

                jobAssembly = Assembly.Load(binary);
                logger.Info("Successfully loaded job assembly into domain.");
            }

            return(new JobTypeResult(jobAssembly));
        }
Ejemplo n.º 3
0
        public void ChecksummDoubleApply()
        {
            var b = new Byte[] { 1, 2, 3, 4, 5 };

            var c = new Checksum();

            try
            {
                c.CalcAndApply(b);
                Assert.Fail("Error expected");
            } catch (ArgumentException) { }

            b[4] = 0;
            c.CalcAndApply(b);
            Assert.AreEqual(246, b[4]);

            try
            {
                c.CalcAndApply(b);
                Assert.Fail("Error expected");
            } catch (ArgumentException) { }

            Assert.IsTrue(c.Check(b, 0, b.Length));
        }