Skip to content

Commit 9382e46

Browse files
authored
Add files via upload
1 parent 5174a16 commit 9382e46

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

pyfoxfile.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3674,7 +3674,7 @@ def _bytes_to_int(b):
36743674
# =========================
36753675
# Public checksum API
36763676
# =========================
3677-
def GetHeaderChecksum(inlist=None, checksumtype="md5", encodedata=True, formatspecs=__file_format_dict__):
3677+
def GetHeaderChecksum(inlist=None, checksumtype="md5", encodedata=True, formatspecs=__file_format_dict__, saltkey=None):
36783678
"""
36793679
Serialize header fields (list/tuple => joined with delimiter + trailing delimiter;
36803680
or a single field) and compute the requested checksum. Returns lowercase hex.
@@ -3686,15 +3686,16 @@ def GetHeaderChecksum(inlist=None, checksumtype="md5", encodedata=True, formatsp
36863686
if encodedata and not isinstance(hdr_bytes, (bytes, bytearray, memoryview)):
36873687
hdr_bytes = _to_bytes(hdr_bytes)
36883688
hdr_bytes = bytes(hdr_bytes)
3689-
36903689
if CheckSumSupport(algo_key, hashlib_guaranteed):
3691-
h = hashlib.new(algo_key)
3692-
h.update(hdr_bytes)
3693-
return h.hexdigest().lower()
3690+
if(saltkey is None):
3691+
h = hashlib.new(algo_key, hdr_bytes)
3692+
else:
3693+
h = hmac.new(saltkey, hdr_bytes, digestmod=algo_key)
3694+
return h.hexdigest().lower()
36943695

36953696
return "0"
36963697

3697-
def GetFileChecksum(inbytes, checksumtype="md5", encodedata=True, formatspecs=__file_format_dict__):
3698+
def GetFileChecksum(inbytes, checksumtype="md5", encodedata=True, formatspecs=__file_format_dict__, saltkey=None):
36983699
"""
36993700
Accepts bytes/str/file-like.
37003701
- Hashlib algos: streamed in 1 MiB chunks.
@@ -3708,7 +3709,10 @@ def GetFileChecksum(inbytes, checksumtype="md5", encodedata=True, formatspecs=__
37083709
# hashlib
37093710

37103711
if CheckSumSupport(algo_key, hashlib_guaranteed):
3711-
h = hashlib.new(algo_key)
3712+
if(saltkey is None):
3713+
h = hashlib.new(algo_key)
3714+
else:
3715+
h = hmac.new(saltkey, digestmod=algo_key)
37123716
while True:
37133717
chunk = inbytes.read(__filebuff_size__)
37143718
if not chunk:
@@ -3729,8 +3733,10 @@ def GetFileChecksum(inbytes, checksumtype="md5", encodedata=True, formatspecs=__
37293733
# one-shot
37303734

37313735
if CheckSumSupport(algo_key, hashlib_guaranteed):
3732-
h = hashlib.new(algo_key)
3733-
h.update(data)
3736+
if(saltkey is None):
3737+
h = hashlib.new(algo_key, data)
3738+
else:
3739+
h = hmac.new(saltkey, data, digestmod=algo_key)
37343740
return h.hexdigest().lower()
37353741

37363742
return "0"

0 commit comments

Comments
 (0)