Skip to main content

asterust_junos/system/
master_password.rs

1//! `master-password`
2//! `system { master-password { ... } }`.
3//!
4//! # See also
5//!
6//! - [master-password](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/master-password-edit-system.html)
7
8use crate::arg_of;
9use asterust::config::ConfigLine;
10
11/// The `system master-password` settings. The password itself is not extracted.
12#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct MasterPassword {
15    pub iteration_count: Option<String>,
16    /// `hmac-sha1`, `hmac-sha2-256` or `hmac-sha2-512`.
17    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}