#[cfg(feature = "aes")]
mod aes;
mod decryptor;
mod encryptor;
mod state;
pub use self::{decryptor::Decryptor, encryptor::Encryptor};
pub use ::cipher::{
Block, BlockModeDecrypt, BlockModeEncrypt, common::BlockSizeUser, common::InvalidLength,
};
#[cfg(feature = "aes")]
pub use self::aes::Aes;
#[cfg(feature = "tdes")]
pub use ::des::TdesEde3 as Tdes;
use self::state::State;
#[cfg(feature = "tdes")]
use {crate::Cipher, ::cipher::common::KeyInit};
pub(crate) mod sealed {
use crate::Cipher;
use ::cipher::{BlockCipherDecrypt, BlockCipherEncrypt, common::InvalidLength};
pub trait BlockCipher: BlockCipherDecrypt + BlockCipherEncrypt {
fn new_from_slice(slice: &[u8]) -> Result<Self, InvalidLength>;
fn is_supported(cipher: Cipher) -> bool;
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub(crate) enum BlockMode {
Cbc,
Ctr,
}
#[cfg(feature = "aes")]
pub type AesEncryptor = Encryptor<Aes>;
#[cfg(feature = "aes")]
pub type AesDecryptor = Decryptor<Aes>;
#[cfg(feature = "tdes")]
pub type TdesEncryptor = Encryptor<Tdes>;
#[cfg(feature = "tdes")]
pub type TdesDecryptor = Decryptor<Tdes>;
#[cfg(feature = "tdes")]
impl sealed::BlockCipher for Tdes {
fn new_from_slice(slice: &[u8]) -> Result<Self, InvalidLength> {
KeyInit::new_from_slice(slice)
}
fn is_supported(cipher: Cipher) -> bool {
cipher == Cipher::TdesCbc
}
}