2024-09-06 23:09:10 +02:00
|
|
|
//! A module for managing and sharing secrets in the Wooly Vault application.
|
|
|
|
//!
|
|
|
|
//! This module provides a [`Vault`] struct that holds a secret and allows it to be shared safely
|
|
|
|
//! across the application using an [`Arc`] (Atomic Reference Counted) pointer.
|
|
|
|
|
2024-09-05 17:18:08 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2024-09-06 23:09:10 +02:00
|
|
|
/// A type alias for an [`Arc`] pointer to a [`Vault`] instance.
|
|
|
|
///
|
|
|
|
/// This type is used to share a [`Vault`] instance across multiple parts of the application.
|
2024-09-05 17:18:08 +02:00
|
|
|
pub type VaultRef = Arc<Vault>;
|
|
|
|
|
2024-09-06 23:09:10 +02:00
|
|
|
/// A struct that holds a secret and provides methods for accessing it.
|
|
|
|
///
|
|
|
|
/// The [`Vault`] struct is designed to be shared safely across the application using an [`Arc`] pointer.
|
2024-09-05 17:18:08 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
pub struct Vault {
|
2024-09-06 23:09:10 +02:00
|
|
|
/// The secret stored in the vault
|
2024-09-05 17:18:08 +02:00
|
|
|
secret: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Vault {
|
2024-09-06 23:09:10 +02:00
|
|
|
/// Creates a new [`Vault`] instance with the given secret.
|
|
|
|
///
|
|
|
|
/// Returns an [`Arc`] pointer to the new [`Vault`] instance.
|
|
|
|
///
|
|
|
|
/// # Returns
|
|
|
|
///
|
|
|
|
/// A new [`Vault`] instance with the given secret.
|
2024-09-05 17:18:08 +02:00
|
|
|
pub fn new(secret: &str) -> VaultRef {
|
|
|
|
let v = Self {
|
|
|
|
secret: secret.to_string(),
|
|
|
|
};
|
|
|
|
Arc::new(v)
|
|
|
|
}
|
2024-09-06 23:09:10 +02:00
|
|
|
|
|
|
|
/// Returns a reference to the secret stored in the vault.
|
|
|
|
///
|
|
|
|
/// # Returns
|
|
|
|
///
|
|
|
|
/// A reference to the secret stored in the vault.
|
2024-09-05 17:18:08 +02:00
|
|
|
pub fn secret(&self) -> &str {
|
|
|
|
&self.secret
|
|
|
|
}
|
|
|
|
}
|