@@ -29,8 +29,7 @@ from publickey cimport PyPublicKeySystem
2929from utils cimport to_bytes, to_str, handle_error_codes
3030from statinfo cimport StatInfo
3131from knownhost cimport PyKnownHost
32- IF EMBEDDED_LIB:
33- from fileinfo cimport FileInfo
32+ from fileinfo cimport FileInfo
3433
3534
3635cimport c_ssh2
@@ -43,20 +42,12 @@ LIBSSH2_SESSION_BLOCK_OUTBOUND = c_ssh2.LIBSSH2_SESSION_BLOCK_OUTBOUND
4342
4443LIBSSH2_HOSTKEY_HASH_MD5 = c_ssh2.LIBSSH2_HOSTKEY_HASH_MD5
4544LIBSSH2_HOSTKEY_HASH_SHA1 = c_ssh2.LIBSSH2_HOSTKEY_HASH_SHA1
46- IF EMBEDDED_LIB:
47- LIBSSH2_HOSTKEY_HASH_SHA256 = c_ssh2.LIBSSH2_HOSTKEY_HASH_SHA256
48- LIBSSH2_HOSTKEY_TYPE_ECDSA_256 = c_ssh2.LIBSSH2_HOSTKEY_TYPE_ECDSA_256
49- LIBSSH2_HOSTKEY_TYPE_ECDSA_384 = c_ssh2.LIBSSH2_HOSTKEY_TYPE_ECDSA_384
50- LIBSSH2_HOSTKEY_TYPE_ECDSA_521 = c_ssh2.LIBSSH2_HOSTKEY_TYPE_ECDSA_521
51- LIBSSH2_HOSTKEY_TYPE_ED25519 = c_ssh2.LIBSSH2_HOSTKEY_TYPE_ED25519
52- ELSE :
53- LIBSSH2_HOSTKEY_HASH_SHA256 = None
54- LIBSSH2_HOSTKEY_HASH_SHA256 = None
55- LIBSSH2_HOSTKEY_TYPE_ECDSA_256 = None
56- LIBSSH2_HOSTKEY_TYPE_ECDSA_384 = None
57- LIBSSH2_HOSTKEY_TYPE_ECDSA_521 = None
58- LIBSSH2_HOSTKEY_TYPE_ED25519 = None
45+ LIBSSH2_HOSTKEY_HASH_SHA256 = c_ssh2.LIBSSH2_HOSTKEY_HASH_SHA256
5946
47+ LIBSSH2_HOSTKEY_TYPE_ECDSA_256 = c_ssh2.LIBSSH2_HOSTKEY_TYPE_ECDSA_256
48+ LIBSSH2_HOSTKEY_TYPE_ECDSA_384 = c_ssh2.LIBSSH2_HOSTKEY_TYPE_ECDSA_384
49+ LIBSSH2_HOSTKEY_TYPE_ECDSA_521 = c_ssh2.LIBSSH2_HOSTKEY_TYPE_ECDSA_521
50+ LIBSSH2_HOSTKEY_TYPE_ED25519 = c_ssh2.LIBSSH2_HOSTKEY_TYPE_ED25519
6051LIBSSH2_HOSTKEY_TYPE_UNKNOWN = c_ssh2.LIBSSH2_HOSTKEY_TYPE_UNKNOWN
6152LIBSSH2_HOSTKEY_TYPE_RSA = c_ssh2.LIBSSH2_HOSTKEY_TYPE_RSA
6253LIBSSH2_HOSTKEY_TYPE_DSS = c_ssh2.LIBSSH2_HOSTKEY_TYPE_DSS
@@ -67,17 +58,16 @@ cdef class MethodType:
6758 self .value = value
6859
6960
70- IF EMBEDDED_LIB:
71- LIBSSH2_METHOD_KEX = MethodType(c_ssh2.LIBSSH2_METHOD_KEX)
72- LIBSSH2_METHOD_HOSTKEY = MethodType(c_ssh2.LIBSSH2_METHOD_HOSTKEY)
73- LIBSSH2_METHOD_CRYPT_CS = MethodType(c_ssh2.LIBSSH2_METHOD_CRYPT_CS)
74- LIBSSH2_METHOD_CRYPT_SC = MethodType(c_ssh2.LIBSSH2_METHOD_CRYPT_SC)
75- LIBSSH2_METHOD_MAC_CS = MethodType(c_ssh2.LIBSSH2_METHOD_MAC_CS)
76- LIBSSH2_METHOD_MAC_SC = MethodType(c_ssh2.LIBSSH2_METHOD_MAC_SC)
77- LIBSSH2_METHOD_COMP_CS = MethodType(c_ssh2.LIBSSH2_METHOD_COMP_CS)
78- LIBSSH2_METHOD_COMP_SC = MethodType(c_ssh2.LIBSSH2_METHOD_COMP_SC)
79- LIBSSH2_METHOD_LANG_CS = MethodType(c_ssh2.LIBSSH2_METHOD_LANG_CS)
80- LIBSSH2_METHOD_LANG_SC = MethodType(c_ssh2.LIBSSH2_METHOD_LANG_SC)
61+ LIBSSH2_METHOD_KEX = MethodType(c_ssh2.LIBSSH2_METHOD_KEX)
62+ LIBSSH2_METHOD_HOSTKEY = MethodType(c_ssh2.LIBSSH2_METHOD_HOSTKEY)
63+ LIBSSH2_METHOD_CRYPT_CS = MethodType(c_ssh2.LIBSSH2_METHOD_CRYPT_CS)
64+ LIBSSH2_METHOD_CRYPT_SC = MethodType(c_ssh2.LIBSSH2_METHOD_CRYPT_SC)
65+ LIBSSH2_METHOD_MAC_CS = MethodType(c_ssh2.LIBSSH2_METHOD_MAC_CS)
66+ LIBSSH2_METHOD_MAC_SC = MethodType(c_ssh2.LIBSSH2_METHOD_MAC_SC)
67+ LIBSSH2_METHOD_COMP_CS = MethodType(c_ssh2.LIBSSH2_METHOD_COMP_CS)
68+ LIBSSH2_METHOD_COMP_SC = MethodType(c_ssh2.LIBSSH2_METHOD_COMP_SC)
69+ LIBSSH2_METHOD_LANG_CS = MethodType(c_ssh2.LIBSSH2_METHOD_LANG_CS)
70+ LIBSSH2_METHOD_LANG_SC = MethodType(c_ssh2.LIBSSH2_METHOD_LANG_SC)
8171
8272
8373cdef void kbd_callback(const char * name, int name_len,
@@ -278,30 +268,29 @@ cdef class Session:
278268 _privatekey, _passphrase, _hostname)
279269 return handle_error_codes(rc)
280270
281- IF EMBEDDED_LIB:
282- def userauth_publickey_frommemory (
283- self , username , bytes privatekeyfiledata ,
284- passphrase = ' ' , bytes publickeyfiledata = None ):
285- cdef int rc
286- cdef bytes b_username = to_bytes(username)
287- cdef bytes b_passphrase = to_bytes(passphrase)
288- cdef char * _username = b_username
289- cdef char * _passphrase = b_passphrase
290- cdef char * _publickeyfiledata = NULL
291- cdef char * _privatekeyfiledata = privatekeyfiledata
292- cdef size_t username_len, privatekeydata_len
293- cdef size_t pubkeydata_len = 0
294- username_len, privatekeydata_len = \
295- len (b_username), len (privatekeyfiledata)
296- if publickeyfiledata is not None :
297- _publickeyfiledata = publickeyfiledata
298- pubkeydata_len = len (publickeyfiledata)
299- with nogil:
300- rc = c_ssh2.libssh2_userauth_publickey_frommemory(
301- self ._session, _username, username_len, _publickeyfiledata,
302- pubkeydata_len, _privatekeyfiledata,
303- privatekeydata_len, _passphrase)
304- return handle_error_codes(rc)
271+ def userauth_publickey_frommemory (
272+ self , username , bytes privatekeyfiledata ,
273+ passphrase = ' ' , bytes publickeyfiledata = None ):
274+ cdef int rc
275+ cdef bytes b_username = to_bytes(username)
276+ cdef bytes b_passphrase = to_bytes(passphrase)
277+ cdef char * _username = b_username
278+ cdef char * _passphrase = b_passphrase
279+ cdef char * _publickeyfiledata = NULL
280+ cdef char * _privatekeyfiledata = privatekeyfiledata
281+ cdef size_t username_len, privatekeydata_len
282+ cdef size_t pubkeydata_len = 0
283+ username_len, privatekeydata_len = \
284+ len (b_username), len (privatekeyfiledata)
285+ if publickeyfiledata is not None :
286+ _publickeyfiledata = publickeyfiledata
287+ pubkeydata_len = len (publickeyfiledata)
288+ with nogil:
289+ rc = c_ssh2.libssh2_userauth_publickey_frommemory(
290+ self ._session, _username, username_len, _publickeyfiledata,
291+ pubkeydata_len, _privatekeyfiledata,
292+ privatekeydata_len, _passphrase)
293+ return handle_error_codes(rc)
305294
306295 def userauth_password (self , username not None , password not None ):
307296 """ Perform password authentication
@@ -557,15 +546,14 @@ cdef class Session:
557546 self ._session)
558547 return rc
559548
560- IF EMBEDDED_LIB:
561- def set_last_error (self , int errcode , errmsg not None ):
562- cdef bytes b_errmsg = to_bytes(errmsg)
563- cdef char * _errmsg = b_errmsg
564- cdef int rc
565- with nogil:
566- rc = c_ssh2.libssh2_session_set_last_error(
567- self ._session, errcode, _errmsg)
568- return rc
549+ def set_last_error (self , int errcode , errmsg not None ):
550+ cdef bytes b_errmsg = to_bytes(errmsg)
551+ cdef char * _errmsg = b_errmsg
552+ cdef int rc
553+ with nogil:
554+ rc = c_ssh2.libssh2_session_set_last_error(
555+ self ._session, errcode, _errmsg)
556+ return rc
569557
570558 def scp_recv (self , path not None ):
571559 """ Receive file via SCP.
@@ -589,28 +577,26 @@ cdef class Session:
589577 self ._session))
590578 return PyChannel(channel, self ), statinfo
591579
592- IF EMBEDDED_LIB:
593- def scp_recv2 (self , path not None ):
594- """ Receive file via SCP.
595-
596- Available only on libssh2 >= 1.7.
580+ def scp_recv2 (self , path not None ):
581+ """ Receive file via SCP.
597582
598- :param path: File path to receive.
599- :type path: str
583+ :param path: File path to receive.
584+ :type path: str
600585
601- :rtype: tuple(:py:class:`ssh2.channel.Channel`,
602- :py:class:`ssh2.fileinfo.FileInfo`) or ``None``"""
603- cdef FileInfo fileinfo = FileInfo()
604- cdef bytes b_path = to_bytes(path)
605- cdef char * _path = b_path
606- cdef c_ssh2.LIBSSH2_CHANNEL * channel
607- with nogil:
608- channel = c_ssh2.libssh2_scp_recv2(
609- self ._session, _path, fileinfo._stat)
610- if channel is NULL :
611- return handle_error_codes(c_ssh2.libssh2_session_last_errno(
612- self ._session))
613- return PyChannel(channel, self ), fileinfo
586+ :rtype: tuple(:py:class:`ssh2.channel.Channel`,
587+ :py:class:`ssh2.fileinfo.FileInfo`) or ``None``
588+ """
589+ cdef FileInfo fileinfo = FileInfo()
590+ cdef bytes b_path = to_bytes(path)
591+ cdef char * _path = b_path
592+ cdef c_ssh2.LIBSSH2_CHANNEL * channel
593+ with nogil:
594+ channel = c_ssh2.libssh2_scp_recv2(
595+ self ._session, _path, fileinfo._stat)
596+ if channel is NULL :
597+ return handle_error_codes(c_ssh2.libssh2_session_last_errno(
598+ self ._session))
599+ return PyChannel(channel, self ), fileinfo
614600
615601 def scp_send (self , path not None , int mode , size_t size ):
616602 """ Deprecated in favour of scp_send64. Send file via SCP.
0 commit comments