示例#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()));
        }
示例#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));
        }
示例#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()));
        }
示例#4
0
 public void SHA1()
 {
     Assert.IsTrue(Toolbox.ByteMatch(torrent.SHA1, sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("this is a sha1 hash string"))));
 }
示例#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"))));
 }
示例#6
0
 public bool Equals(byte[] other)
 {
     return(other == null || other.Length != InfoHash.HASH_SIZE ? false : Toolbox.ByteMatch(Hash, other));
 }
示例#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));
 }
示例#8
0
 public void ByteMatch_DifferentArrayLengths()
 {
     Assert.IsFalse(Toolbox.ByteMatch(new byte[1], new byte[2]));
 }