Commit d00ecd4d6b

d00ecd4d6b3e8227f72943711d47c98c3be6c892

parent: 73656c0b1c

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2021-06-09 19:46 UTC

feat(commands): Show the verification state of our devices

Layout: unified · split

src/server.rs +76 −15
@@ -874,6 +874,12 @@ impl InnerServer {
874874 }
875875
876876 pub async fn devices(&self) {
877 enum DeviceTrust {
878 Verified,
879 Unverified,
880 Unsupported,
881 }
882
877883 if let Some(c) = self.connection() {
878884 let mut response = match c.devices().await {
879885 Ok(r) => r,
@@ -949,32 +955,87 @@ impl InnerServer {
949955 d.get_key(DeviceKeyAlgorithm::Ed25519).cloned()
950956 })
951957 .flatten()
952 }
953 .unwrap_or_else(|| "-".to_owned());
958 };
959
960 let verified = if is_own_device {
961 DeviceTrust::Verified
962 } else {
963 c.client()
964 .get_device(&own_user_id, &device_info.device_id)
965 .await
966 .unwrap()
967 .map(|d| {
968 if d.is_trusted() {
969 DeviceTrust::Verified
970 } else {
971 DeviceTrust::Unverified
972 }
973 })
974 .unwrap_or(DeviceTrust::Unsupported)
975 };
976
977 let verified = match verified {
978 DeviceTrust::Verified => {
979 format!(
980 "{}Trusted{}",
981 Weechat::color("green"),
982 Weechat::color("reset")
983 )
984 }
985 DeviceTrust::Unverified => {
986 format!(
987 "{}Not trusted{}",
988 Weechat::color("red"),
989 Weechat::color("reset")
990 )
991 }
992 DeviceTrust::Unsupported => {
993 format!(
994 "{}No encryption support{}",
995 Weechat::color("darkgray"),
996 Weechat::color("reset")
997 )
998 }
999 };
9541000
955 let fingerprint = fingerprint
956 .chars()
957 .collect::<Vec<char>>()
958 .chunks(4)
959 .map(|c| c.iter().collect::<String>())
960 .collect::<Vec<String>>()
961 .join(" ");
1001 let fingerprint = if let Some(fingerprint) = fingerprint {
1002 let fingerprint = fingerprint
1003 .chars()
1004 .collect::<Vec<char>>()
1005 .chunks(4)
1006 .map(|c| c.iter().collect::<String>())
1007 .collect::<Vec<String>>()
1008 .join(" ");
1009
1010 format!(
1011 "{}{}{}",
1012 Weechat::color("magenta"),
1013 fingerprint,
1014 Weechat::color("reset")
1015 )
1016 } else {
1017 format!(
1018 "{}-{}",
1019 Weechat::color("darkgray"),
1020 Weechat::color("reset")
1021 )
1022 };
9621023
9631024 let info = format!(
9641025 " \
9651026 Name: {}{}\n \
966 Device ID: {}{}{}\n \
967 Last seen: {}\n\
968 Fingerprint: {}{}{}\n",
1027 Device ID: {}{}{}\n \
1028 Security: {}\n\
1029 Fingerprint: {}\n \
1030 Last seen: {}\n",
9691031 bold,
9701032 device_info.display_name.as_deref().unwrap_or(""),
9711033 Weechat::color(&color),
9721034 device_info.device_id.as_str(),
9731035 Weechat::color("reset"),
974 last_seen,
975 Weechat::color("magenta"),
1036 verified,
9761037 fingerprint,
977 Weechat::color("reset"),
1038 last_seen,
9781039 );
9791040
9801041 lines.push(info);