InfoHash() публичный статический Метод

public static InfoHash ( object infoHash ) : void
infoHash object
Результат void
Пример #1
0
        public static InfoHash FromBase32(string infoHash)
        {
            Check.InfoHash(infoHash);
            if (infoHash.Length != 32)
            {
                throw new ArgumentException("Infohash must be a base32 encoded 32 character string");
            }

            infoHash = infoHash.ToLower();
            var infohashOffset = 0;
            var hash           = new byte[20];
            var temp           = new byte[8];

            for (var i = 0; i < hash.Length;)
            {
                for (var j = 0; j < 8; j++)
                {
                    if (!Base32DecodeTable.TryGetValue(infoHash[infohashOffset++], out temp[j]))
                    {
                        throw new ArgumentException("infoHash", "Value is not a valid base32 encoded string");
                    }
                }

                //8 * 5bits = 40 bits = 5 bytes
                hash[i++] = (byte)((temp[0] << 3) | (temp[1] >> 2));
                hash[i++] = (byte)((temp[1] << 6) | (temp[2] << 1) | (temp[3] >> 4));
                hash[i++] = (byte)((temp[3] << 4) | (temp[4] >> 1));
                hash[i++] = (byte)((temp[4] << 7) | (temp[5] << 2) | (temp[6] >> 3));
                hash[i++] = (byte)((temp[6] << 5) | temp[7]);
            }

            return(new InfoHash(hash));
        }
Пример #2
0
 public InfoHash(byte[] infoHash)
 {
     Check.InfoHash(infoHash);
     if (infoHash.Length != 20)
     {
         throw new ArgumentException("Infohash must be exactly 20 bytes long");
     }
     _hash = (byte[])infoHash.Clone();
 }
Пример #3
0
        public static InfoHash FromHex(string infoHash)
        {
            Check.InfoHash(infoHash);
            if (infoHash.Length != 40)
            {
                throw new ArgumentException("Infohash must be 40 characters long");
            }

            var hash = new byte[20];

            for (var i = 0; i < hash.Length; i++)
            {
                hash[i] = byte.Parse(infoHash.Substring(i * 2, 2), NumberStyles.HexNumber);
            }

            return(new InfoHash(hash));
        }
Пример #4
0
 public static InfoHash UrlDecode(string infoHash)
 {
     Check.InfoHash(infoHash);
     return(new InfoHash(UriHelper.UrlDecode(infoHash)));
 }