File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
2
Implements auth methods
3
3
"""
4
- from ._compat import text_type
4
+ from ._compat import text_type , PY2
5
5
from .constants import CLIENT
6
6
from .err import OperationalError
7
7
@@ -38,15 +38,14 @@ def scramble_native_password(password, message):
38
38
39
39
40
40
def _my_crypt (message1 , message2 ):
41
- length = len (message1 )
42
- result = b''
43
- for i in range (length ):
44
- x = (
45
- struct .unpack ('B' , message1 [i :i + 1 ])[0 ] ^
46
- struct .unpack ('B' , message2 [i :i + 1 ])[0 ]
47
- )
48
- result += struct .pack ('B' , x )
49
- return result
41
+ result = bytearray (message1 )
42
+ if PY2 :
43
+ message2 = bytearray (message2 )
44
+
45
+ for i in range (len (result )):
46
+ result [i ] ^= message2 [i ]
47
+
48
+ return bytes (result )
50
49
51
50
52
51
# old_passwords support ported from libmysql/password.c
@@ -186,6 +185,8 @@ def scramble_caching_sha2(password, nonce):
186
185
p3 = hashlib .sha256 (p2 + nonce ).digest ()
187
186
188
187
res = bytearray (p1 )
188
+ if PY2 :
189
+ p3 = bytearray (p3 )
189
190
for i in range (len (p3 )):
190
191
res [i ] ^= p3 [i ]
191
192
You can’t perform that action at this time.
0 commit comments