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

improve comments valid identity name

parent 3aca4ecd
No related branches found
No related tags found
1 merge request!119restrict identity name
......@@ -16,15 +16,20 @@
#![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 {
idty_name.len() >= 3
&& idty_name.len() <= 64
&& idty_name[0] != 32
&& idty_name[idty_name.len() - 1] != 32
&& idty_name.len() <= 64 // length smaller than 64
&& idty_name[0] != 32 // does not start with space
&& idty_name[idty_name.len() - 1] != 32 // does not end with space
// all characters are alphanumeric or punctuation or space
&& idty_name
.iter()
.all(|c| c.is_ascii_alphanumeric() || c.is_ascii_punctuation() || *c == 32)
// disallow two consecutive spaces
&& idty_name
.iter()
.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