Skip to content

Commit 3e9f3f4

Browse files
committed
Enable copying identities between agents
The copy-identities can be used to copy identities from one agent to another. This is useful to allow copying identities from a system agent to a non system agent.
1 parent 430e6ac commit 3e9f3f4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/clj_ssh/ssh.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
PipedInputStream PipedOutputStream]
3939
[com.jcraft.jsch
4040
JSch Session Channel ChannelShell ChannelExec ChannelSftp JSchException
41-
Identity IdentityFile Logger KeyPair LocalIdentityRepository]))
41+
Identity IdentityFile IdentityRepository Logger KeyPair LocalIdentityRepository]))
4242

4343
;;; forward jsch's logging to java logging
4444
(def ^{:dynamic true}
@@ -209,6 +209,12 @@
209209
[^KeyPair keypair]
210210
(.getFingerPrint keypair))
211211

212+
(defn copy-identities
213+
[^JSch from-agent ^JSch to-agent]
214+
(let [^IdentityRepository ir (.getIdentityRepository from-agent)]
215+
(doseq [^Identity id (.getIdentities ir)]
216+
(.addIdentity to-agent id nil))))
217+
212218
;; JSch's IdentityFile has a private constructor that would let us avoid this
213219
;; were it public.
214220
(deftype KeyPairIdentity [^JSch jsch ^String identity ^KeyPair kpair]

0 commit comments

Comments
 (0)