Skip to content

Commit

Permalink
ssh-key: add DotSsh::{write_private_key, write_public_key} (#259)
Browse files Browse the repository at this point in the history
Adds helpers for writing private/public key files into `~/.ssh`
  • Loading branch information
tarcieri authored Jul 30, 2024
1 parent 31a2858 commit e4198f5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ssh-key/src/dot_ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ impl DotSsh {
.ok()?
.find(|key| key.fingerprint(fingerprint.algorithm()) == fingerprint)
}

/// Write a private key into `~/.ssh`.
pub fn write_private_key(&self, filename: impl AsRef<Path>, key: &PrivateKey) -> Result<()> {
key.write_openssh_file(&self.path.join(filename), Default::default())
}

/// Write a public key into `~/.ssh`.
pub fn write_public_key(&self, filename: impl AsRef<Path>, key: &PublicKey) -> Result<()> {
key.write_openssh_file(&self.path.join(filename))
}
}

impl Default for DotSsh {
Expand Down

0 comments on commit e4198f5

Please sign in to comment.