Files
k-mood/crates/domain/src/provider/encrypted_credential.rs
Gabriel Kaszewski 23d052278a
All checks were successful
CI / ci (push) Successful in 19m38s
changes
2026-08-26 20:58:14 +02:00

27 lines
736 B
Rust

use crate::errors::DomainError;
#[derive(Clone, PartialEq, Eq)]
pub struct EncryptedCredential(Vec<u8>);
impl EncryptedCredential {
pub fn from_persistence(ciphertext: Vec<u8>) -> Self {
Self(ciphertext)
}
pub fn value(&self) -> &[u8] {
&self.0
}
}
impl std::fmt::Debug for EncryptedCredential {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "EncryptedCredential(<redacted {} bytes>)", self.0.len())
}
}
#[async_trait::async_trait]
pub trait CredentialCipher: Send + Sync {
fn encrypt(&self, plaintext: &[u8]) -> Result<EncryptedCredential, DomainError>;
fn decrypt(&self, credential: &EncryptedCredential) -> Result<Vec<u8>, DomainError>;
}