wtx 0.44.3

A collection of different transport implementations and related tools focused primarily on web technologies.
Documentation
use crate::misc::DefaultArray;
use core::marker::PhantomData;

#[cfg(feature = "crypto-aws-lc-rs")]
mod aws_lc_rs;
pub(crate) mod global;
#[cfg(feature = "hkdf")]
mod hkdf;
#[cfg(feature = "crypto-ring")]
mod ring;

/// HMAC-based Key Derivation Function
pub trait Hkdf: Sized {
  /// Output array
  type Digest;

  /// The HKDF-Extract operation from the RFC-5869
  fn extract(salt: Option<&[u8]>, ikm: &[u8]) -> (Self::Digest, Self);

  /// Creates a new instance from an already cryptographically strong pseudorandom key.
  fn from_prk(prk: &[u8]) -> crate::Result<Self>;

  /// Performs a one-shot HMAC
  fn compute<'data>(
    data: impl IntoIterator<Item = &'data [u8]>,
    key: &[u8],
  ) -> crate::Result<Self::Digest>;

  /// The HKDF-Expand operation from the RFC-5869
  fn expand(&self, info: &[u8], okm: &mut [u8]) -> crate::Result<()>;
}

/// Stub [`Hkdf`] implementation used when no backend is enabled.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct HkdfStub<D>(PhantomData<D>);

impl<D> Hkdf for HkdfStub<D>
where
  D: DefaultArray,
{
  type Digest = D;

  #[inline]
  fn extract(_: Option<&[u8]>, _: &[u8]) -> (Self::Digest, Self) {
    (Self::Digest::default_array(), Self(PhantomData))
  }

  #[inline]
  fn from_prk(_: &[u8]) -> crate::Result<Self> {
    Ok(Self(PhantomData))
  }

  #[inline]
  fn compute<'data>(
    _: impl IntoIterator<Item = &'data [u8]>,
    _: &[u8],
  ) -> crate::Result<Self::Digest> {
    Ok(Self::Digest::default_array())
  }

  #[inline]
  fn expand(&self, _: &[u8], _: &mut [u8]) -> crate::Result<()> {
    Ok(())
  }
}