pub struct CryptoUtils;Implementations§
Source§impl CryptoUtils
impl CryptoUtils
Sourcepub fn derive_key(
password: &str,
salt: &SaltString,
) -> Result<Vec<u8>, ServiceError>
pub fn derive_key( password: &str, salt: &SaltString, ) -> Result<Vec<u8>, ServiceError>
Derive a key from password and salt with Argon2
Sourcepub fn encrypt(
data: &[u8],
key: &[u8],
salt: &[u8],
) -> Result<String, ServiceError>
pub fn encrypt( data: &[u8], key: &[u8], salt: &[u8], ) -> Result<String, ServiceError>
Encrypt data with the provided key and return a base64 encoded string to store in the database
Sourcepub fn decrypt_data(
data: String,
password: Option<&SecretString>,
) -> Result<String, ServiceError>
pub fn decrypt_data( data: String, password: Option<&SecretString>, ) -> Result<String, ServiceError>
Decrypt an identity key from the database
Sourcepub fn store_encrypted(
idkey: &str,
password: Option<&SecretString>,
fixed_salt: Option<SaltString>,
) -> Result<String, ServiceError>
pub fn store_encrypted( idkey: &str, password: Option<&SecretString>, fixed_salt: Option<SaltString>, ) -> Result<String, ServiceError>
Encrypt a string to save it in the database
§Parameters
idkey- The string data to be encryptedpassword- Optional password used for encryption. If None, returns the data unencryptedfixed_salt- Optional fixed salt for encryption. If None, generates a random salt. This parameter is primarily used for unit testing to ensure consistent encryption results.
§Returns
Returns a Result containing either:
- Ok(String) - The encrypted data encoded in base64
- Err(ServiceError) - If encryption fails
Auto Trait Implementations§
impl Freeze for CryptoUtils
impl RefUnwindSafe for CryptoUtils
impl Send for CryptoUtils
impl Sync for CryptoUtils
impl Unpin for CryptoUtils
impl UnwindSafe for CryptoUtils
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more