use crate::cryptographic_hashs::CryptographicHash;

use super::HMAC;


/// HMAC-SM3块式计算器（HMAC-SM3 Block Mode Calculator）
///
/// # 示例（Examples）
///
/// ```rust
/// # fn main() -> Result<(), ()> {
/// use neuedu_cryptos::common::bytes_to_hexstring;
/// use neuedu_cryptos::mac::hmac_sm3;
///
/// let mac = hmac_sm3(b"key", b"message")?;
///
/// assert_eq!(bytes_to_hexstring(&mac), "34c90b291a80b7fd7f2be43d683935bab9d149164666c4ef8857c815cf2ef832");
/// #
/// #     Ok(())
/// # }
/// ```
pub fn hmac_sm3(key: &[u8], message: &[u8]) -> Result<Vec<u8>, ()> {
    let mut instance = HMAC::new(key, CryptographicHash::SM3);
    instance.update(message).unwrap();

    instance.r#final()
}


/// HMAC-SHA1块式计算器（HMAC-SHA1 Block Mode Calculator）
///
/// # 示例（Examples）
///
/// ```rust
/// # fn main() -> Result<(), ()> {
/// use neuedu_cryptos::common::bytes_to_hexstring;
/// use neuedu_cryptos::mac::hmac_sha1;
///
/// let mac = hmac_sha1(b"key", b"message")?;
///
/// assert_eq!(bytes_to_hexstring(&mac), "2088df74d5f2146b48146caf4965377e9d0be3a4");
/// #
/// #     Ok(())
/// # }
/// ```
pub fn hmac_sha1(key: &[u8], message: &[u8]) -> Result<Vec<u8>, ()> {
    let mut instance = HMAC::new(key, CryptographicHash::SHA1);
    instance.update(message).unwrap();

    instance.r#final()
}


/// HMAC-SHA224块式计算器（HMAC-SHA224 Block Mode Calculator）
///
/// # 示例（Examples）
///
/// ```rust
/// # fn main() -> Result<(), ()> {
/// use neuedu_cryptos::common::bytes_to_hexstring;
/// use neuedu_cryptos::mac::hmac_sha224;
///
/// let mac = hmac_sha224(b"key", b"message")?;
///
/// assert_eq!(bytes_to_hexstring(&mac), "a0b5eecae3f74f0561a8da6f389f78f1a3895c8c183c31c1756d7925");
/// #
/// #     Ok(())
/// # }
/// ```
pub fn hmac_sha224(key: &[u8], message: &[u8]) -> Result<Vec<u8>, ()> {
    let mut instance = HMAC::new(key, CryptographicHash::SHA224);
    instance.update(message).unwrap();

    instance.r#final()
}


/// HMAC-SHA256块式计算器（HMAC-SHA256 Block Mode Calculator）
///
/// # 示例（Examples）
///
/// ```rust
/// # fn main() -> Result<(), ()> {
/// use neuedu_cryptos::common::bytes_to_hexstring;
/// use neuedu_cryptos::mac::hmac_sha256;
///
/// let mac = hmac_sha256(b"key", b"message")?;
///
/// assert_eq!(bytes_to_hexstring(&mac), "6e9ef29b75fffc5b7abae527d58fdadb2fe42e7219011976917343065f58ed4a");
/// #
/// #     Ok(())
/// # }
/// ```
pub fn hmac_sha256(key: &[u8], message: &[u8]) -> Result<Vec<u8>, ()> {
    let mut instance = HMAC::new(key, CryptographicHash::SHA256);
    instance.update(message).unwrap();

    instance.r#final()
}


/// HMAC-SHA384块式计算器（HMAC-SHA384 Block Mode Calculator）
///
/// # 示例（Examples）
///
/// ```rust
/// # fn main() -> Result<(), ()> {
/// use neuedu_cryptos::common::bytes_to_hexstring;
/// use neuedu_cryptos::mac::hmac_sha384;
///
/// let mac = hmac_sha384(b"key", b"message")?;
///
/// assert_eq!(bytes_to_hexstring(&mac), "0fd3ae3237be98c64a075b7394989fc6789f31788fada42eada85ee6698bde2feae20b66271b67544b9062c773b2d86f");
/// #
/// #     Ok(())
/// # }
/// ```
pub fn hmac_sha384(key: &[u8], message: &[u8]) -> Result<Vec<u8>, ()> {
    let mut instance = HMAC::new(key, CryptographicHash::SHA384);
    instance.update(message).unwrap();

    instance.r#final()
}


/// HMAC-SHA512块式计算器（HMAC-SHA512 Block Mode Calculator）
///
/// # 示例（Examples）
///
/// ```rust
/// # fn main() -> Result<(), ()> {
/// use neuedu_cryptos::common::bytes_to_hexstring;
/// use neuedu_cryptos::mac::hmac_sha512;
///
/// let mac = hmac_sha512(b"key", b"message")?;
///
/// assert_eq!(bytes_to_hexstring(&mac), "e477384d7ca229dd1426e64b63ebf2d36ebd6d7e669a6735424e72ea6c01d3f8b56eb39c36d8232f5427999b8d1a3f9cd1128fc69f4d75b434216810fa367e98");
/// #
/// #     Ok(())
/// # }
/// ```
pub fn hmac_sha512(key: &[u8], message: &[u8]) -> Result<Vec<u8>, ()> {
    let mut instance = HMAC::new(key, CryptographicHash::SHA512);
    instance.update(message).unwrap();

    instance.r#final()
}
