Skip to content
Snippets Groups Projects
Unverified Commit 55c96e80 authored by NewUserHa's avatar NewUserHa Committed by GitHub
Browse files

gh-99305: Speed up secrets.token_hex() ~2x (#99306)


simple code modernization.

Co-authored-by: default avatarPieter Eendebak <pieter.eendebak@gmail.com>
parent f531b687
Branches
Tags
No related merge requests found
......@@ -13,7 +13,6 @@
import base64
import binascii
from hmac import compare_digest
from random import SystemRandom
......@@ -56,7 +55,7 @@ def token_hex(nbytes=None):
'f9bf78b9a18ce6d46a0cd2b0b86df9da'
"""
return binascii.hexlify(token_bytes(nbytes)).decode('ascii')
return token_bytes(nbytes).hex()
def token_urlsafe(nbytes=None):
"""Return a random URL-safe text string, in Base64 encoding.
......
Improve performance of :func:`secrets.token_hex`.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment