mod cipher;
#[cfg(feature = "rustcrypto")]
mod rustcrypto_engine;
mod table_engine;
use core::fmt;
use tc_block_cipher::{
BlockCipher, BlockCipherInit, BlockError, CipherDirection, InitError, KeyParams,
};
use crate::ALGO_NAME;
#[cfg(feature = "rustcrypto")]
pub use rustcrypto_engine::BlowfishRustCryptoEngine;
pub use table_engine::BlowfishTableEngine;
#[cfg(feature = "rustcrypto")]
use rustcrypto_engine::BlowfishRustCryptoEngine as Backend;
#[cfg(not(feature = "rustcrypto"))]
use table_engine::BlowfishTableEngine as Backend;
pub struct BlowfishEngine {
inner: Backend,
}
impl BlowfishEngine {
pub const fn new() -> Self {
Self {
inner: Backend::new(),
}
}
}
impl Default for BlowfishEngine {
fn default() -> Self {
Self::new()
}
}
impl fmt::Display for BlowfishEngine {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(ALGO_NAME)
}
}
impl BlockCipher for BlowfishEngine {
type Error = BlockError;
fn block_size(&self) -> usize {
self.inner.block_size()
}
fn process_block(&mut self, input: &[u8], output: &mut [u8]) -> Result<usize, BlockError> {
self.inner.process_block(input, output)
}
}
impl<P: KeyParams + ?Sized> BlockCipherInit<P> for BlowfishEngine {
type Error = InitError;
fn init(&mut self, direction: CipherDirection, params: &P) -> Result<(), InitError> {
self.inner.init(direction, params)
}
}