asterust_junos/system/
master_password.rs1use crate::arg_of;
9use asterust::config::ConfigLine;
10
11#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct MasterPassword {
15 pub iteration_count: Option<String>,
16 pub pseudorandom_function: Option<String>,
18}
19
20pub(super) fn parse_master_password(master_password: &ConfigLine) -> MasterPassword {
21 MasterPassword {
22 iteration_count: arg_of(master_password, "iteration-count").map(str::to_string),
23 pseudorandom_function: arg_of(master_password, "pseudorandom-function").map(str::to_string),
24 }
25}
26
27#[cfg(test)]
28mod tests {
29 use crate::system::system;
30 use asterust::config::juniper;
31
32 #[test]
33 fn extracts_master_password_settings() {
34 let master = system(&juniper::parse_braces(
35 "system {\n master-password {\n iteration-count 500;\n pseudorandom-function hmac-sha2-256;\n }\n}\n",
36 ))
37 .unwrap()
38 .master_password
39 .unwrap();
40 assert_eq!(master.iteration_count.as_deref(), Some("500"));
41 assert_eq!(master.pseudorandom_function.as_deref(), Some("hmac-sha2-256"));
42 }
43}