use encoding_rs::WINDOWS_1252;
use httpdate::fmt_http_date;
use std::time::SystemTime;
pub struct AppHash {
pub request_id: u32,
pub hash: String,
pub date_formatted: String,
}
impl AppHash {
pub fn new(request_id: u32, app_secret: &str) -> AppHash {
let now = fmt_http_date(SystemTime::now());
let new_request_id = request_id + 1;
let combined = format!("{}{}", app_secret, now);
let (cow, _encoding_used, _had_errors) = WINDOWS_1252.encode(&combined[..]);
let md5_hash = format!("{:x}", md5::compute(cow));
AppHash {
request_id: new_request_id,
hash: md5_hash,
date_formatted: now,
}
}
}
impl std::fmt::LowerHex for AppHash {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
f.write_str(&self.hash)
}
}