Skip to content

Commit 2873d30

Browse files
committed
Use the right method from secrets this time
1 parent fea27ad commit 2873d30

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

asyncpg/protocol/scram.pyx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,11 @@ import base64
99
import hashlib
1010
import hmac
1111
import re
12+
import secrets
1213
import stringprep
1314
import unicodedata
1415

1516

16-
# try to import the secrets library from Python 3.6+ for the
17-
# cryptographic token generator for generating nonces as part of SCRAM
18-
# Otherwise fall back on os.urandom
19-
try:
20-
from secrets import token_bytes as generate_token_bytes
21-
except ImportError:
22-
from os import urandom as generate_token_bytes
23-
2417
@cython.final
2518
cdef class SCRAMAuthentication:
2619
"""Contains the protocol for generating and a SCRAM hashed password.
@@ -198,7 +191,7 @@ cdef class SCRAMAuthentication:
198191
cdef:
199192
bytes token
200193

201-
token = generate_token_bytes(num_bytes)
194+
token = secrets.token_bytes(num_bytes)
202195

203196
return base64.b64encode(token)
204197

0 commit comments

Comments
 (0)