encrypt return emtpy if exceed max len to avoid another encrypt

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2023-08-19 20:44:54 +08:00
parent 9cba0a0b89
commit e1ae3601c4

View File

@ -89,6 +89,9 @@ pub fn encrypt_str_or_original(s: &str, version: &str, max_len: usize) -> String
log::error!("Duplicate encryption!");
return s.to_owned();
}
if s.bytes().len() > max_len {
return String::default();
}
if version == "00" {
if let Ok(s) = encrypt(s.as_bytes(), max_len) {
return version.to_owned() + &s;
@ -122,6 +125,9 @@ pub fn encrypt_vec_or_original(v: &[u8], version: &str, max_len: usize) -> Vec<u
log::error!("Duplicate encryption!");
return v.to_owned();
}
if v.len() > max_len {
return vec![];
}
if version == "00" {
if let Ok(s) = encrypt(v, max_len) {
let mut version = version.to_owned().into_bytes();