Skip to content

Commit b254fb7

Browse files
committed
remove unused enum
1 parent 651ee02 commit b254fb7

File tree

2 files changed

+16
-34
lines changed

2 files changed

+16
-34
lines changed

resources/sshdconfig/src/metadata.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,27 @@
33

44
// keywords that can have multiple comma-separated arguments per line but cannot be repeated over multiple lines,
55
// as subsequent entries are ignored, should be represented as arrays
6-
pub const MULTI_ARG_KEYWORDS_COMMA_SEP: [&str; 10] = [
7-
"authenticationmethods",
8-
"casignaturealgorithms",
9-
"ciphers",
10-
"hostbasedacceptedalgorithms",
11-
"hostkeyalgorithms",
12-
"kexalgorithms",
13-
"macs",
14-
"permituserenvironment",
15-
"persourcepenaltyexemptlist",
16-
"pubkeyacceptedalgorithms"
17-
];
18-
19-
// keywords that can have multiple space-separated arguments per line but cannot be repeated over multiple lines,
20-
// as subsequent entries are ignored, should be represented as arrays
21-
pub const MULTI_ARG_KEYWORDS_SPACE_SEP: [&str; 12] = [
6+
pub const MULTI_ARG_KEYWORDS: [&str; 22] = [
227
"acceptenv",
238
"allowgroups",
249
"allowusers",
10+
"authenticationmethods",
2511
"authorizedkeysfile",
12+
"casignaturealgorithms",
2613
"channeltimeout",
14+
"ciphers",
2715
"denygroups",
2816
"denyusers",
17+
"hostbasedacceptedalgorithms",
18+
"hostkeyalgorithms",
2919
"ipqos",
20+
"kexalgorithms",
21+
"macs",
3022
"permitlisten",
3123
"permitopen",
24+
"permituserenvironment",
25+
"persourcepenaltyexemptlist",
26+
"pubkeyacceptedalgorithms",
3227
"persourcepenalties",
3328
"rekeylimit" // first arg is bytes, second arg (optional) is amount of time
3429
];

resources/sshdconfig/src/parser.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@ use tracing::debug;
88
use tree_sitter::Parser;
99

1010
use crate::error::SshdConfigError;
11-
use crate::metadata::{MULTI_ARG_KEYWORDS_COMMA_SEP, MULTI_ARG_KEYWORDS_SPACE_SEP, REPEATABLE_KEYWORDS};
12-
13-
#[derive(Debug, Clone, Copy, PartialEq)]
14-
enum KeywordType {
15-
CommaSeparated,
16-
SpaceSeparated,
17-
Unseparated
18-
}
11+
use crate::metadata::{MULTI_ARG_KEYWORDS, REPEATABLE_KEYWORDS};
1912

2013
#[derive(Debug, JsonSchema)]
2114
pub struct SshdConfigParser {
@@ -187,7 +180,6 @@ impl SshdConfigParser {
187180
let mut operator: Option<String> = None;
188181
let mut is_vec = false;
189182
let mut is_repeatable = false;
190-
let mut keyword_type = KeywordType::Unseparated;
191183

192184
if let Some(keyword) = keyword_node.child_by_field_name("keyword") {
193185
let Ok(text) = keyword.utf8_text(input_bytes) else {
@@ -198,13 +190,8 @@ impl SshdConfigParser {
198190
debug!("{}", t!("parser.keywordDebug", text = text).to_string());
199191
}
200192

201-
if MULTI_ARG_KEYWORDS_SPACE_SEP.contains(&text) {
202-
keyword_type = KeywordType::SpaceSeparated;
203-
} else if MULTI_ARG_KEYWORDS_COMMA_SEP.contains(&text) {
204-
keyword_type = KeywordType::CommaSeparated;
205-
}
206193
is_repeatable = REPEATABLE_KEYWORDS.contains(&text);
207-
is_vec = is_repeatable || keyword_type != KeywordType::Unseparated;
194+
is_vec = is_repeatable || MULTI_ARG_KEYWORDS.contains(&text);
208195
key = Some(text.to_string());
209196
}
210197

@@ -221,7 +208,7 @@ impl SshdConfigParser {
221208
return Err(SshdConfigError::ParserError(t!("parser.failedToParseNode", input = input).to_string()));
222209
}
223210
if node.kind() == "arguments" {
224-
value = parse_arguments_node(node, input, input_bytes, is_vec, keyword_type)?;
211+
value = parse_arguments_node(node, input, input_bytes, is_vec)?;
225212
if target_map.is_some() {
226213
debug!("{}: {:?}", t!("parser.valueDebug").to_string(), value);
227214
}
@@ -290,7 +277,7 @@ impl SshdConfigParser {
290277
}
291278
}
292279

293-
fn parse_arguments_node(arg_node: tree_sitter::Node, input: &str, input_bytes: &[u8], is_vec: bool, _keyword_type: KeywordType) -> Result<Value, SshdConfigError> {
280+
fn parse_arguments_node(arg_node: tree_sitter::Node, input: &str, input_bytes: &[u8], is_vec: bool) -> Result<Value, SshdConfigError> {
294281
let mut cursor = arg_node.walk();
295282
let mut vec: Vec<Value> = Vec::new();
296283
// if there is more than one argument, but a vector is not expected for the keyword, throw an error
@@ -323,7 +310,7 @@ fn parse_arguments_node(arg_node: tree_sitter::Node, input: &str, input_bytes: &
323310
_ => return Err(SshdConfigError::ParserError(t!("parser.unknownNode", kind = node.kind()).to_string()))
324311
}
325312
}
326-
// Always return array if is_vec is true (for MULTI_ARG_KEYWORDS_COMMA_SEP, MULTI_ARG_KEYWORDS_SPACE_SEP, and REPEATABLE_KEYWORDS)
313+
// Always return array if is_vec is true (for MULTI_ARG_KEYWORDS, and REPEATABLE_KEYWORDS)
327314
if is_vec {
328315
Ok(Value::Array(vec))
329316
} else if !vec.is_empty() {

0 commit comments

Comments
 (0)