//! 分组密码算法（Block Cipher Algorthms）
//!
//! 在密码学中，分组密码是一种对称密钥算法。它将明文分成多个等长的模块，使用确定的算法和对称密钥对每组分别加密解密。\
//! In cryptography, a block cipher is a deterministic algorithm that operates on fixed-length groups of bits, called blocks.
//! Block ciphers are the elementary building blocks of many cryptographic protocols.

pub(self) mod constants;
pub(self) mod operation_modes;
mod sm4;
mod sm4_block;

pub use self::operation_modes::OperationMode;
pub use self::sm4::SM4;
pub use self::sm4_block::{
    sm4_ecb_encrypt, sm4_ecb_decrypt,
    sm4_cbc_encrypt, sm4_cbc_decrypt,
    sm4_cfb_encrypt, sm4_cfb_decrypt,
    sm4_ofb_encrypt, sm4_ofb_decrypt,
};


/// 操作模式（Operation）
#[derive(PartialEq)]
pub enum Operation {
    /// 加密（Encryption）
    Encrypt,
    /// 解密（Decryption）
    Decrypt,
}


/// 分组密码（Block Cipher）
pub enum BlockCipher {
    /// SM4分组密码算法（ShangMi 4 Block Cipher Algorithm）
    SM4,
}


/// 分组密码特性（Trait for Block Cipher Algorithms）
pub trait BlockCipherImpl {

    /// 填入任意长度的待计算的消息。\
    /// Feed a message of any length to be calculated.
    ///
    /// # 参数（Arguments）
    ///
    /// * message - 消息（Message）
    ///
    ///   任意长度的消息。\
    ///   Message of any length.
    fn update(&mut self, message: &[u8]) -> Result<Vec<u8>, ()>;

    /// 结束填入待计算的消息。\
    /// End feeding in messages to be calculated.
    fn r#final(&mut self) -> Result<Vec<u8>, ()>;
}
