spacedls 0.4.0

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

/// Trait for encryption-only service providers.
pub trait EncProvider {
    type Spec: EncSpec;
    type EncryptError;
    type DecryptError;

    fn encrypt(
        &self,
        p: &EncParams<Self::Spec>,
        plain: &[u8],
        cipher: &mut [u8],
    ) -> Result<usize, Self::EncryptError>;
    fn decrypt(
        &self,
        p: &EncParams<Self::Spec>,
        cipher: &mut [u8],
    ) -> Result<usize, Self::DecryptError>;

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

impl<E: EncProvider> super::sealed::Sealed for AsEnc<E> {}
impl<E: EncProvider> ServiceProviderGeneric for AsEnc<E> {
    type Param = EncParams<E::Spec>;
    const KIND: ServiceKind = ServiceKind::Enc;
}

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

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