Skip to content

Commit

Permalink
fix: cleanup empty key file when bailing out of generating secp256k1
Browse files Browse the repository at this point in the history
  • Loading branch information
QuinnWilton committed Mar 11, 2024
1 parent d20087f commit c44ba07
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion homestar-runtime/src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,11 @@ fn generate_key_file(path: &PathBuf, key_type: &KeyType) -> Result<()> {
Ok(mut file) => {
let key = match *key_type {
KeyType::Ed25519 => ed25519_compact::KeyPair::generate().sk.to_pem(),
KeyType::Secp256k1 => bail!("Aborting... generating secp256k1 keys is not yet supported, please provide an existing key file, or choose another key type."),
KeyType::Secp256k1 => {
std::fs::remove_file(path).expect("to delete key file");

bail!("Aborting... generating secp256k1 keys is not yet supported, please provide an existing key file, or choose another key type.")
}
};

file.write_all(key.as_bytes())
Expand Down

0 comments on commit c44ba07

Please sign in to comment.