use crate::client::Client;
use crate::errors::{Error, Result};
use crate::models::PasswordCheckResponse;
use crate::utils::keccak_hash_prefix;
impl Client {
pub async fn check_password(&self, password: &str) -> Result<PasswordCheckResponse> {
if password.is_empty() {
return Err(Error::Validation {
message: "password must not be empty".to_string(),
});
}
let hash_prefix = keccak_hash_prefix(password);
let url = format!(
"{}/v1/pass/anon/{}",
self.config.password_base_url, hash_prefix
);
match self.get_with_retry(&url).await {
Ok(response) => {
let body: PasswordCheckResponse = response.json().await?;
Ok(body)
}
Err(Error::NotFound { .. }) => {
Ok(PasswordCheckResponse {
search_pass_anon: crate::models::PasswordSearchAnon {
anon: hash_prefix,
char: String::new(),
count: "0".to_string(),
},
})
}
Err(e) => Err(e),
}
}
}