@@ -18,8 +18,10 @@ from cpython cimport PyObject_AsFileDescriptor
1818from libc.stdlib cimport malloc, free
1919from libc.string cimport const_char
2020
21- from utils cimport to_bytes, to_str, handle_error_codes
21+ from utils cimport to_bytes, to_str, handle_ssh_error_codes, \
22+ handle_auth_error_codes
2223from options cimport Option
24+ from key cimport SSHKey
2325
2426from exceptions import OptionError
2527
@@ -43,7 +45,7 @@ cdef class Session:
4345 cdef int rc
4446 with nogil:
4547 rc = c_ssh.ssh_blocking_flush(self ._session, timeout)
46- return handle_error_codes (rc, self ._session)
48+ return handle_ssh_error_codes (rc, self ._session)
4749
4850 def new_channel (self ):
4951 cdef c_ssh.ssh_channel _channel
@@ -54,7 +56,7 @@ cdef class Session:
5456 cdef int rc
5557 with nogil:
5658 rc = c_ssh.ssh_connect(self ._session)
57- return handle_error_codes (rc, self ._session)
59+ return handle_ssh_error_codes (rc, self ._session)
5860
5961 def disconnect (self ):
6062 with nogil:
@@ -78,7 +80,7 @@ cdef class Session:
7880 with nogil:
7981 rc = c_ssh.ssh_channel_cancel_forward(
8082 self ._session, c_address, port)
81- return handle_error_codes (rc, self ._session)
83+ return handle_ssh_error_codes (rc, self ._session)
8284
8385 def listen_forward (self , address , int port , int bound_port ):
8486 cdef bytes b_address = to_bytes(address)
@@ -87,7 +89,7 @@ cdef class Session:
8789 with nogil:
8890 rc = c_ssh.ssh_channel_listen_forward(
8991 self ._session, c_address, port, & bound_port)
90- return handle_error_codes (rc, self ._session)
92+ return handle_ssh_error_codes (rc, self ._session)
9193
9294 def get_disconnect_message (self ):
9395 cdef const char * message
@@ -160,7 +162,7 @@ cdef class Session:
160162 cdef int rc
161163 with nogil:
162164 rc = c_ssh.ssh_options_copy(self ._session, & destination._session)
163- return handle_error_codes (rc, self ._session)
165+ return handle_ssh_error_codes (rc, self ._session)
164166
165167 def options_getopt (self ):
166168 raise NotImplementedError
@@ -171,14 +173,14 @@ cdef class Session:
171173 cdef int rc
172174 with nogil:
173175 rc = c_ssh.ssh_options_parse_config(self ._session, c_filepath)
174- return handle_error_codes (rc, self ._session)
176+ return handle_ssh_error_codes (rc, self ._session)
175177
176178 def options_set_port (self , int port ):
177179 cdef int rc
178180 with nogil:
179181 rc = c_ssh.ssh_options_set(
180182 self ._session, c_ssh.ssh_options_e.SSH_OPTIONS_PORT, & port)
181- return handle_error_codes (rc, self ._session)
183+ return handle_ssh_error_codes (rc, self ._session)
182184
183185 def options_set (self , Option option , value ):
184186 """ Set an option for session.
@@ -193,7 +195,7 @@ cdef class Session:
193195 c_value = b_value
194196 with nogil:
195197 rc = c_ssh.ssh_options_set(self ._session, option._option, c_value)
196- return handle_error_codes (rc, self ._session)
198+ return handle_ssh_error_codes (rc, self ._session)
197199
198200 def options_get (self , Option option ):
199201 cdef char * _value
@@ -214,22 +216,22 @@ cdef class Session:
214216 cdef int rc
215217 with nogil:
216218 rc = c_ssh.ssh_options_get_port(self ._session, & port_target)
217- return handle_error_codes (rc, self ._session)
219+ return handle_ssh_error_codes (rc, self ._session)
218220
219221 def send_ignore (self , bytes data ):
220222 cdef char * c_data = data
221223 cdef int rc
222224 with nogil:
223225 rc = c_ssh.ssh_send_ignore(self ._session, c_data)
224- return handle_error_codes (rc, self ._session)
226+ return handle_ssh_error_codes (rc, self ._session)
225227
226228 def send_debug (self , bytes message , int always_display ):
227229 cdef char * c_message = message
228230 cdef int rc
229231 with nogil:
230232 rc = c_ssh.ssh_send_debug(
231233 self ._session, c_message, always_display)
232- return handle_error_codes (rc, self ._session)
234+ return handle_ssh_error_codes (rc, self ._session)
233235
234236 def gssapi_set_creds (self , creds ):
235237 raise NotImplementedError
@@ -239,7 +241,7 @@ cdef class Session:
239241 cdef char * c_service = service
240242 with nogil:
241243 rc = c_ssh.ssh_service_request(self ._session, c_service)
242- return handle_error_codes (rc, self ._session)
244+ return handle_ssh_error_codes (rc, self ._session)
243245
244246 def set_agent_channel (self , channel ):
245247 raise NotImplementedError
@@ -248,7 +250,7 @@ cdef class Session:
248250 cdef int rc
249251 with nogil:
250252 rc = c_ssh.ssh_set_agent_socket(self ._session, fd)
251- return handle_error_codes (rc, self ._session)
253+ return handle_ssh_error_codes (rc, self ._session)
252254
253255 def set_blocking (self , int blocking ):
254256 with nogil:
@@ -278,44 +280,44 @@ cdef class Session:
278280 cdef int rc
279281 with nogil:
280282 rc = c_ssh.ssh_userauth_none(self ._session, NULL )
281- return handle_error_codes (rc, self ._session)
283+ return handle_ssh_error_codes (rc, self ._session)
282284
283285 def userauth_list (self ):
284286 cdef int rc
285287 with nogil:
286288 rc = c_ssh.ssh_userauth_list(self ._session, NULL )
287- return handle_error_codes (rc, self ._session)
289+ return handle_ssh_error_codes (rc, self ._session)
288290
289- def userauth_try_publickey (self , username , pubkey ):
290- cdef bytes b_username = to_bytes(username)
291- cdef char * c_username = b_username
291+ def userauth_try_publickey (self , SSHKey pubkey ):
292292 cdef int rc
293- raise NotImplementedError
293+ with nogil:
294+ rc = c_ssh.ssh_userauth_try_publickey(
295+ self ._session, NULL , pubkey._key)
296+ return handle_auth_error_codes(rc, self ._session)
294297
295- def userauth_publickey (self , username , privkey ):
296- cdef bytes b_username = to_bytes(username)
297- cdef char * c_username = b_username
298+ def userauth_publickey (self , SSHKey privkey ):
298299 cdef int rc
299- raise NotImplementedError
300+ with nogil:
301+ rc = c_ssh.ssh_userauth_publickey(
302+ self ._session, NULL , privkey._key)
303+ return handle_auth_error_codes(rc, self ._session)
300304
301305 def userauth_agent (self , username ):
302306 cdef bytes b_username = to_bytes(username)
303307 cdef char * c_username = b_username
304308 cdef int rc
305309 with nogil:
306310 rc = c_ssh.ssh_userauth_agent(self ._session, c_username)
307- return handle_error_codes (rc, self ._session)
311+ return handle_ssh_error_codes (rc, self ._session)
308312
309- def userauth_publickey_auto (self , username , passphrase ):
310- cdef bytes b_username = to_bytes(username)
313+ def userauth_publickey_auto (self , passphrase ):
311314 cdef bytes b_passphrase = to_bytes(passphrase)
312- cdef char * c_username = b_username
313315 cdef char * c_passphrase = b_passphrase
314316 cdef int rc
315317 with nogil:
316318 rc = c_ssh.ssh_userauth_publickey_auto(
317- self ._session, c_username , c_passphrase)
318- return handle_error_codes (rc, self ._session)
319+ self ._session, NULL , c_passphrase)
320+ return handle_ssh_error_codes (rc, self ._session)
319321
320322 def userauth_password (self , username , password ):
321323 cdef bytes b_username = to_bytes(username)
@@ -326,7 +328,7 @@ cdef class Session:
326328 with nogil:
327329 rc = c_ssh.ssh_userauth_password(
328330 self ._session, c_username, c_password)
329- return handle_error_codes (rc, self ._session)
331+ return handle_ssh_error_codes (rc, self ._session)
330332
331333 def userauth_kbdint (self , username , submethods ):
332334 cdef bytes b_username = to_bytes(username)
@@ -337,13 +339,14 @@ cdef class Session:
337339 with nogil:
338340 rc = c_ssh.ssh_userauth_kbdint(
339341 self ._session, c_username, c_submethods)
340- return handle_error_codes (rc, self ._session)
342+ return handle_ssh_error_codes (rc, self ._session)
341343
342344 def userauth_kbdint_getinstruction (self ):
343345 cdef bytes b_instruction
344346 cdef const_char * _instruction
345347 with nogil:
346- _instruction = c_ssh.ssh_userauth_kbdint_getinstruction(self ._session)
348+ _instruction = c_ssh.ssh_userauth_kbdint_getinstruction(
349+ self ._session)
347350 b_instruction = to_str(< char * > _instruction)
348351 return b_instruction
349352
@@ -392,19 +395,19 @@ cdef class Session:
392395 with nogil:
393396 rc = c_ssh.ssh_userauth_kbdint_setanswer(
394397 self ._session, i, < const_char * > (c_answer))
395- return handle_error_codes (rc, self ._session)
398+ return handle_ssh_error_codes (rc, self ._session)
396399
397400 def userauth_gssapi (self ):
398401 cdef int rc
399402 with nogil:
400403 rc = c_ssh.ssh_userauth_gssapi(self ._session)
401- return handle_error_codes (rc, self ._session)
404+ return handle_ssh_error_codes (rc, self ._session)
402405
403406 def write_knownhost (self ):
404407 cdef int rc
405408 with nogil:
406409 rc = c_ssh.ssh_write_knownhost(self ._session)
407- return handle_error_codes (rc, self ._session)
410+ return handle_ssh_error_codes (rc, self ._session)
408411
409412 def dump_knownhost (self ):
410413 cdef const_char * _known_host
0 commit comments