Skip to content
Snippets Groups Projects
Commit b1ca24ce authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

improve comments valid identity name

parent 44c22c2a
No related branches found
No related tags found
No related merge requests found
...@@ -16,15 +16,20 @@ ...@@ -16,15 +16,20 @@
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
/// Bound length; forbid trailing or double spaces; accept only ascii alphanumeric or punctuation or space /// Rules for valid identity names are defined below
/// - Bound length to 64
/// - forbid trailing or double spaces
/// - accept only ascii alphanumeric or punctuation or space
pub fn validate_idty_name(idty_name: &[u8]) -> bool { pub fn validate_idty_name(idty_name: &[u8]) -> bool {
idty_name.len() >= 3 idty_name.len() >= 3
&& idty_name.len() <= 64 && idty_name.len() <= 64 // length smaller than 64
&& idty_name[0] != 32 && idty_name[0] != 32 // does not start with space
&& idty_name[idty_name.len() - 1] != 32 && idty_name[idty_name.len() - 1] != 32 // does not end with space
// all characters are alphanumeric or punctuation or space
&& idty_name && idty_name
.iter() .iter()
.all(|c| c.is_ascii_alphanumeric() || c.is_ascii_punctuation() || *c == 32) .all(|c| c.is_ascii_alphanumeric() || c.is_ascii_punctuation() || *c == 32)
// disallow two consecutive spaces
&& idty_name && idty_name
.iter() .iter()
.zip(idty_name.iter().skip(1)) .zip(idty_name.iter().skip(1))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment