Skip to content

Commit

Permalink
Rename WEP to uppercase
Browse files Browse the repository at this point in the history
  • Loading branch information
jcronenberg committed Jan 25, 2024
1 parent 501e381 commit 410267b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion rust/agama-dbus-server/src/network/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum NetworkStateError {
#[error("Unexpected configuration")]
UnexpectedConfiguration,
#[error("Invalid WEP authentication algorithm: '{0}'")]
InvalidWepAuthAlg(String),
InvalidWEPAuthAlg(String),
}

impl From<NetworkStateError> for zbus::fdo::Error {
Expand Down
34 changes: 17 additions & 17 deletions rust/agama-dbus-server/src/network/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ pub struct WirelessConfig {
pub band: Option<WirelessBand>,
pub channel: Option<u32>,
pub bssid: Option<macaddr::MacAddr6>,
pub wep_security: Option<WepSecurity>,
pub wep_security: Option<WEPSecurity>,
}

impl TryFrom<ConnectionConfig> for WirelessConfig {
Expand Down Expand Up @@ -830,51 +830,51 @@ impl TryFrom<&str> for SecurityProtocol {
}

#[derive(Debug, Default, PartialEq, Clone)]
pub struct WepSecurity {
pub auth_alg: WepAuthAlg,
pub wep_key_type: WepKeyType,
pub struct WEPSecurity {
pub auth_alg: WEPAuthAlg,
pub wep_key_type: WEPKeyType,
pub keys: Vec<String>,
pub wep_key_index: u32,
}

#[derive(Debug, Default, PartialEq, Clone)]
pub enum WepKeyType {
pub enum WEPKeyType {
#[default]
Unknown = 0,
Key = 1,
Passphrase = 2,
}

#[derive(Debug, Default, PartialEq, Clone)]
pub enum WepAuthAlg {
pub enum WEPAuthAlg {
#[default]
Unset,
Open,
Shared,
Leap,
}

impl TryFrom<&str> for WepAuthAlg {
impl TryFrom<&str> for WEPAuthAlg {
type Error = NetworkStateError;

fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"open" => Ok(WepAuthAlg::Open),
"shared" => Ok(WepAuthAlg::Shared),
"leap" => Ok(WepAuthAlg::Leap),
"" => Ok(WepAuthAlg::Unset),
_ => Err(NetworkStateError::InvalidWepAuthAlg(value.to_string())),
"open" => Ok(WEPAuthAlg::Open),
"shared" => Ok(WEPAuthAlg::Shared),
"leap" => Ok(WEPAuthAlg::Leap),
"" => Ok(WEPAuthAlg::Unset),
_ => Err(NetworkStateError::InvalidWEPAuthAlg(value.to_string())),
}
}
}

impl fmt::Display for WepAuthAlg {
impl fmt::Display for WEPAuthAlg {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = match &self {
WepAuthAlg::Open => "open",
WepAuthAlg::Shared => "shared",
WepAuthAlg::Leap => "shared",
WepAuthAlg::Unset => "",
WEPAuthAlg::Open => "open",
WEPAuthAlg::Shared => "shared",
WEPAuthAlg::Leap => "shared",
WEPAuthAlg::Unset => "",
};
write!(f, "{}", name)
}
Expand Down
34 changes: 17 additions & 17 deletions rust/agama-dbus-server/src/network/nm/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,28 +614,28 @@ fn wireless_config_from_dbus(conn: &OwnedNestedHash) -> Option<WirelessConfig> {
let wep_key_type: u32 = *wep_key_type.downcast_ref()?;
match wep_key_type {
// 0 shouldn't appear because it is treated as empty but just in case
0 => WepKeyType::Unknown,
1 => WepKeyType::Key,
2 => WepKeyType::Passphrase,
0 => WEPKeyType::Unknown,
1 => WEPKeyType::Key,
2 => WEPKeyType::Passphrase,
_ => {
log::error!("\"wep-key-type\" from NetworkManager not valid");
WepKeyType::default()
WEPKeyType::default()
}
}
} else {
WepKeyType::default()
WEPKeyType::default()
};
let auth_alg = if let Some(auth_alg) = security.get("auth-alg") {
WepAuthAlg::try_from(auth_alg.downcast_ref()?).ok()?
WEPAuthAlg::try_from(auth_alg.downcast_ref()?).ok()?
} else {
WepAuthAlg::default()
WEPAuthAlg::default()
};
let wep_key_index: u32 = if let Some(wep_key_index) = security.get("wep-tx-keyidx") {
*wep_key_index.downcast_ref()?
} else {
0
};
wireless_config.wep_security = Some(WepSecurity {
wireless_config.wep_security = Some(WEPSecurity {
wep_key_type,
auth_alg,
wep_key_index,
Expand Down Expand Up @@ -899,7 +899,7 @@ mod test {
("key-mgmt".to_string(), Value::new("wpa-psk").to_owned()),
(
"wep-key-type".to_string(),
Value::new(WepKeyType::Key as u32).to_owned(),
Value::new(WEPKeyType::Key as u32).to_owned(),
),
("auth-alg".to_string(), Value::new("open").to_owned()),
("wep-tx-keyidx".to_string(), Value::new(1_u32).to_owned()),
Expand All @@ -925,8 +925,8 @@ mod test {
Some(macaddr::MacAddr6::from_str("12:34:56:78:9A:BC").unwrap())
);
let wep_security = wireless.wep_security.as_ref().unwrap();
assert_eq!(wep_security.wep_key_type, WepKeyType::Key);
assert_eq!(wep_security.auth_alg, WepAuthAlg::Open);
assert_eq!(wep_security.wep_key_type, WEPKeyType::Key);
assert_eq!(wep_security.auth_alg, WEPAuthAlg::Open);
assert_eq!(wep_security.wep_key_index, 1);
}
}
Expand Down Expand Up @@ -965,9 +965,9 @@ mod test {
band: Some(WirelessBand::BG),
channel: Some(10),
bssid: Some(macaddr::MacAddr6::from_str("12:34:56:78:9A:BC").unwrap()),
wep_security: Some(WepSecurity {
auth_alg: WepAuthAlg::Open,
wep_key_type: WepKeyType::Key,
wep_security: Some(WEPSecurity {
auth_alg: WEPAuthAlg::Open,
wep_key_type: WEPKeyType::Key,
wep_key_index: 1,
keys: vec![
"5b73215e232f4c577c5073455d".to_string(),
Expand Down Expand Up @@ -1019,21 +1019,21 @@ mod test {
let password: &str = security.get("psk").unwrap().downcast_ref().unwrap();
assert_eq!(password, "wpa-password");

let auth_alg: WepAuthAlg = security
let auth_alg: WEPAuthAlg = security
.get("auth-alg")
.unwrap()
.downcast_ref::<str>()
.unwrap()
.try_into()
.unwrap();
assert_eq!(auth_alg, WepAuthAlg::Open);
assert_eq!(auth_alg, WEPAuthAlg::Open);

let wep_key_type: u32 = *security
.get("wep-key-type")
.unwrap()
.downcast_ref::<u32>()
.unwrap();
assert_eq!(wep_key_type, WepKeyType::Key as u32);
assert_eq!(wep_key_type, WEPKeyType::Key as u32);

let wep_key_index: u32 = *security
.get("wep-tx-keyidx")
Expand Down

0 comments on commit 410267b

Please sign in to comment.