File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -35,13 +35,13 @@ serde = { version = "1.0", features = ["derive"] }
3535thiserror = " 1.0"
3636unicode-truncate = " 1.0"
3737url = " 2.5"
38+ tempfile = " 3"
3839
3940[dev-dependencies ]
4041env_logger = " 0.11"
4142invalidstring = { path = " ../invalidstring" , version = " 0.1" }
4243pretty_assertions = " 1.4"
4344serial_test = " 3.2"
44- tempfile = " 3"
4545
4646[features ]
4747default = [" trace-libgit" ]
Original file line number Diff line number Diff line change @@ -186,10 +186,24 @@ impl SignBuilder {
186186 if key_path. is_file ( ) {
187187 Ok ( key_path)
188188 } else if signing_key. starts_with ( "ssh-" ) {
189- Ok ( key_path) //TODO: write key to temp file
189+ use std:: io:: Write ;
190+ use tempfile:: NamedTempFile ;
191+ let mut temp_file =
192+ NamedTempFile :: new ( ) . map_err ( |err| {
193+ SignBuilderError :: SSHSigningKey ( err. to_string ( ) )
194+ } ) ?;
195+ writeln ! ( temp_file, "{}" , signing_key) . map_err (
196+ |err| {
197+ SignBuilderError :: SSHSigningKey ( err. to_string ( ) )
198+ } ,
199+ ) ?;
200+ let temp_file = temp_file. keep ( ) . map_err ( |err| {
201+ SignBuilderError :: SSHSigningKey ( err. to_string ( ) )
202+ } ) ?;
203+ Ok ( temp_file. 1 )
190204 } else {
191205 Err ( SignBuilderError :: SSHSigningKey ( String :: from (
192- "ssh key could not be resolve . Either the key is not a file or the key is not a valid public ssh key" ,
206+ "ssh key could not been resolved . Either the key is not a file or the key is not a valid public ssh key" ,
193207 ) ) )
194208 }
195209 }
@@ -311,6 +325,8 @@ impl Sign for SSHSign {
311325 . wait_with_output ( )
312326 . map_err ( |e| SignError :: Output ( e. to_string ( ) ) ) ?;
313327
328+ //TODO: cleanup temp file if created
329+
314330 if !output. status . success ( ) {
315331 return Err ( SignError :: Shellout ( format ! (
316332 "failed to sign data, program '{}' exited non-zero: {}" ,
You can’t perform that action at this time.
0 commit comments