From e4198f52adf3cc29711c768b5f030d298affc347 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Mon, 29 Jul 2024 18:52:59 -0600 Subject: [PATCH] ssh-key: add `DotSsh::{write_private_key, write_public_key}` (#259) Adds helpers for writing private/public key files into `~/.ssh` --- ssh-key/src/dot_ssh.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ssh-key/src/dot_ssh.rs b/ssh-key/src/dot_ssh.rs index 1a265bb..def9895 100644 --- a/ssh-key/src/dot_ssh.rs +++ b/ssh-key/src/dot_ssh.rs @@ -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, 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, key: &PublicKey) -> Result<()> { + key.write_openssh_file(&self.path.join(filename)) + } } impl Default for DotSsh {