Skip to content

Commit 0210785

Browse files
authored
Add files via upload
1 parent acc7e11 commit 0210785

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

pyfoxfile.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3764,13 +3764,16 @@ def GetHeaderChecksum(inlist=None, checksumtype="md5", encodedata=True, formatsp
37643764
if encodedata and not isinstance(hdr_bytes, (bytes, bytearray, memoryview)):
37653765
hdr_bytes = _to_bytes(hdr_bytes)
37663766
hdr_bytes = bytes(hdr_bytes)
3767+
saltkeyval = None
37673768
if(saltkey is not None):
3768-
saltkey = _to_bytes(saltkey)
3769+
skfp = (saltkey, "rb")
3770+
saltkeyval = skfp.read()
3771+
skfp.close()
37693772
if CheckSumSupport(algo_key, hashlib_guaranteed):
3770-
if(saltkey is None):
3773+
if(saltkey is None or saltkeyval is None):
37713774
h = hashlib.new(algo_key, hdr_bytes)
37723775
else:
3773-
h = hmac.new(saltkey, hdr_bytes, digestmod=algo_key)
3776+
h = hmac.new(saltkeyval, hdr_bytes, digestmod=algo_key)
37743777
return h.hexdigest().lower()
37753778

37763779
return "0"
@@ -3783,17 +3786,20 @@ def GetFileChecksum(inbytes, checksumtype="md5", encodedata=True, formatspecs=__
37833786
- Falls back to one-shot for non-file-like inputs.
37843787
"""
37853788
algo_key = (checksumtype or "md5").lower()
3789+
saltkeyval = None
37863790
if(saltkey is not None):
3787-
saltkey = _to_bytes(saltkey)
3791+
skfp = (saltkey, "rb")
3792+
saltkeyval = skfp.read()
3793+
skfp.close()
37883794
# file-like streaming
37893795
if hasattr(inbytes, "read"):
37903796
# hashlib
37913797

37923798
if CheckSumSupport(algo_key, hashlib_guaranteed):
3793-
if(saltkey is None):
3799+
if(saltkey is None or saltkeyval is None):
37943800
h = hashlib.new(algo_key)
37953801
else:
3796-
h = hmac.new(saltkey, digestmod=algo_key)
3802+
h = hmac.new(saltkeyval, digestmod=algo_key)
37973803
while True:
37983804
chunk = inbytes.read(__filebuff_size__)
37993805
if not chunk:
@@ -3814,10 +3820,10 @@ def GetFileChecksum(inbytes, checksumtype="md5", encodedata=True, formatspecs=__
38143820
# one-shot
38153821

38163822
if CheckSumSupport(algo_key, hashlib_guaranteed):
3817-
if(saltkey is None):
3823+
if(saltkey is None or saltkeyval is None):
38183824
h = hashlib.new(algo_key, data)
38193825
else:
3820-
h = hmac.new(saltkey, data, digestmod=algo_key)
3826+
h = hmac.new(saltkeyval, data, digestmod=algo_key)
38213827
return h.hexdigest().lower()
38223828

38233829
return "0"

0 commit comments

Comments
 (0)