Skip to content

Commit e3bd6a2

Browse files
committed
fix: implement standard FromStr trait for StrictHostKeyChecking to resolve clippy warning
1 parent 883f348 commit e3bd6a2

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async fn main() -> Result<()> {
4949
}
5050

5151
// Parse strict host key checking mode
52-
let strict_mode = StrictHostKeyChecking::from_str(&cli.strict_host_key_checking);
52+
let strict_mode = cli.strict_host_key_checking.parse().unwrap_or_default();
5353

5454
// Get command to execute
5555
let command = cli.get_command();

src/ssh/known_hosts.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use async_ssh2_tokio::ServerCheckMethod;
1616
use directories::BaseDirs;
1717
use std::path::PathBuf;
18+
use std::str::FromStr;
1819

1920
/// Get the default known_hosts file path
2021
pub fn get_default_known_hosts_path() -> Option<PathBuf> {
@@ -102,13 +103,23 @@ impl StrictHostKeyChecking {
102103
pub fn to_bool(&self) -> bool {
103104
matches!(self, Self::Yes)
104105
}
106+
}
107+
108+
impl Default for StrictHostKeyChecking {
109+
fn default() -> Self {
110+
Self::AcceptNew
111+
}
112+
}
113+
114+
impl FromStr for StrictHostKeyChecking {
115+
type Err = ();
105116

106-
pub fn from_str(s: &str) -> Self {
107-
match s.to_lowercase().as_str() {
117+
fn from_str(s: &str) -> Result<Self, Self::Err> {
118+
Ok(match s.to_lowercase().as_str() {
108119
"yes" | "true" => Self::Yes,
109120
"no" | "false" => Self::No,
110121
"accept-new" | "tofu" => Self::AcceptNew,
111122
_ => Self::AcceptNew, // Default
112-
}
123+
})
113124
}
114125
}

0 commit comments

Comments
 (0)