Skip to content

Commit a3faaf6

Browse files
authored
Add files via upload
1 parent 7a34150 commit a3faaf6

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

pyarchivefile.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3666,7 +3666,7 @@ def _bytes_to_int(b):
36663666
# =========================
36673667
# Public checksum API
36683668
# =========================
3669-
def GetHeaderChecksum(inlist=None, checksumtype="md5", encodedata=True, formatspecs=__file_format_dict__):
3669+
def GetHeaderChecksum(inlist=None, checksumtype="md5", encodedata=True, formatspecs=__file_format_dict__, saltkey=None):
36703670
"""
36713671
Serialize header fields (list/tuple => joined with delimiter + trailing delimiter;
36723672
or a single field) and compute the requested checksum. Returns lowercase hex.
@@ -3678,15 +3678,16 @@ def GetHeaderChecksum(inlist=None, checksumtype="md5", encodedata=True, formatsp
36783678
if encodedata and not isinstance(hdr_bytes, (bytes, bytearray, memoryview)):
36793679
hdr_bytes = _to_bytes(hdr_bytes)
36803680
hdr_bytes = bytes(hdr_bytes)
3681-
36823681
if CheckSumSupport(algo_key, hashlib_guaranteed):
3683-
h = hashlib.new(algo_key)
3684-
h.update(hdr_bytes)
3685-
return h.hexdigest().lower()
3682+
if(saltkey is None):
3683+
h = hashlib.new(algo_key, hdr_bytes)
3684+
else:
3685+
h = hmac.new(saltkey, hdr_bytes, digestmod=algo_key)
3686+
return h.hexdigest().lower()
36863687

36873688
return "0"
36883689

3689-
def GetFileChecksum(inbytes, checksumtype="md5", encodedata=True, formatspecs=__file_format_dict__):
3690+
def GetFileChecksum(inbytes, checksumtype="md5", encodedata=True, formatspecs=__file_format_dict__, saltkey=None):
36903691
"""
36913692
Accepts bytes/str/file-like.
36923693
- Hashlib algos: streamed in 1 MiB chunks.
@@ -3700,7 +3701,10 @@ def GetFileChecksum(inbytes, checksumtype="md5", encodedata=True, formatspecs=__
37003701
# hashlib
37013702

37023703
if CheckSumSupport(algo_key, hashlib_guaranteed):
3703-
h = hashlib.new(algo_key)
3704+
if(saltkey is None):
3705+
h = hashlib.new(algo_key)
3706+
else:
3707+
h = hmac.new(saltkey, digestmod=algo_key)
37043708
while True:
37053709
chunk = inbytes.read(__filebuff_size__)
37063710
if not chunk:
@@ -3721,8 +3725,10 @@ def GetFileChecksum(inbytes, checksumtype="md5", encodedata=True, formatspecs=__
37213725
# one-shot
37223726

37233727
if CheckSumSupport(algo_key, hashlib_guaranteed):
3724-
h = hashlib.new(algo_key)
3725-
h.update(data)
3728+
if(saltkey is None):
3729+
h = hashlib.new(algo_key, data)
3730+
else:
3731+
h = hmac.new(saltkey, data, digestmod=algo_key)
37263732
return h.hexdigest().lower()
37273733

37283734
return "0"

0 commit comments

Comments
 (0)