Example #1
0
        public void TestCompressionLowerCase()
        {
            var compress     = new CompressionOutputContext();
            var domain       = new Domain("EXAMPLE.COM");
            var domain_bytes = compress.SerializeDomain(domain);

            compress.MoveForward((UInt16)domain_bytes.Length);

            var expected = new byte[]
            {
                7, // Length of 'example'
                101,
                120,
                97,
                109,
                112,
                108,
                101,
                3, // Length of com
                99,
                111,
                109,
                0 // Length of root
            };

            Assert.That(domain_bytes, Is.EqualTo(expected));
        }
Example #2
0
        public void TestCompressionFirstUse()
        {
            var compress     = new CompressionOutputContext();
            var domain       = new Domain("example.com");
            var domain_bytes = compress.SerializeDomain(domain);

            var expected = new byte[]
            {
                7, // Length of 'example'
                101,
                120,
                97,
                109,
                112,
                108,
                101,
                3, // Length of com
                99,
                111,
                109,
                0 // Length of root
            };

            Assert.That(domain_bytes, Is.EqualTo(expected));
        }
Example #3
0
        public Tuple <MemoryStream, DNSOutputStream> DNSOutput()
        {
            var compress = new CompressionOutputContext();
            var memory   = new MemoryStream();
            var stream   = new DNSOutputStream(memory, compress);

            return(Tuple.Create(memory, stream));
        }
Example #4
0
        /**
         * A convenience wrapper around Serialize.
         */
        public byte[] ToBytes()
        {
            var buffer_stream = new MemoryStream();
            var compress      = new CompressionOutputContext();
            var dns_out       = new DNSOutputStream(buffer_stream, compress);

            Serialize(dns_out);
            return(buffer_stream.ToArray());
        }
Example #5
0
        public void TestCompressionMultipleUses()
        {
            var compress      = new CompressionOutputContext();
            var domain_stream = new MemoryStream();

            var domain       = new Domain("example.com");
            var domain_bytes = compress.SerializeDomain(domain);

            domain_stream.Write(domain_bytes, 0, domain_bytes.Length);

            domain       = new Domain("hostmaster.example.com");
            domain_bytes = compress.SerializeDomain(domain);
            domain_stream.Write(domain_bytes, 0, domain_bytes.Length);

            var expected = new byte[]
            {
                7, // Length of 'example'
                101,
                120,
                97,
                109,
                112,
                108,
                101,
                3, // Length of com
                99,
                111,
                109,
                0,  // Length of root
                10, // Length of hostmaster
                104,
                111,
                115,
                116,
                109,
                97,
                115,
                116,
                101,
                114,
                // Two bytes worth of pointer - they should have 1 at the 15th
                // bit and the 14th bit on the MSB, and the LSB should be 0
                // (since that is the offset of the start of the example.com
                // domain
                192,
                0
            };

            Assert.That(domain_stream.ToArray(), Is.EqualTo(expected));
        }
Example #6
0
 public DNSOutputStream(Stream stream, CompressionOutputContext compress)
 {
     this.stream   = stream;
     this.compress = compress;
 }