Пример #1
0
        public static string[] DecodeContinuationTokenV2(string[] tokenSplits)
        {
            int num = Convert.ToInt32(tokenSplits[1]);

            if (num != tokenSplits[2].Length)
            {
                throw new ContinuationTokenParserException(string.Format("Encoded token list string length ({0}) did not match actual encoded token list string length ({1}).", num, tokenSplits[2].Length), "continuationToken");
            }
            string str   = ContinuationTokenParser.UrlCustomUnescapeBase64String(tokenSplits[2]);
            string empty = string.Empty;

            try
            {
                empty = (new UTF8Encoding()).GetString(Convert.FromBase64String(str));
            }
            catch (FormatException formatException)
            {
                throw new ContinuationTokenParserException("The continuation token can't be decoded from Base-64 string.", formatException);
            }
            List <string> strs = new List <string>();
            int           num1 = 0;

            do
            {
                int num2 = -1;
                if (empty.Length - num1 < 7)
                {
                    object[] length = new object[] { empty.Length, empty.Length - num1, num1, 6, 1 };
                    throw new ContinuationTokenParserException(string.Format("The token list string of length {0} only has {1} characters left given current offset {2}, which is not enough to contain a single token length which is of length {3} and the delimiter of length {4}.", length));
                }
                num2  = int.Parse(empty.Substring(num1, 6));
                num1 += 6;
                if (empty[num1] != '!')
                {
                    throw new ContinuationTokenParserException(string.Format("The token list string does not contain the expected delimiter {0} at position {1} after extracting a token length.", '!', num1));
                }
                num1++;
                if (empty.Length - num1 < num2 + 1)
                {
                    object[] objArray = new object[] { empty.Length, empty.Length - num1, num1, num2, 1 };
                    throw new ContinuationTokenParserException(string.Format("The token list string of length {0} only has {1} characters left given current offset {2}, which is not enough to contain a token of length {3} and the delimiter of length {4}.", objArray));
                }
                string str1 = empty.Substring(num1, num2);
                num1 += num2;
                if (empty[num1] != '!')
                {
                    throw new ContinuationTokenParserException(string.Format("The token list string does not contain the expected delimiter {0} at position {1} after extracting a token.", '!', num1));
                }
                num1++;
                strs.Add(str1);
            }while (num1 != empty.Length);
            return(strs.ToArray());
        }
Пример #2
0
        public static string[] DecodeContinuationTokenV1(string[] tokenSplits)
        {
            string[] strArrays;
            int      num = Convert.ToInt32(tokenSplits[1]);

            if (num != tokenSplits[2].Length)
            {
                throw new ContinuationTokenParserException(string.Format("Token size ({0}) did not match token length ({1}).", num, tokenSplits[2].Length), "continuationToken");
            }
            string str  = tokenSplits[2].Substring(0, num);
            string str1 = ContinuationTokenParser.UrlCustomUnescapeBase64String(str);

            try
            {
                string str2 = (new UTF8Encoding()).GetString(Convert.FromBase64String(str1));
                strArrays = new string[] { str2 };
            }
            catch (FormatException formatException)
            {
                throw new ContinuationTokenParserException("The continuation token can't be decoded from Base-64 string.", formatException);
            }
            return(strArrays);
        }