Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/shasum.py @ 75:a31de3c65877
Remove the use of "hmac.compare_digest()": there are no secrets to protect here
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 27 Feb 2022 15:42:34 +0100 |
| parents | c3268f4e752f |
| children | 8708c34e2723 |
comparison
equal
deleted
inserted
replaced
| 74:6cec638c995c | 75:a31de3c65877 |
|---|---|
| 18 import argparse | 18 import argparse |
| 19 import base64 | 19 import base64 |
| 20 import binascii | 20 import binascii |
| 21 import errno | 21 import errno |
| 22 import hashlib | 22 import hashlib |
| 23 try: | |
| 24 from hmac import compare_digest | |
| 25 except ImportError: | |
| 26 compare_digest = None | |
| 27 import io | 23 import io |
| 28 try: | 24 try: |
| 29 import mmap | 25 import mmap |
| 30 except ImportError: | 26 except ImportError: |
| 31 mmap = None | 27 mmap = None |
| 209 exd = base64.b64decode(expected_digest) | 205 exd = base64.b64decode(expected_digest) |
| 210 except TypeError: | 206 except TypeError: |
| 211 return False | 207 return False |
| 212 else: | 208 else: |
| 213 return False | 209 return False |
| 214 if compare_digest: | 210 return given_digest == exd |
| 215 return compare_digest(given_digest, exd) | |
| 216 else: | |
| 217 return given_digest == exd | |
| 218 | 211 |
| 219 | 212 |
| 220 def verify_digests_with_checklist(opts): | 213 def verify_digests_with_checklist(opts): |
| 221 dest = opts.dest or sys.stdout | 214 dest = opts.dest or sys.stdout |
| 222 exit_code = 0 | 215 exit_code = 0 |
