Skip to content

Commit 5aa0851

Browse files
authored
Add files via upload
1 parent b2d784b commit 5aa0851

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

pyarchivefile.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3756,13 +3756,16 @@ def GetHeaderChecksum(inlist=None, checksumtype="md5", encodedata=True, formatsp
37563756
if encodedata and not isinstance(hdr_bytes, (bytes, bytearray, memoryview)):
37573757
hdr_bytes = _to_bytes(hdr_bytes)
37583758
hdr_bytes = bytes(hdr_bytes)
3759+
saltkeyval = None
37593760
if(saltkey is not None):
3760-
saltkey = _to_bytes(saltkey)
3761+
skfp = (saltkey, "rb")
3762+
saltkeyval = skfp.read()
3763+
skfp.close()
37613764
if CheckSumSupport(algo_key, hashlib_guaranteed):
3762-
if(saltkey is None):
3765+
if(saltkey is None or saltkeyval is None):
37633766
h = hashlib.new(algo_key, hdr_bytes)
37643767
else:
3765-
h = hmac.new(saltkey, hdr_bytes, digestmod=algo_key)
3768+
h = hmac.new(saltkeyval, hdr_bytes, digestmod=algo_key)
37663769
return h.hexdigest().lower()
37673770

37683771
return "0"
@@ -3775,17 +3778,20 @@ def GetFileChecksum(inbytes, checksumtype="md5", encodedata=True, formatspecs=__
37753778
- Falls back to one-shot for non-file-like inputs.
37763779
"""
37773780
algo_key = (checksumtype or "md5").lower()
3781+
saltkeyval = None
37783782
if(saltkey is not None):
3779-
saltkey = _to_bytes(saltkey)
3783+
skfp = (saltkey, "rb")
3784+
saltkeyval = skfp.read()
3785+
skfp.close()
37803786
# file-like streaming
37813787
if hasattr(inbytes, "read"):
37823788
# hashlib
37833789

37843790
if CheckSumSupport(algo_key, hashlib_guaranteed):
3785-
if(saltkey is None):
3791+
if(saltkey is None or saltkeyval is None):
37863792
h = hashlib.new(algo_key)
37873793
else:
3788-
h = hmac.new(saltkey, digestmod=algo_key)
3794+
h = hmac.new(saltkeyval, digestmod=algo_key)
37893795
while True:
37903796
chunk = inbytes.read(__filebuff_size__)
37913797
if not chunk:
@@ -3806,10 +3812,10 @@ def GetFileChecksum(inbytes, checksumtype="md5", encodedata=True, formatspecs=__
38063812
# one-shot
38073813

38083814
if CheckSumSupport(algo_key, hashlib_guaranteed):
3809-
if(saltkey is None):
3815+
if(saltkey is None or saltkeyval is None):
38103816
h = hashlib.new(algo_key, data)
38113817
else:
3812-
h = hmac.new(saltkey, data, digestmod=algo_key)
3818+
h = hmac.new(saltkeyval, data, digestmod=algo_key)
38133819
return h.hexdigest().lower()
38143820

38153821
return "0"

0 commit comments

Comments
 (0)