use tor_rpcbase as rpc;
mod cookie;
mod inherent;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct RpcAuthentication {}
#[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize)]
enum AuthenticationScheme {
#[serde(rename = "auth:inherent")]
Inherent,
#[serde(rename = "auth:cookie")]
Cookie,
}
#[derive(Debug, Clone, thiserror::Error, serde::Serialize)]
enum AuthenticationFailure {
#[error("Tried to use unexpected authentication method")]
IncorrectMethod,
#[error("Tried to re-authenticate with a cookie authentication object")]
CookieNonceReused,
#[error("Incorrect authentication value")]
IncorrectAuthentication,
#[error("Shutting down; can't authenticate")]
ShuttingDown,
}
#[derive(Debug, serde::Serialize)]
struct AuthenticateReply {
session: rpc::ObjectId,
}
impl From<AuthenticationFailure> for rpc::RpcError {
fn from(value: AuthenticationFailure) -> Self {
use AuthenticationFailure as AF;
use tor_error::ErrorKind as EK;
let mut err = rpc::RpcError::new(value.to_string(), rpc::RpcErrorKind::RequestError);
match value {
AF::IncorrectMethod | AF::CookieNonceReused | AF::IncorrectAuthentication => {}
AF::ShuttingDown => err.set_kind(EK::ArtiShuttingDown),
}
err
}
}