2026-04-01 21:16:39 -04:00
|
|
|
use crate::error::AgeError;
|
|
|
|
|
use crate::identities::Identity;
|
2026-04-02 20:53:07 -04:00
|
|
|
use crate::identities::scrypt::ScryptIdentity;
|
2026-04-12 16:35:53 -04:00
|
|
|
use crate::ports::IdentitySource;
|
2026-03-31 17:26:10 -04:00
|
|
|
|
|
|
|
|
pub struct PromptSource;
|
|
|
|
|
|
2026-04-01 21:16:39 -04:00
|
|
|
impl IdentitySource for PromptSource {
|
2026-04-01 20:44:05 -04:00
|
|
|
fn name(&self) -> &str {
|
|
|
|
|
"prompt"
|
|
|
|
|
}
|
2026-03-31 17:26:10 -04:00
|
|
|
|
2026-04-01 21:16:39 -04:00
|
|
|
fn load(&self) -> Result<Box<dyn Identity>, AgeError> {
|
|
|
|
|
let passphrase = rpassword::prompt_password("Enter age passphrase: ").map_err(|e| {
|
|
|
|
|
AgeError::SourceError {
|
|
|
|
|
name: self.name().to_string(),
|
|
|
|
|
source: anyhow::anyhow!("could not read passphrase: {e}"),
|
|
|
|
|
}
|
|
|
|
|
})?;
|
|
|
|
|
if passphrase.trim().is_empty() {
|
|
|
|
|
return Err(AgeError::SourceError {
|
|
|
|
|
name: self.name().to_string(),
|
|
|
|
|
source: anyhow::anyhow!("empty passphrase entered"),
|
|
|
|
|
});
|
2026-03-31 17:26:10 -04:00
|
|
|
}
|
2026-04-01 21:16:39 -04:00
|
|
|
Ok(Box::new(ScryptIdentity::new(passphrase)))
|
2026-03-31 17:26:10 -04:00
|
|
|
}
|
|
|
|
|
}
|