Exemplo n.º 1
0
 protected byte[] FetchHexadecimalEncodedString()
 {
     CaptureItem();
     byte[] result = CurrentItemText.DecodeHexadecimalEncodedString(false);
     if (null != result)
     {
         return(result);
     }
     ParsingError("Expected an hexadecimal string. Found {0}.", CurrentItemText);
     // Not reachable.
     return(null);
 }
Exemplo n.º 2
0
        protected IPEndPoint FetchIPEndPoint()
        {
            bool errorEncountered = false;

            CaptureItem();
            try {
                int splitAt;

                if (CurrentItemText.StartsWith("["))
                {
                    int closingBracketIndex = CurrentItemText.IndexOf(']');
                    if (2 > closingBracketIndex)
                    {
                        errorEncountered = true;
                        return(null);
                    }
                    splitAt = CurrentItemText.IndexOf(':', closingBracketIndex);
                }
                else
                {
                    splitAt = CurrentItemText.IndexOf(':');
                }
                IPAddress ipAddress;
                ushort    port;

                if ((-1 != splitAt) &&
                    (0 != splitAt) &&
                    (CurrentItemText.Length > (splitAt + 1)) &&
                    IPAddress.TryParse(CurrentItemText.Substring(0, splitAt), out ipAddress) &&
                    ushort.TryParse(CurrentItemText.Substring(splitAt + 1), out port))
                {
                    return(new IPEndPoint(ipAddress, port));
                }
                errorEncountered = true;
                return(null);
            }
            finally {
                if (errorEncountered)
                {
                    ParsingError("Expecting an IP endpoint. Found '{0}'", CurrentItemText);
                }
            }
        }
Exemplo n.º 3
0
        protected TorVersion[] FetchVersionsListItem()
        {
            CaptureItem();
            List <TorVersion> result = new List <TorVersion>();

            string[] items = CurrentItemText.Split(',');
            foreach (string item in items)
            {
                string versionString;
                string qualifier;
                if (!SplitPair(item, '-', out versionString, out qualifier, true))
                {
                    ParsingError("Invalid version number {0}.", item);
                }
                Version parsedVersion;
                if (!Version.TryParse(versionString, out parsedVersion))
                {
                    ParsingError("Ill-formed version number '{0}'.", item);
                }
                result.Add(new TorVersion(parsedVersion, qualifier));
            }
            return(result.ToArray());
        }