use crate::backend::Metadata;
use lawn_constants::Error;
type Result<T> = std::result::Result<T, Error>;
pub struct AuthenticationInfo<'a> {
id: Option<u32>,
user: &'a [u8],
dir: &'a [u8],
location: &'a [u8],
}
impl<'a> AuthenticationInfo<'a> {
pub fn new(
id: Option<u32>,
user: &'a [u8],
dir: &'a [u8],
location: &'a [u8],
) -> AuthenticationInfo<'a> {
AuthenticationInfo {
id,
user,
dir,
location,
}
}
pub fn id(&self) -> Option<u32> {
self.id
}
pub fn user(&self) -> &[u8] {
self.user
}
pub fn dir(&self) -> &[u8] {
self.dir
}
pub fn location(&self) -> &[u8] {
self.location
}
}
pub trait AuthenticatorHandle {
fn read(&self, data: &mut [u8]) -> Result<u32>;
fn write(&self, data: &[u8]) -> Result<u32>;
fn info(&self) -> Option<AuthenticationInfo<'_>>;
}
pub trait Authenticator {
fn create(
&self,
meta: &Metadata,
uname: &[u8],
aname: &[u8],
nuname: Option<u32>,
) -> Box<dyn AuthenticatorHandle + Send + Sync>;
}