From 3d8488d7b4ea2ceffeed625f2fdc48c74ce0a3f8 Mon Sep 17 00:00:00 2001 From: moznion Date: Sun, 29 Nov 2020 02:09:59 +0900 Subject: [PATCH] Fix type opt handling --- code_generator/src/main.rs | 12 ++++-------- dicts/dictionary.rfc2865 | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/code_generator/src/main.rs b/code_generator/src/main.rs index 684539d..f3998af 100644 --- a/code_generator/src/main.rs +++ b/code_generator/src/main.rs @@ -413,7 +413,6 @@ fn parse_dict_file(dict_file_path: &Path) -> Result { let line_filter_re = Regex::new(r"^(?:#.*|)$").unwrap(); let tabs_re = Regex::new(r"\t+").unwrap(); let trailing_comment_re = Regex::new(r"\s*?#.+?$").unwrap(); - let spaces_re = Regex::new(r"\s+").unwrap(); let mut radius_attributes: Vec = Vec::new(); let mut radius_attribute_to_values: BTreeMap> = BTreeMap::new(); @@ -435,14 +434,11 @@ fn parse_dict_file(dict_file_path: &Path) -> Result { let kind = items[0]; match kind { ATTRIBUTE_KIND => { - let attribute_type_leaf = trailing_comment_re.replace(items[3], "").to_string(); - let type_descriptions: Vec<&str> = spaces_re.split(&attribute_type_leaf).collect(); - let mut encryption_type: Option = None; let mut has_tag = false; - if type_descriptions.len() >= 2 { + if items.len() >= 5 { // TODO consider to extract to a method - for type_opt in type_descriptions[1].split(',') { + for type_opt in items[4].split(',') { if type_opt == USER_PASSWORD_TYPE_OPT { encryption_type = Some(EncryptionType::UserPassword); continue; @@ -458,7 +454,7 @@ fn parse_dict_file(dict_file_path: &Path) -> Result { } } - let typ = match RadiusAttributeValueType::from_str(type_descriptions[0]) { + let typ = match RadiusAttributeValueType::from_str(items[3]) { Ok(t) => { if t == RadiusAttributeValueType::String { match encryption_type { @@ -475,7 +471,7 @@ fn parse_dict_file(dict_file_path: &Path) -> Result { } } Err(_) => { - return Err(format!("invalid type has come => {}", type_descriptions[0])); + return Err(format!("invalid type has come => {}", items[3])); } }; diff --git a/dicts/dictionary.rfc2865 b/dicts/dictionary.rfc2865 index 77446b6..ae87daa 100644 --- a/dicts/dictionary.rfc2865 +++ b/dicts/dictionary.rfc2865 @@ -9,7 +9,7 @@ # $Id$ # ATTRIBUTE User-Name 1 string -ATTRIBUTE User-Password 2 string encrypt=1 +ATTRIBUTE User-Password 2 string encrypt=1 ATTRIBUTE CHAP-Password 3 octets ATTRIBUTE NAS-IP-Address 4 ipaddr ATTRIBUTE NAS-Port 5 integer