Updated DecryptedAccount::validate to use an all method of the iterators

This commit is contained in:
StNicolay 2023-06-04 18:19:54 +03:00
parent 593f438435
commit cc41fbbaa4
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D

View File

@ -4,6 +4,8 @@ use cryptography::prelude::*;
use entity::prelude::*;
use serde::{Deserialize, Serialize};
use crate::utils::validate_field;
#[derive(Serialize, Deserialize)]
pub struct DecryptedAccount {
pub name: String,
@ -43,15 +45,9 @@ impl DecryptedAccount {
/// Returns true if the account's fields are valid
#[inline]
pub fn validate(&self) -> bool {
for string in [&self.name, &self.login, &self.password] {
let is_invalid = string
.chars()
.any(|char| char == '`' || char == '\\' || char == '\n');
if is_invalid {
return false;
}
}
true
[&self.name, &self.login, &self.password]
.into_iter()
.all(|field| validate_field(field))
}
}