File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -127,9 +127,9 @@ Licensed under EPL (http://www.eclipse.org/legal/epl-v10.html)"
127
127
(defn has-identity?
128
128
" Check if the given identity is present."
129
129
([name] (has-identity? *ssh-agent* name))
130
- ([agent name] (some #(= name %) (.getIdentityNames agent))))
130
+ ([#^JSch agent name] (some #(= name %) (.getIdentityNames agent))))
131
131
132
- (defn make-identity
132
+ (defn #^Identity make-identity
133
133
" Create a JSch identity. This can be used to check whether the key is
134
134
encrypted."
135
135
([private-key-path public-key-path]
@@ -157,7 +157,11 @@ Licensed under EPL (http://www.eclipse.org/legal/epl-v10.html)"
157
157
(if (instance? Identity private-key)
158
158
private-key
159
159
(file-path private-key))
160
- (and passphrase (.getBytes passphrase)))))
160
+ (and passphrase (.getBytes passphrase))))
161
+ ([#^JSch agent #^String name #^bytes private-key #^bytes public-key
162
+ #^bytes passphrase]
163
+ (.addIdentity
164
+ agent name private-key public-key passphrase)))
161
165
162
166
(defn add-identity-with-keychain
163
167
" Add a private key, only if not already known, using the keychain to obtain
@@ -340,7 +344,7 @@ keys. All other option key pairs will be passed as SSH config options."
340
344
(doto exec
341
345
(.setInputStream
342
346
(if (string? in)
343
- (java.io.ByteArrayInputStream. (.getBytes in))
347
+ (java.io.ByteArrayInputStream. (.getBytes #^String in))
344
348
in)
345
349
false )
346
350
(.setOutputStream out-stream)
Original file line number Diff line number Diff line change @@ -28,9 +28,15 @@ list, Alan Dipert and MeikelBrandmeyer."
28
28
(defn private-key-path
29
29
[] (str (. System getProperty " user.home" ) " /.ssh/clj_ssh" ))
30
30
31
+ (defn public-key-path
32
+ [] (str (. System getProperty " user.home" ) " /.ssh/clj_ssh.pub" ))
33
+
31
34
(defn encrypted-private-key-path
32
35
[] (str (. System getProperty " user.home" ) " /.ssh/clj_ssh_pp" ))
33
36
37
+ (defn encrypted-public-key-path
38
+ [] (str (. System getProperty " user.home" ) " /.ssh/clj_ssh_pp.pub" ))
39
+
34
40
(defn username
35
41
[] (or (. System getProperty " ssh.username" )
36
42
(. System getProperty " user.name" )))
@@ -111,7 +117,17 @@ list, Alan Dipert and MeikelBrandmeyer."
111
117
(with-ssh-agent [false ]
112
118
(add-identity key)
113
119
(is (= 1 (count (.getIdentityNames *ssh-agent*))))
114
- (add-identity *ssh-agent* key))))
120
+ (add-identity *ssh-agent* key)))
121
+ (testing " passing byte arrays"
122
+ (with-ssh-agent [false ]
123
+ (add-identity
124
+ *ssh-agent*
125
+ " name"
126
+ (.getBytes (slurp (private-key-path )))
127
+ (.getBytes (slurp (public-key-path )))
128
+ nil )
129
+ (is (= 1 (count (.getIdentityNames *ssh-agent*))))
130
+ (is (= " name" (first (.getIdentityNames *ssh-agent*)))))))
115
131
116
132
(deftest has-identity?-test
117
133
(let [key (private-key-path )]
You can’t perform that action at this time.
0 commit comments