@@ -51,9 +51,12 @@ impl FileEntry {
5151 }
5252}
5353
54- impl From < ( DBKey , & str , & str ) > for FileEntry {
55- fn from ( ( value, lib_path, file_path) : ( DBKey , & str , & str ) ) -> Self {
56- let host_template = HostTemplate :: try_from ( & value) . expect ( "change this" ) ; //TODO: change
54+ impl TryFrom < ( DBKey , & str , & str ) > for FileEntry {
55+ type Error =anyhow:: Error ;
56+
57+ fn try_from ( ( db_key, lib_path, file_path) : ( DBKey , & str , & str ) ) -> std:: prelude:: v1:: Result < Self , Self :: Error > {
58+
59+ let host_template = HostTemplate :: try_from ( & db_key) . context ( "while parsing host template from db key" ) ?;
5760
5861 let accepted_algorithms = match host_template. template {
5962 tssh_core:: tpm:: Template :: RSA ( rsa_template) => match rsa_template. keybits {
@@ -69,17 +72,21 @@ impl From<(DBKey, &str, &str)> for FileEntry {
6972 } ,
7073 } ;
7174
72- Self {
73- host : value . host ,
74- username : value . username ,
75- port : value . port ,
75+ Ok ( Self {
76+ host : db_key . host ,
77+ username : db_key . username ,
78+ port : db_key . port ,
7679 pkcs11_provider : lib_path. to_string ( ) ,
7780 identity_file : file_path. to_string ( ) ,
7881 accepted_algorithms : accepted_algorithms. to_string ( ) ,
79- }
82+ } )
83+
84+
8085 }
8186}
8287
88+
89+
8390const KEY_DIR_NAME : & str = "keys" ;
8491const SSH_FILE_NAME : & str = "ssh_file" ;
8592
@@ -111,17 +118,17 @@ where
111118 file. write_all ( x. pub_key . as_bytes ( ) )
112119 . context ( "while writing to keyfile" ) ?;
113120 ssh_file_content. push_str (
114- FileEntry :: from ( (
121+ FileEntry :: try_from ( (
115122 x,
116123 env. lib_path . to_string_lossy ( ) . to_string ( ) . as_str ( ) ,
117124 file_path. to_string_lossy ( ) . to_string ( ) . as_str ( ) ,
118- ) )
125+ ) ) ?
119126 . as_file_entry ( )
120127 . as_str ( ) ,
121128 ) ;
122129 }
123130
124- std:: fs:: write ( tssh_ssh_file_path, ssh_file_content. as_bytes ( ) ) . context ( "wile writing ssh file" )
131+ std:: fs:: write ( tssh_ssh_file_path, ssh_file_content. as_bytes ( ) ) . context ( "while writing ssh file" )
125132}
126133
127134pub fn generate_include ( env : & DirEnv ) -> Result < String > {
0 commit comments