spacedls 0.4.0

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

/// Trait for authenticated encryption (AEAD) service providers.
///
/// The `aad` parameter is a slice of slices for non-contiguous additional authenticated data.
pub trait AuthEncProvider {
    type Spec: AuthEncSpec;

    type SealError;
    type OpenError;

    fn seal(
        &self,
        p: &AuthEncParams<Self::Spec>,
        aad: &[&[u8]],
        plain: &[u8],
        cipher: &mut [u8],
    ) -> Result<(usize, Mac<<Self::Spec as AuthEncSpec>::MacSize>), Self::SealError>;

    fn open(
        &self,
        p: &AuthEncParams<Self::Spec>,
        aad: &[&[u8]],
        cipher: &mut [u8],
        mac: &[u8],
    ) -> Result<(usize, VerifyMacResult), Self::OpenError>;

    fn pad_len(size: usize) -> u16;
}

impl<AE: AuthEncProvider> super::sealed::Sealed for AsAuthEnc<AE> {}
impl<AE: AuthEncProvider> ServiceProviderGeneric for AsAuthEnc<AE> {
    type Param = AuthEncParams<AE::Spec>;
    const KIND: ServiceKind = ServiceKind::AuthEnc;
}

/// Newtype wrapper marking a provider as authenticated-encryption service.
pub struct AsAuthEnc<T>(pub T);

impl<T> Deref for AsAuthEnc<T> {
    type Target = T;
    #[inline]
    fn deref(&self) -> &T { &self.0 }
}
impl<T> DerefMut for AsAuthEnc<T> {
    #[inline]
    fn deref_mut(&mut self) -> &mut T { &mut self.0 }
}
impl<T> From<T> for AsAuthEnc<T> {
    #[inline]
    fn from(t: T) -> Self { AsAuthEnc(t) }
}
impl<T: Debug> Debug for AsAuthEnc<T> {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        f.debug_tuple("AsAuthEnc").field(&self.0).finish()
    }
}