use crate::identity::IdentityConfiguration;
use std::path::{Path, PathBuf};
pub const IDENTITY_PEM: &str = "identity.pem";
pub const IDENTITY_PEM_ENCRYPTED: &str = "identity.pem.encrypted";
#[derive(Clone, Debug)]
pub(crate) struct IdentityFileLocations {
root_dir: PathBuf,
}
impl IdentityFileLocations {
pub fn new(root_dir: PathBuf) -> Self {
Self { root_dir }
}
pub fn root(&self) -> &Path {
&self.root_dir
}
pub fn get_identity_pem_path(
&self,
identity_name: &str,
identity_config: &IdentityConfiguration,
) -> PathBuf {
if identity_config.encryption.is_some() {
self.get_encrypted_identity_pem_path(identity_name)
} else {
self.get_plaintext_identity_pem_path(identity_name)
}
}
pub fn get_plaintext_identity_pem_path(&self, identity_name: &str) -> PathBuf {
self.get_identity_dir_path(identity_name).join(IDENTITY_PEM)
}
pub fn get_encrypted_identity_pem_path(&self, identity_name: &str) -> PathBuf {
self.get_identity_dir_path(identity_name)
.join(IDENTITY_PEM_ENCRYPTED)
}
pub fn get_identity_dir_path(&self, identity: &str) -> PathBuf {
self.root_dir.join(identity)
}
}