mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-07 12:00:43 +00:00
feat: return ServiceError instead of using unwraps
This commit is contained in:
parent
fc504efd58
commit
a575556bdd
1 changed files with 8 additions and 4 deletions
|
|
@ -267,14 +267,18 @@ pub async fn encrypt_password_with_recipients(
|
||||||
pub async fn decrypt_password_with_private_key(
|
pub async fn decrypt_password_with_private_key(
|
||||||
password_encrypted: &str,
|
password_encrypted: &str,
|
||||||
key: &str,
|
key: &str,
|
||||||
) -> Result<String, ServiceError> {
|
) -> Result<String, ServiceError> { // TODO More specific error handling
|
||||||
let encrypted = base64::decode(password_encrypted).unwrap();
|
let Ok(encrypted) = base64::decode(password_encrypted) else {
|
||||||
|
return Err(ServiceError::CryptoEncryptFailed);
|
||||||
|
};
|
||||||
|
|
||||||
let mut decrypt_buffer = Vec::new();
|
let mut decrypt_buffer = Vec::new();
|
||||||
|
|
||||||
age_decrypt_with_private_key(encrypted.as_slice(), &mut decrypt_buffer, key).await.unwrap();
|
if age_decrypt_with_private_key(encrypted.as_slice(), &mut decrypt_buffer, key).await.is_err() {
|
||||||
|
return Err(ServiceError::CryptoDecryptFailed);
|
||||||
|
};
|
||||||
|
|
||||||
Ok(String::from_utf8(decrypt_buffer).ok().unwrap())
|
String::from_utf8(decrypt_buffer).map_err(|_| ServiceError::CryptoDecryptFailed)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn encrypt_file_with_recipients<P: AsRef<Path>>(
|
pub async fn encrypt_file_with_recipients<P: AsRef<Path>>(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue