public void corruptBenNumberDecode()
        {
            var data = Encoding.UTF8.GetBytes("i35212");

            Assert.Throws <BEncodingException> (() => {
                BEncodedValue.Decode(data);
            });

            Assert.Throws <BEncodingException> (() => {
                BEncodedValue.Decode(new MemoryStream(data));
            });
        }
        public static BEncodedValue Decode(byte[] buffer, int offset, int length, bool strictDecoding)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (offset < 0 || length < 0)
            {
                throw new IndexOutOfRangeException("Neither offset or length can be less than zero");
            }

            if (offset > buffer.Length - length)
            {
                throw new ArgumentOutOfRangeException("length");
            }

            using (RawReader reader = new RawReader(new MemoryStream(buffer, offset, length), strictDecoding))
                return(BEncodedValue.Decode(reader));
        }
 public static T Clone <T> (T value)
     where T : BEncodedValue
 {
     Check.Value(value);
     return((T)BEncodedValue.Decode(value.Encode()));
 }
 public static T Decode <T>(RawReader reader) where T : BEncodedValue
 {
     return((T)BEncodedValue.Decode(reader));
 }
 /// <summary>
 /// Decode BEncoded data in the given stream
 /// </summary>
 /// <param name="stream">The stream containing the BEncoded data</param>
 /// <returns>BEncodedValue containing the data that was in the stream</returns>
 public static T Decode <T>(Stream stream) where T : BEncodedValue
 {
     return((T)BEncodedValue.Decode(stream));
 }
 public static T Decode <T>(byte[] buffer, int offset, int length, bool strictDecoding) where T : BEncodedValue
 {
     return((T)BEncodedValue.Decode(buffer, offset, length, strictDecoding));
 }
 /// <summary>
 /// Decode BEncoded data in the given byte array
 /// </summary>
 /// <param name="buffer">The byte array containing the BEncoded data</param>
 /// <param name="offset">The offset at which the data starts at</param>
 /// <param name="length">The number of bytes to be decoded</param>
 /// <returns>BEncodedValue containing the data that was in the byte[]</returns>
 public static T Decode <T>(byte[] buffer, int offset, int length) where T : BEncodedValue
 {
     return(BEncodedValue.Decode <T>(buffer, offset, length, true));
 }
 /// <summary>
 /// Interface for all BEncoded values
 /// </summary>
 /// <param name="data">The byte array containing the BEncoded data</param>
 /// <returns></returns>
 public static T Decode <T>(byte[] data) where T : BEncodedValue
 {
     return((T)BEncodedValue.Decode(data));
 }
        public void DecodeDictionary_MissingTrailingE()
        {
            string benString = "d1:a1:b";

            Assert.Throws <BEncodingException> (() => BEncodedValue.Decode(Encoding.UTF8.GetBytes(benString)));
        }
Exemple #10
0
        public void DecodeString_TooShort()
        {
            string benString = "5:test";

            Assert.Throws <BEncodingException> (() => BEncodedValue.Decode(Encoding.UTF8.GetBytes(benString)));
        }
Exemple #11
0
        public void DecodeString_NoColon()
        {
            string benString = "12";

            Assert.Throws <BEncodingException> (() => BEncodedValue.Decode(Encoding.UTF8.GetBytes(benString)));
        }
Exemple #12
0
        public void DecodeNumber_InvalidDigit()
        {
            string benString = "i123$21e";

            Assert.Throws <BEncodingException> (() => BEncodedValue.Decode(Encoding.UTF8.GetBytes(benString)));
        }
Exemple #13
0
        public void DecodeDictionary_OutOfOrder_Strict()
        {
            string benString = "d1:b1:b1:a1:ae";

            Assert.Throws <BEncodingException> (() => BEncodedValue.Decode(Encoding.UTF8.GetBytes(benString), true));
        }