Initial project commit

This commit is contained in:
2022-06-11 16:42:18 -04:00
commit 14565a17e2
60 changed files with 3739 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TorControlLibrary.Exceptions
{
public class TorException : System.Exception
{
public static TorException Parse(String errorLine)
{
TorException ex = null;
switch (errorLine.Substring(0, 3))
{
case "552":
if (errorLine.Contains("Unknown stream"))
ex = new TorUnknownStreamException()
{
StreamID = Int32.Parse(errorLine.Substring(errorLine.IndexOf('"') + 1, errorLine.Length - (errorLine.LastIndexOf('"') + 1)))
};
else if (errorLine.Contains("Unknown circuit"))
ex = new TorUnknownCircuitException()
{
CircuitID = Int32.Parse(errorLine.Substring(errorLine.IndexOf('"') + 1, errorLine.Length - (errorLine.LastIndexOf('"') + 1)))
};
else
ex = new TorException();
break;
case "551":
if (errorLine.Contains("one-hop circuit"))
{
ex = new TorOneCircuitException();
}
break;
case "515":
ex = new TorAuthenticationException();
break;
default:
throw new ApplicationException("Unhandled exception from TOR control port");
}
ex.ErrorDescription = errorLine.Substring(4);
ex.StatusCode = Int32.Parse(errorLine.Substring(0, 3));
return ex;
}
public Int32 StatusCode { get; set; }
public String ErrorDescription { get; set; }
}
}