fix: password reset ApplicationDetails reencryption

This commit is contained in:
Sebastian Pravda 2023-01-12 18:51:45 +01:00
parent 242f25adb5
commit 019ac766c8
No known key found for this signature in database
GPG key ID: F3BC84F08EFA3F57

View file

@ -43,9 +43,18 @@ pub struct EncryptedApplicationDetails {
impl EncryptedString { impl EncryptedString {
pub async fn new(s: &str, recipients: &Vec<String>) -> Result<Self, ServiceError> { pub async fn new(s: &str, recipients: &Vec<String>) -> Result<Self, ServiceError> {
let recipients = recipients.iter().map(|s| &**s).collect(); let recipients = recipients.iter().map(|s| &**s).collect();
match crypto::encrypt_password_with_recipients(&s, &recipients).await { let encrypted_string = crypto::encrypt_password_with_recipients(&s, &recipients).await?;
Ok(encrypted) => Ok(Self(encrypted)), Ok(Self(encrypted_string))
Err(_) => Err(ServiceError::CryptoEncryptFailed), }
pub async fn new_option(s: &str, recipients: &Vec<String>) -> Result<Option<Self>, ServiceError> {
match s.is_empty() {
true => Ok(None),
false => {
let recipients = recipients.iter().map(|s| &**s).collect();
let encrypted_s = crypto::encrypt_password_with_recipients(&s, &recipients).await?;
Ok(Some(Self(encrypted_s)))
},
} }
} }
@ -109,30 +118,30 @@ impl EncryptedCandidateDetails {
) -> Result<EncryptedCandidateDetails, ServiceError> { ) -> Result<EncryptedCandidateDetails, ServiceError> {
let birthdate_str = form.birthdate.format(NAIVE_DATE_FMT).to_string(); let birthdate_str = form.birthdate.format(NAIVE_DATE_FMT).to_string();
let d = tokio::try_join!( let d = tokio::try_join!(
EncryptedString::new(&form.name, recipients), EncryptedString::new_option(&form.name, recipients),
EncryptedString::new(&form.surname, recipients), EncryptedString::new_option(&form.surname, recipients),
EncryptedString::new(&form.birthplace, recipients), EncryptedString::new_option(&form.birthplace, recipients),
EncryptedString::new(&birthdate_str, recipients), EncryptedString::new_option(&birthdate_str, recipients),
EncryptedString::new(&form.address, recipients), EncryptedString::new_option(&form.address, recipients),
EncryptedString::new(&form.telephone, recipients), EncryptedString::new_option(&form.telephone, recipients),
EncryptedString::new(&form.citizenship, recipients), EncryptedString::new_option(&form.citizenship, recipients),
EncryptedString::new(&form.email, recipients), EncryptedString::new_option(&form.email, recipients),
EncryptedString::new(&form.sex, recipients), EncryptedString::new_option(&form.sex, recipients),
EncryptedString::new(&form.personal_id_number, recipients), EncryptedString::new_option(&form.personal_id_number, recipients),
)?; )?;
Ok( Ok(
EncryptedCandidateDetails { EncryptedCandidateDetails {
name: Some(d.0), name: d.0,
surname: Some(d.1), surname: d.1,
birthplace: Some(d.2), birthplace: d.2,
birthdate: Some(d.3), birthdate: d.3,
address: Some(d.4), address: d.4,
telephone: Some(d.5), telephone: d.5,
citizenship: Some(d.6), citizenship: d.6,
email: Some(d.7), email: d.7,
sex: Some(d.8), sex: d.8,
personal_id_number: Some(d.9), personal_id_number: d.9,
study: Some(form.study.clone()), study: Some(form.study.clone()),
} }
) )
@ -208,18 +217,18 @@ impl EncryptedParentDetails {
recipients: &Vec<String>, recipients: &Vec<String>,
) -> Result<EncryptedParentDetails, ServiceError> { ) -> Result<EncryptedParentDetails, ServiceError> {
let d = tokio::try_join!( let d = tokio::try_join!(
EncryptedString::new(&form.name, recipients), EncryptedString::new_option(&form.name, recipients),
EncryptedString::new(&form.surname, recipients), EncryptedString::new_option(&form.surname, recipients),
EncryptedString::new(&form.telephone, recipients), EncryptedString::new_option(&form.telephone, recipients),
EncryptedString::new(&form.email, recipients), EncryptedString::new_option(&form.email, recipients),
)?; )?;
Ok( Ok(
EncryptedParentDetails { EncryptedParentDetails {
name: Some(d.0), name: d.0,
surname: Some(d.1), surname: d.1,
telephone: Some(d.2), telephone: d.2,
email: Some(d.3), email: d.3,
} }
) )
} }