Beispiel #1
0
        public void benDictionaryEncoding()
        {
            byte[] data = System.Text.Encoding.UTF8.GetBytes("d4:spaml1:a1:bee");

            BEncodedDictionary dict = new BEncodedDictionary();
            BEncodedList       list = new BEncodedList();

            list.Add(new BEncodedString("a"));
            list.Add(new BEncodedString("b"));
            dict.Add("spam", list);
            Assert.AreEqual(System.Text.Encoding.UTF8.GetString(data), System.Text.Encoding.UTF8.GetString(dict.Encode()));
            Assert.IsTrue(Toolbox.ByteMatch(data, dict.Encode()));
        }
Beispiel #2
0
        public void benDictionaryEncodingBuffered()
        {
            byte[] data = Encoding.UTF8.GetBytes("d4:spaml1:a1:bee");
            var    dict = new BEncodedDictionary();
            var    list = new BEncodedList {
                new BEncodedString("a"),
                new BEncodedString("b")
            };

            dict.Add("spam", list);
            byte[] result = new byte[dict.LengthInBytes()];
            dict.Encode(result, 0);
            Assert.IsTrue(Toolbox.ByteMatch(data, result));
        }
Beispiel #3
0
        public void benDictionaryEncoding()
        {
            byte[] data = Encoding.UTF8.GetBytes("d4:spaml1:a1:bee");

            var dict = new BEncodedDictionary();
            var list = new BEncodedList {
                new BEncodedString("a"),
                new BEncodedString("b")
            };

            dict.Add("spam", list);
            Assert.AreEqual(Encoding.UTF8.GetString(data), Encoding.UTF8.GetString(dict.Encode()));
            Assert.IsTrue(Toolbox.ByteMatch(data, dict.Encode()));
        }
Beispiel #4
0
 public void SHA1()
 {
     Assert.IsTrue(Toolbox.ByteMatch(torrent.SHA1, sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("this is a sha1 hash string"))));
 }
Beispiel #5
0
 public void ED2K()
 {
     Assert.IsTrue(Toolbox.ByteMatch(torrent.ED2K, sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("ed2k isn't a sha, but who cares"))));
 }
Beispiel #6
0
 public bool Equals(byte[] other)
 {
     return(other == null || other.Length != InfoHash.HASH_SIZE ? false : Toolbox.ByteMatch(Hash, other));
 }
Beispiel #7
0
 public void ByteMatch_DifferentArrayLengths2()
 {
     Assert.IsFalse(Toolbox.ByteMatch(new byte[1], 0, new byte[2], 0, 2));
     Assert.IsTrue(Toolbox.ByteMatch(new byte[1], 0, new byte[2], 0, 1));
 }
Beispiel #8
0
 public void ByteMatch_DifferentArrayLengths()
 {
     Assert.IsFalse(Toolbox.ByteMatch(new byte[1], new byte[2]));
 }