Skip to content

Commit 5b2e9ed

Browse files
committed
wip(external-ssh-signer): support key literal in config
1 parent 56f15d6 commit 5b2e9ed

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

asyncgit/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ serde = { version = "1.0", features = ["derive"] }
3535
thiserror = "1.0"
3636
unicode-truncate = "1.0"
3737
url = "2.5"
38+
tempfile = "3"
3839

3940
[dev-dependencies]
4041
env_logger = "0.11"
4142
invalidstring = { path = "../invalidstring", version = "0.1" }
4243
pretty_assertions = "1.4"
4344
serial_test = "3.2"
44-
tempfile = "3"
4545

4646
[features]
4747
default = ["trace-libgit"]

asyncgit/src/sync/sign.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff 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: {}",

0 commit comments

Comments
 (0)