Skip to content

Commit d1b8f6d

Browse files
committed
Update pycatfile.py
1 parent 368bf00 commit d1b8f6d

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

pycatfile.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,7 +4209,7 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
42094209
pass
42104210
fp.seek(len(delimiter), 1)
42114211
jsonfcs = GetFileChecksum(fprejsoncontent, fjsonchecksumtype, True, formatspecs)
4212-
if(jsonfcs != fjsonchecksum and not skipchecksum):
4212+
if(not hmac.compare_digest(fjsonchecksum, jsonfcs) and not skipchecksum):
42134213
VerbosePrintOut("File JSON Data Checksum Error with file " +
42144214
fname + " at offset " + str(fheaderstart))
42154215
VerbosePrintOut("'" + fjsonchecksum + "' != " + "'" + jsonfcs + "'")
@@ -4238,7 +4238,7 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
42384238
newfccs = GetFileChecksum(
42394239
fcontents, HeaderOut[-3].lower(), False, formatspecs)
42404240
fcontents.seek(0, 0)
4241-
if(fccs != newfccs and not skipchecksum and not listonly):
4241+
if(not hmac.compare_digest(fccs, newfccs) and not skipchecksum and not listonly):
42424242
VerbosePrintOut("File Content Checksum Error with file " +
42434243
fname + " at offset " + str(fcontentstart))
42444244
VerbosePrintOut("'" + fccs + "' != " + "'" + newfccs + "'")
@@ -4410,7 +4410,7 @@ def ReadFileHeaderDataWithContentToArray(fp, listonly=False, contentasfile=True,
44104410
fp.seek(len(delimiter), 1)
44114411
fjend = fp.tell() - 1
44124412
jsonfcs = GetFileChecksum(fprejsoncontent, fjsonchecksumtype, True, formatspecs)
4413-
if(jsonfcs != fjsonchecksum and not skipchecksum):
4413+
if(not hmac.compare_digest(fjsonchecksum, jsonfcs) and not skipchecksum):
44144414
VerbosePrintOut("File JSON Data Checksum Error with file " +
44154415
fname + " at offset " + str(fheaderstart))
44164416
VerbosePrintOut("'" + fjsonchecksum + "' != " + "'" + jsonfcs + "'")
@@ -4444,7 +4444,7 @@ def ReadFileHeaderDataWithContentToArray(fp, listonly=False, contentasfile=True,
44444444
newfccs = GetFileChecksum(
44454445
fcontents, HeaderOut[-3].lower(), False, formatspecs)
44464446
fcontents.seek(0, 0)
4447-
if(fccs != newfccs and not skipchecksum and not listonly):
4447+
if(not hmac.compare_digest(fccs, newfccs) and not skipchecksum and not listonly):
44484448
VerbosePrintOut("File Content Checksum Error with file " +
44494449
fname + " at offset " + str(fcontentstart))
44504450
VerbosePrintOut("'" + fccs + "' != " + "'" + newfccs + "'")
@@ -4622,7 +4622,7 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
46224622
pass
46234623
fp.seek(len(delimiter), 1)
46244624
jsonfcs = GetFileChecksum(fprejsoncontent, fjsonchecksumtype, True, formatspecs)
4625-
if(jsonfcs != fjsonchecksum and not skipchecksum):
4625+
if(not hmac.compare_digest(fjsonchecksum, jsonfcs) and not skipchecksum):
46264626
VerbosePrintOut("File JSON Data Checksum Error with file " +
46274627
fname + " at offset " + str(fheaderstart))
46284628
VerbosePrintOut("'" + fjsonchecksum + "' != " + "'" + jsonfcs + "'")
@@ -4655,7 +4655,7 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
46554655
fcontents.seek(0, 0)
46564656
newfccs = GetFileChecksum(
46574657
fcontents, HeaderOut[-3].lower(), False, formatspecs)
4658-
if(fccs != newfccs and not skipchecksum and not listonly):
4658+
if(not hmac.compare_digest(fccs, newfccs) and not skipchecksum and not listonly):
46594659
VerbosePrintOut("File Content Checksum Error with file " +
46604660
fname + " at offset " + str(fcontentstart))
46614661
VerbosePrintOut("'" + fccs + "' != " + "'" + newfccs + "'")
@@ -4839,15 +4839,15 @@ def ReadFileDataWithContentToArray(fp, filestart=0, seekstart=0, seekend=0, list
48394839
prejsoncontent = fp.read(prefjsonsize).decode("UTF-8")
48404840
fp.seek(len(delimiter), 1)
48414841
prejsonfcs = GetFileChecksum(prejsoncontent, prefjsonchecksumtype, True, formatspecs)
4842-
if(prejsonfcs != prefjsonchecksum and not skipchecksum):
4842+
if(not hmac.compare_digest(prefjsonchecksum, prejsonfcs) and not skipchecksum):
48434843
VerbosePrintOut("File JSON Data Checksum Error with file " +
48444844
prefname + " at offset " + str(prefhstart))
48454845
VerbosePrintOut("'" + prefjsonchecksum + "' != " + "'" + prejsonfcs + "'")
48464846
return False
48474847
prenewfcs = GetHeaderChecksum(
48484848
preheaderdata[:-2], preheaderdata[-4].lower(), True, formatspecs)
48494849
prefcs = preheaderdata[-2]
4850-
if(prefcs != prenewfcs and not skipchecksum):
4850+
if(not hmac.compare_digest(prefcs, prenewfcs) and not skipchecksum):
48514851
VerbosePrintOut("File Header Checksum Error with file " +
48524852
prefname + " at offset " + str(prefhstart))
48534853
VerbosePrintOut("'" + prefcs + "' != " +
@@ -4866,7 +4866,7 @@ def ReadFileDataWithContentToArray(fp, filestart=0, seekstart=0, seekend=0, list
48664866
prefcontents, preheaderdata[-3].lower(), False, formatspecs)
48674867
prefccs = preheaderdata[-1]
48684868
pyhascontents = True
4869-
if(prefccs != prenewfccs and not skipchecksum):
4869+
if(not hmac.compare_digest(prefccs, prenewfccs) and not skipchecksum):
48704870
VerbosePrintOut("File Content Checksum Error with file " +
48714871
prefname + " at offset " + str(prefcontentstart))
48724872
VerbosePrintOut("'" + prefccs +
@@ -5000,7 +5000,7 @@ def ReadFileDataWithContentToList(fp, filestart=0, seekstart=0, seekend=0, listo
50005000
prefprejsoncontent = fp.read(prefjsonsize).decode("UTF-8")
50015001
fp.seek(len(delimiter), 1)
50025002
prejsonfcs = GetFileChecksum(prefprejsoncontent, prefjsonchecksumtype, True, formatspecs)
5003-
if(prejsonfcs != prefjsonchecksum and not skipchecksum):
5003+
if(not hmac.compare_digest(prefjsonchecksum, prejsonfcs) and not skipchecksum):
50045004
VerbosePrintOut("File JSON Data Checksum Error with file " +
50055005
prefname + " at offset " + str(prefhstart))
50065006
VerbosePrintOut("'" + prefjsonchecksum + "' != " + "'" + prejsonfcs + "'")
@@ -5029,7 +5029,7 @@ def ReadFileDataWithContentToList(fp, filestart=0, seekstart=0, seekend=0, listo
50295029
prefcontents, preheaderdata[-3].lower(), False, formatspecs)
50305030
prefccs = preheaderdata[-1]
50315031
pyhascontents = True
5032-
if(prefccs != prenewfccs and not skipchecksum):
5032+
if(not hmac.compare_digest(prefcs, prenewfcs) and not skipchecksum):
50335033
VerbosePrintOut("File Content Checksum Error with file " +
50345034
prefname + " at offset " + str(prefcontentstart))
50355035
VerbosePrintOut("'" + prefccs +
@@ -9559,7 +9559,7 @@ def CatFileValidate(infile, fmttype="auto", filestart=0,
95599559
VerbosePrintOut(outfname)
95609560
VerbosePrintOut("Record Number " + str(il) + "; File ID " + str(fid) + "; iNode Number " + str(finode))
95619561

9562-
if(hmac.compare_digest(infcs, outfcs)):
9562+
if(hmac.compare_digest(outfcs, infcs)):
95639563
if(verbose):
95649564
VerbosePrintOut("File Header Checksum Passed at offset " + str(outfhstart))
95659565
VerbosePrintOut("'" + outfcs + "' == " + "'" + infcs + "'")
@@ -9595,7 +9595,7 @@ def CatFileValidate(infile, fmttype="auto", filestart=0,
95959595
infccs = GetFileChecksum(outfcontents, inheaderdata[-3].lower(), False, formatspecs)
95969596
pyhascontents = True
95979597

9598-
if(outfccs == infccs):
9598+
if(hmac.compare_digest(outfccs, infccs)):
95999599
if(verbose):
96009600
VerbosePrintOut("File Content Checksum Passed at offset " + str(outfcontentstart))
96019601
VerbosePrintOut("'" + outfccs + "' == " + "'" + infccs + "'")

0 commit comments

Comments
 (0)