use crate::error::AppError;
pub async fn run_blocking<F, T>(blocking_fn: F) -> Result<T, AppError>
where
F: FnOnce() -> Result<T, AppError> + Send + 'static,
T: Send + 'static,
{
tokio::task::spawn_blocking(blocking_fn)
.await
.map_err(|join_err| AppError::TaskFailed(join_err.to_string()))?
}
pub fn constant_time_eq(left: &[u8], right: &[u8]) -> bool {
if left.len() != right.len() {
return false;
}
let mut difference: u8 = 0;
for (left_byte, right_byte) in left.iter().zip(right.iter()) {
difference |= left_byte ^ right_byte;
}
difference == 0
}