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