use std::path::{Path, PathBuf};
use secrecy::ExposeSecret;
#[allow(dead_code)]
pub struct IdentityMaterial {
pub identity_file: PathBuf,
pub recipient: String,
}
pub fn generate_identity(root: &Path, label: &str) -> IdentityMaterial {
let identity_file = root.join(format!("{label}.agekey"));
let identity = age::x25519::Identity::generate();
std::fs::write(
&identity_file,
identity.to_string().expose_secret().as_bytes(),
)
.unwrap_or_else(|error| {
panic!(
"failed to write identity {}: {error}",
identity_file.display()
)
});
let recipient = identity.to_public().to_string();
assert!(!recipient.is_empty(), "generated empty recipient");
IdentityMaterial {
identity_file,
recipient,
}
}