Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
avoid erasing key file during generation if it already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
musitdev committed Jan 21, 2024
1 parent d9353cc commit 66358b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion crates/cli/src/keyfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ use std::path::PathBuf;
pub fn create_key_file(file_path: &PathBuf) -> crate::BoxResult<()> {
let key = SecretKey::random(&mut StdRng::from_entropy());
let key_array = key.serialize();
Ok(fs::write(file_path, &key_array[..])?)
if !file_path.as_path().exists() {
Ok(fs::write(file_path, &key_array[..])?)
} else {
Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
"Key file already exist. Can't erase it.",
)))
}
}

pub fn read_key_file(file_path: &PathBuf) -> crate::BoxResult<SecretKey> {
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct ArgConfiguration {

#[derive(Subcommand, Debug)]
enum ConfCommands {
/// Deploy prover and verifier.
/// Generate a private key file using --keyfile option.
GenerateKey,

/// Deploy prover and verifier.
Expand Down

0 comments on commit 66358b2

Please sign in to comment.