8000 Fix caching_sha2_password didn't work with PY2 (#701) · vicdeveloper/PyMySQL@24f093a · GitHub
[go: up one dir, main page]

Skip to content

Commit 24f093a

Browse files
authored
Fix caching_sha2_password didn't work with PY2 (PyMySQL#701)
Fixes PyMySQL#700
1 parent 2fb8b1b commit 24f093a

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pymysql/_auth.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Implements auth methods
33
"""
4-
from ._compat import text_type
4+
from ._compat import text_type, PY2
55
from .constants import CLIENT
66
from .err import OperationalError
77

@@ -38,15 +38,14 @@ def scramble_native_password(password, message):
3838

3939

4040
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)
5049

5150

5251
# old_passwords support ported from libmysql/password.c
@@ -186,6 +185,8 @@ def scramble_caching_sha2(password, nonce):
186185
p3 = hashlib.sha256(p2 + nonce).digest()
187186

188187
res = bytearray(p1)
188+
if PY2:
189+
p3 = bytearray(p3)
189190
for i in range(len(p3)):
190191
res[i] ^= p3[i]
191192

0 commit comments

Comments
 (0)
0