Skip to content

Commit 75c8a6d

Browse files
committed
Allow generate-keypair to write key files
1 parent bb90267 commit 75c8a6d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/clj_ssh/ssh.clj

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -932,11 +932,18 @@ cmd specifies a command to exec. Valid commands are:
932932

933933
(defn generate-keypair
934934
"Generate a keypair, returned as [private public] byte arrays.
935-
Valid types are :rsa and :dsa. key-size is in bytes. passphrase
936-
can be a string or byte array."
937-
[agent key-type key-size passphrase]
935+
Valid types are :rsa and :dsa. key-size is in bytes. passphrase can be a
936+
string or byte array. Optionally writes the keypair to the paths specified
937+
using the :private-key-path and :public-key-path keys."
938+
[agent key-type key-size passphrase
939+
& {:keys [comment private-key-path public-key-path]}]
938940
(let [keypair (KeyPair/genKeyPair agent (key-type key-types) key-size)]
939-
(when passphrase (.setPassphrase keypair passphrase))
941+
(when passphrase
942+
(.setPassphrase keypair passphrase))
943+
(when public-key-path
944+
(.writePublicKey keypair public-key-path comment))
945+
(when private-key-path
946+
(.writePrivateKey keypair private-key-path))
940947
(let [pub-baos (ByteArrayOutputStream.)
941948
pri-baos (ByteArrayOutputStream.)]
942949
(.writePublicKey keypair pub-baos "")

0 commit comments

Comments
 (0)