Skip to content
Snippets Groups Projects

restrict identity name

Merged Hugo Trentesaux requested to merge hugo-comment into master
1 file
+ 9
4
Compare changes
  • Side-by-side
  • Inline
@@ -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))
Loading