purecrypt 0.1.0-alpha

Minimal, readable, dependency-free implementations of modern cryptographic primitives in pure Rust
Documentation
#[cfg(feature = "zeroize")]
use zeroize::{Zeroize, ZeroizeOnDrop};

use super::consts::*;

#[derive(Clone)]
#[cfg_attr(feature = "zeroize", derive(Zeroize, ZeroizeOnDrop))]
pub struct Constants([u8; CONSTANTS_LEN]);

#[derive(Clone, Default)]
#[cfg_attr(feature = "zeroize", derive(Zeroize, ZeroizeOnDrop))]
pub struct Key([u8; KEY_LEN]);

#[derive(Clone, Default)]
#[cfg_attr(feature = "zeroize", derive(Zeroize, ZeroizeOnDrop))]
pub struct Seed([u8; KEY_LEN]);

impl Constants {
    pub fn is_default(&self) -> bool {
        self.0 == DEFAULT_CONSTANTS
    }
}

impl Key {
    pub fn into_seed(self) -> Seed {
        Seed(self.0)
    }
}

impl Seed {
    pub fn into_key(&self) -> Key {
        Key(self.0)
    }
}

impl Default for Constants {
    fn default() -> Self {
        Self::new(DEFAULT_CONSTANTS)
    }
}

bytes_wrapper_impl!(Constants, CONSTANTS_LEN);
bytes_wrapper_impl!(Key, KEY_LEN);
bytes_wrapper_impl!(Seed, KEY_LEN);