mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-19 22:41:13 +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(
|
||||
password_encrypted: &str,
|
||||
key: &str,
|
||||
) -> Result<String, ServiceError> {
|
||||
let encrypted = base64::decode(password_encrypted).unwrap();
|
||||
) -> Result<String, ServiceError> { // TODO More specific error handling
|
||||
let Ok(encrypted) = base64::decode(password_encrypted) else {
|
||||
return Err(ServiceError::CryptoEncryptFailed);
|
||||
};
|
||||
|
||||
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>>(
|
||||
|
|
|
|||
Loading…
Reference in a new issue