use super::{AuthParams, AuthSpec, Mac, ServiceKind, ServiceProviderGeneric, VerifyMacResult};
use core::fmt::{Debug, Formatter};
use core::ops::{Deref, DerefMut};
pub trait AuthProvider {
type Spec: AuthSpec;
type SignError;
type VerifyError;
fn sign(
&self,
p: &AuthParams<Self::Spec>,
data: &[&[u8]],
) -> Result<Mac<<Self::Spec as AuthSpec>::MacSize>, Self::SignError>;
fn verify(
&self,
p: &AuthParams<Self::Spec>,
data: &[&[u8]],
mac: &[u8],
) -> Result<VerifyMacResult, Self::VerifyError>;
}
impl<A: AuthProvider> super::sealed::Sealed for AsAuth<A> {}
impl<A: AuthProvider> ServiceProviderGeneric for AsAuth<A> {
type Param = AuthParams<A::Spec>;
const KIND: ServiceKind = ServiceKind::Auth;
}
pub struct AsAuth<T>(pub T);
impl<T> Deref for AsAuth<T> {
type Target = T;
#[inline]
fn deref(&self) -> &T { &self.0 }
}
impl<T> DerefMut for AsAuth<T> {
#[inline]
fn deref_mut(&mut self) -> &mut T { &mut self.0 }
}
impl<T> From<T> for AsAuth<T> {
#[inline]
fn from(t: T) -> Self { AsAuth(t) }
}
impl<T: Debug> Debug for AsAuth<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_tuple("AsAuth").field(&self.0).finish()
}
}