use hmac::{Hmac, Mac};
use sha2::Sha256;

use crate::Error;

pub(crate) fn hmac_sha256_base64<T, E>(key: T, data: E) -> Result<String, Error>
where
    T: AsRef<[u8]>,
    E: AsRef<[u8]>,
{
    type HmacSha256 = Hmac<Sha256>;

    let mut mac = HmacSha256::new_from_slice(key.as_ref())?;
    mac.update(data.as_ref());
    Ok(base64_simd::STANDARD.encode_to_string(mac.finalize().into_bytes()))
}
