use super::{CryptographicHash, CryptographicHashImpl, SHA2};


/// 安全散列算法2（SHA-224）块式计算器（Secure Hash Algorithm 2 (SHA-224) Block Mode Calculator）
///
/// # 参数（Arguments）
///
/// * message - 消息（Message）
///
/// # 示例（Examples）
///
/// ```rust
/// # fn main() -> Result<(), ()> {
/// use neuedu_cryptos::cryptographic_hashs::sha224;
///
/// let digest = sha224(b"abc")?;
///
/// assert_eq!(digest, [
///     0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22,
///     0x86, 0x42, 0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3,
///     0x2A, 0xAD, 0xBC, 0xE4, 0xBD, 0xA0, 0xB3, 0xF7,
///     0xE3, 0x6C, 0x9D, 0xA7,
/// ]);
/// #
/// #     Ok(())
/// # }
/// ```
pub fn sha224(message: &[u8]) -> Result<[u8; 28], ()> {
    let mut instance = SHA2::new(CryptographicHash::SHA224);
    instance.update(message).unwrap();

    Ok(instance.r#final().unwrap().try_into().unwrap())
}


/// 安全散列算法2（SHA-256）块式计算器（Secure Hash Algorithm 2 (SHA-256) Block Mode Calculator）
///
/// # 参数（Arguments）
///
/// * message - 消息（Message）
///
/// # 示例（Examples）
///
/// ```rust
/// # fn main() -> Result<(), ()> {
/// use neuedu_cryptos::cryptographic_hashs::sha256;
///
/// let digest = sha256(b"abc")?;
///
/// assert_eq!(digest, [
///     0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA, 0x41,
///     0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23, 0xB0, 0x03,
///     0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C, 0xB4, 0x10, 0xFF,
///     0x61, 0xF2, 0x00, 0x15, 0xAD,
/// ]);
/// #
/// #     Ok(())
/// # }
/// ```
pub fn sha256(message: &[u8]) -> Result<[u8; 32], ()> {
    let mut instance = SHA2::new(CryptographicHash::SHA256);
    instance.update(message).unwrap();

    Ok(instance.r#final().unwrap().try_into().unwrap())
}


/// 安全散列算法2（SHA-384）块式计算器（Secure Hash Algorithm 2 (SHA-384) Block Mode Calculator）
///
/// # 参数（Arguments）
///
/// * message - 消息（Message）
///
/// # 示例（Examples）
///
/// ```rust
/// # fn main() -> Result<(), ()> {
/// use neuedu_cryptos::cryptographic_hashs::sha384;
///
/// let digest = sha384(b"abc")?;
///
/// assert_eq!(digest, [
///     0xCB, 0x00, 0x75, 0x3F, 0x45, 0xA3, 0x5E, 0x8B,
///     0xB5, 0xA0, 0x3D, 0x69, 0x9A, 0xC6, 0x50, 0x07,
///     0x27, 0x2C, 0x32, 0xAB, 0x0E, 0xDE, 0xD1, 0x63,
///     0x1A, 0x8B, 0x60, 0x5A, 0x43, 0xFF, 0x5B, 0xED,
///     0x80, 0x86, 0x07, 0x2B, 0xA1, 0xE7, 0xCC, 0x23,
///     0x58, 0xBA, 0xEC, 0xA1, 0x34, 0xC8, 0x25, 0xA7,
/// ]);
/// #
/// #     Ok(())
/// # }
/// ```
pub fn sha384(message: &[u8]) -> Result<[u8; 48], ()> {
    let mut instance = SHA2::new(CryptographicHash::SHA384);
    instance.update(message).unwrap();

    Ok(instance.r#final().unwrap().try_into().unwrap())
}


/// 安全散列算法2（SHA-512）块式计算器（Secure Hash Algorithm 2 (SHA-512) Block Mode Calculator）
///
/// # 参数（Arguments）
///
/// * message - 消息（Message）
///
/// # 示例（Examples）
///
/// ```rust
/// # fn main() -> Result<(), ()> {
/// use neuedu_cryptos::cryptographic_hashs::sha512;
///
/// let digest = sha512(b"abc")?;
///
/// assert_eq!(digest, [
///     0xDD, 0xAF, 0x35, 0xA1, 0x93, 0x61, 0x7A, 0xBA,
///     0xCC, 0x41, 0x73, 0x49, 0xAE, 0x20, 0x41, 0x31,
///     0x12, 0xE6, 0xFA, 0x4E, 0x89, 0xA9, 0x7E, 0xA2,
///     0x0A, 0x9E, 0xEE, 0xE6, 0x4B, 0x55, 0xD3, 0x9A,
///     0x21, 0x92, 0x99, 0x2A, 0x27, 0x4F, 0xC1, 0xA8,
///     0x36, 0xBA, 0x3C, 0x23, 0xA3, 0xFE, 0xEB, 0xBD,
///     0x45, 0x4D, 0x44, 0x23, 0x64, 0x3C, 0xE8, 0x0E,
///     0x2A, 0x9A, 0xC9, 0x4F, 0xA5, 0x4C, 0xA4, 0x9F,
/// ]);
/// #
/// #     Ok(())
/// # }
/// ```
pub fn sha512(message: &[u8]) -> Result<[u8; 64], ()> {
    let mut instance = SHA2::new(CryptographicHash::SHA512);
    instance.update(message).unwrap();

    Ok(instance.r#final().unwrap().try_into().unwrap())
}
