spacedls 0.4.0

no_std CCSDS 355.0-B-2 (SDLS) Space Data Link Security implementation
Documentation
use super::{AuthParams, AuthSpec, Mac, ServiceKind, ServiceProviderGeneric, VerifyMacResult};
use core::fmt::{Debug, Formatter};
use core::ops::{Deref, DerefMut};

/// Trait for authentication-only (MAC) service providers.
///
/// The `data` parameter is a slice of slices to allow computing the MAC
/// over non-contiguous buffers without copying.
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;
}

/// Newtype wrapper marking a provider as authentication-only service.
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()
    }
}