Skip to content

Commit

Permalink
ssh-key: add DotSsh::{write_private_key, write_public_key}
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 committed Jul 30, 2024
1 parent f741cf0 commit 7f3947f
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 7f3947f

Please sign in to comment.