Files
k-tv/crates/adapters/auth/src/password.rs
Gabriel Kaszewski 25b33b6a0e cleanup: strip comments, extract constants, DRY shared helpers across adapters + infra-wiring
- strip all comments except WHY workaround notes (3 remain)
- remove all #[allow(dead_code)]; fix via _prefix rename
- extract named constants: JWT time units, token types, default config values, jellyfin fallback bitrate
- DRY: move serialize_enum_as_string, content_type_str, parse_content_type, parse_genres_blob to adapter-common
- sqlite+postgres library.rs use shared helpers instead of local copies
- sqlite+postgres channel.rs use shared serialize_enum_as_string
- remove dead `let _ = ext` in scanner.rs
2026-07-12 04:21:21 +02:00

34 lines
916 B
Rust

use domain::errors::DomainResult;
use domain::ports::AuthService;
pub struct PasswordAuthService;
impl AuthService for PasswordAuthService {
fn hash_password(&self, password: &str) -> DomainResult<String> {
Ok(password_auth::generate_hash(password))
}
fn verify_password(&self, password: &str, hash: &str) -> DomainResult<bool> {
Ok(password_auth::verify_password(password, hash).is_ok())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hash_and_verify_round_trip() {
let svc = PasswordAuthService;
let hash = svc.hash_password("supersecret").unwrap();
assert!(svc.verify_password("supersecret", &hash).unwrap());
}
#[test]
fn wrong_password_rejected() {
let svc = PasswordAuthService;
let hash = svc.hash_password("correct").unwrap();
assert!(!svc.verify_password("wrong", &hash).unwrap());
}
}