File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff line change 1515use async_ssh2_tokio:: ServerCheckMethod ;
1616use directories:: BaseDirs ;
1717use std:: path:: PathBuf ;
18+ use std:: str:: FromStr ;
1819
1920/// Get the default known_hosts file path
2021pub 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}
You can’t perform that action at this time.
0 commit comments