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"] }
35
35
thiserror = " 1.0"
36
36
unicode-truncate = " 1.0"
37
37
url = " 2.5"
38
+ tempfile = " 3"
38
39
39
40
[dev-dependencies ]
40
41
env_logger = " 0.11"
41
42
invalidstring = { path = " ../invalidstring" , version = " 0.1" }
42
43
pretty_assertions = " 1.4"
43
44
serial_test = " 3.2"
44
- tempfile = " 3"
45
45
46
46
[features ]
47
47
default = [" trace-libgit" ]
Original file line number Diff line number Diff line change @@ -186,10 +186,24 @@ impl SignBuilder {
186
186
if key_path. is_file ( ) {
187
187
Ok ( key_path)
188
188
} 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 )
190
204
} else {
191
205
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" ,
193
207
) ) )
194
208
}
195
209
}
@@ -311,6 +325,8 @@ impl Sign for SSHSign {
311
325
. wait_with_output ( )
312
326
. map_err ( |e| SignError :: Output ( e. to_string ( ) ) ) ?;
313
327
328
+ //TODO: cleanup temp file if created
329
+
314
330
if !output. status . success ( ) {
315
331
return Err ( SignError :: Shellout ( format ! (
316
332
"failed to sign data, program '{}' exited non-zero: {}" ,
You can’t perform that action at this time.
0 commit comments