diff options
| author | 2019-02-12 11:57:49 +0000 | |
|---|---|---|
| committer | 2019-02-12 11:57:49 +0000 | |
| commit | 9667b8a6e08b57db952162c28a7a079068dfdd04 (patch) | |
| tree | d920411734d2d81dee34341fa9ace8a56c67427b /src/utils/security.py | |
| parent | Use `hmac.compare_digest` to do a constant-time compare (sasl.scram) (diff) | |
| signature | ||
Move constant-time compare function to utils.security
Diffstat (limited to 'src/utils/security.py')
| -rw-r--r-- | src/utils/security.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/utils/security.py b/src/utils/security.py index 266a767a..1c8f2cf4 100644 --- a/src/utils/security.py +++ b/src/utils/security.py @@ -1,4 +1,4 @@ -import socket, ssl +import hmac, socket, ssl, typing def ssl_context(cert: str=None, key: str=None, verify: bool=True ) -> ssl.SSLContext: @@ -21,3 +21,8 @@ def ssl_wrap(sock: socket.socket, cert: str=None, key: str=None, context = ssl_context(cert=cert, key=key, verify=verify) return context.wrap_socket(sock, server_side=server_side, server_hostname=hostname) + +def constant_time_compare( + a: typing.Union[str, bytes], + b: typing.Union[str, bytes]) -> bool: + return hmac.compare_digest(a, b) |
