Skip to content

Commit

Permalink
Do only set permissions mode on unix
Browse files Browse the repository at this point in the history
  • Loading branch information
adzialocha committed Aug 30, 2023
1 parent a5fd234 commit 5861077
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions aquadoggo_cli/src/key_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use std::fs::{self, File};
use std::io::{Read, Write};
use std::os::unix::fs::PermissionsExt;
use std::path::PathBuf;

use anyhow::Result;
Expand Down Expand Up @@ -44,9 +43,12 @@ fn save_key_pair_to_file(key_pair: &KeyPair, path: PathBuf) -> Result<()> {
file.sync_all()?;

// Set permission for sensitive information
let mut permissions = file.metadata()?.permissions();
permissions.set_mode(0o600);
fs::set_permissions(path, permissions)?;
if cfg!(unix) {
use std::os::unix::fs::PermissionsExt;
let mut permissions = file.metadata()?.permissions();
permissions.set_mode(0o600);
fs::set_permissions(path, permissions)?;
}

Ok(())
}
Expand Down

0 comments on commit 5861077

Please sign in to comment.