BaseTools: Use hashlib instead of md5
Use from hashlib import md5 instead of import md5 due to md5 deprecated in python3 Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
committed by
Yonghong Zhu
parent
87010d3d02
commit
fcb1af1b69
@ -19,7 +19,7 @@ GenDEC
|
|||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
import codecs
|
import codecs
|
||||||
import md5
|
from hashlib import md5
|
||||||
from Core.FileHook import __FileHookOpen__
|
from Core.FileHook import __FileHookOpen__
|
||||||
from Library.Parsing import GenSection
|
from Library.Parsing import GenSection
|
||||||
from Library.CommentGenerating import GenHeaderCommentSection
|
from Library.CommentGenerating import GenHeaderCommentSection
|
||||||
@ -646,7 +646,7 @@ def GenPackageUNIEncodeFile(PackageObject, UniFileHeader = '', Encoding=TAB_ENCO
|
|||||||
File = codecs.open(ContainerFile, 'w', Encoding)
|
File = codecs.open(ContainerFile, 'w', Encoding)
|
||||||
File.write(u'\uFEFF' + Content)
|
File.write(u'\uFEFF' + Content)
|
||||||
File.stream.close()
|
File.stream.close()
|
||||||
Md5Sigature = md5.new(__FileHookOpen__(str(ContainerFile), 'rb').read())
|
Md5Sigature = md5(__FileHookOpen__(str(ContainerFile), 'rb').read())
|
||||||
Md5Sum = Md5Sigature.hexdigest()
|
Md5Sum = Md5Sigature.hexdigest()
|
||||||
if (ContainerFile, Md5Sum) not in PackageObject.FileList:
|
if (ContainerFile, Md5Sum) not in PackageObject.FileList:
|
||||||
PackageObject.FileList.append((ContainerFile, Md5Sum))
|
PackageObject.FileList.append((ContainerFile, Md5Sum))
|
||||||
|
@ -18,7 +18,7 @@ GenInf
|
|||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
import codecs
|
import codecs
|
||||||
import md5
|
from hashlib import md5
|
||||||
from Core.FileHook import __FileHookOpen__
|
from Core.FileHook import __FileHookOpen__
|
||||||
from Library.StringUtils import GetSplitValueList
|
from Library.StringUtils import GetSplitValueList
|
||||||
from Library.Parsing import GenSection
|
from Library.Parsing import GenSection
|
||||||
@ -255,7 +255,7 @@ def GenModuleUNIEncodeFile(ModuleObject, UniFileHeader='', Encoding=DT.TAB_ENCOD
|
|||||||
File = codecs.open(ContainerFile, 'wb', Encoding)
|
File = codecs.open(ContainerFile, 'wb', Encoding)
|
||||||
File.write(u'\uFEFF' + Content)
|
File.write(u'\uFEFF' + Content)
|
||||||
File.stream.close()
|
File.stream.close()
|
||||||
Md5Sigature = md5.new(__FileHookOpen__(str(ContainerFile), 'rb').read())
|
Md5Sigature = md5(__FileHookOpen__(str(ContainerFile), 'rb').read())
|
||||||
Md5Sum = Md5Sigature.hexdigest()
|
Md5Sum = Md5Sigature.hexdigest()
|
||||||
if (ContainerFile, Md5Sum) not in ModuleObject.FileList:
|
if (ContainerFile, Md5Sum) not in ModuleObject.FileList:
|
||||||
ModuleObject.FileList.append((ContainerFile, Md5Sum))
|
ModuleObject.FileList.append((ContainerFile, Md5Sum))
|
||||||
|
@ -23,7 +23,7 @@ from os import chmod
|
|||||||
from os import SEEK_SET
|
from os import SEEK_SET
|
||||||
from os import SEEK_END
|
from os import SEEK_END
|
||||||
import stat
|
import stat
|
||||||
import md5
|
from hashlib import md5
|
||||||
import copy
|
import copy
|
||||||
from sys import stdin
|
from sys import stdin
|
||||||
from sys import platform
|
from sys import platform
|
||||||
@ -176,7 +176,7 @@ def UnZipDp(WorkspaceDir, DpPkgFileName, Index=1):
|
|||||||
# verify MD5 signature when existed
|
# verify MD5 signature when existed
|
||||||
#
|
#
|
||||||
if DistPkg.Header.Signature != '':
|
if DistPkg.Header.Signature != '':
|
||||||
Md5Sigature = md5.new(__FileHookOpen__(ContentFile, 'rb').read())
|
Md5Sigature = md5(__FileHookOpen__(ContentFile, 'rb').read())
|
||||||
if DistPkg.Header.Signature != Md5Sigature.hexdigest():
|
if DistPkg.Header.Signature != Md5Sigature.hexdigest():
|
||||||
ContentZipFile.Close()
|
ContentZipFile.Close()
|
||||||
Logger.Error("InstallPkg", FILE_CHECKSUM_FAILURE,
|
Logger.Error("InstallPkg", FILE_CHECKSUM_FAILURE,
|
||||||
@ -215,7 +215,7 @@ def GetPackageList(DistPkg, Dep, WorkspaceDir, Options, ContentZipFile, ModuleLi
|
|||||||
#
|
#
|
||||||
for Package in PackageList:
|
for Package in PackageList:
|
||||||
FilePath = PackageToDec(Package, DistPkg.Header)
|
FilePath = PackageToDec(Package, DistPkg.Header)
|
||||||
Md5Sigature = md5.new(__FileHookOpen__(str(FilePath), 'rb').read())
|
Md5Sigature = md5(__FileHookOpen__(str(FilePath), 'rb').read())
|
||||||
Md5Sum = Md5Sigature.hexdigest()
|
Md5Sum = Md5Sigature.hexdigest()
|
||||||
if (FilePath, Md5Sum) not in Package.FileList:
|
if (FilePath, Md5Sum) not in Package.FileList:
|
||||||
Package.FileList.append((FilePath, Md5Sum))
|
Package.FileList.append((FilePath, Md5Sum))
|
||||||
@ -275,7 +275,7 @@ def GetModuleList(DistPkg, Dep, WorkspaceDir, ContentZipFile, ModuleList):
|
|||||||
for (Module, Package) in ModuleList:
|
for (Module, Package) in ModuleList:
|
||||||
CheckCNameInModuleRedefined(Module, DistPkg)
|
CheckCNameInModuleRedefined(Module, DistPkg)
|
||||||
FilePath = ModuleToInf(Module, Package, DistPkg.Header)
|
FilePath = ModuleToInf(Module, Package, DistPkg.Header)
|
||||||
Md5Sigature = md5.new(__FileHookOpen__(str(FilePath), 'rb').read())
|
Md5Sigature = md5(__FileHookOpen__(str(FilePath), 'rb').read())
|
||||||
Md5Sum = Md5Sigature.hexdigest()
|
Md5Sum = Md5Sigature.hexdigest()
|
||||||
if Package:
|
if Package:
|
||||||
if (FilePath, Md5Sum) not in Package.FileList:
|
if (FilePath, Md5Sum) not in Package.FileList:
|
||||||
@ -803,7 +803,7 @@ def InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly, Executable=False):
|
|||||||
else:
|
else:
|
||||||
chmod(ToFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)
|
chmod(ToFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)
|
||||||
|
|
||||||
Md5Sigature = md5.new(__FileHookOpen__(str(ToFile), 'rb').read())
|
Md5Sigature = md5(__FileHookOpen__(str(ToFile), 'rb').read())
|
||||||
Md5Sum = Md5Sigature.hexdigest()
|
Md5Sum = Md5Sigature.hexdigest()
|
||||||
|
|
||||||
return Md5Sum
|
return Md5Sum
|
||||||
@ -876,7 +876,7 @@ def InstallPackageContent(FromPath, ToPath, Package, ContentZipFile, Dep,
|
|||||||
chmod(ToFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH)
|
chmod(ToFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH)
|
||||||
else:
|
else:
|
||||||
chmod(ToFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH|stat.S_IWUSR|stat.S_IWGRP|stat.S_IWOTH)
|
chmod(ToFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH|stat.S_IWUSR|stat.S_IWGRP|stat.S_IWOTH)
|
||||||
Md5Sigature = md5.new(__FileHookOpen__(str(ToFile), 'rb').read())
|
Md5Sigature = md5(__FileHookOpen__(str(ToFile), 'rb').read())
|
||||||
Md5Sum = Md5Sigature.hexdigest()
|
Md5Sum = Md5Sigature.hexdigest()
|
||||||
if (ToFile, Md5Sum) not in Package.FileList:
|
if (ToFile, Md5Sum) not in Package.FileList:
|
||||||
Package.FileList.append((ToFile, Md5Sum))
|
Package.FileList.append((ToFile, Md5Sum))
|
||||||
|
@ -27,7 +27,7 @@ from sys import stdin
|
|||||||
from sys import platform
|
from sys import platform
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
from platform import python_version
|
from platform import python_version
|
||||||
import md5
|
from hashlib import md5
|
||||||
from time import strftime
|
from time import strftime
|
||||||
from time import localtime
|
from time import localtime
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
@ -196,7 +196,7 @@ def Main(Options = None):
|
|||||||
#
|
#
|
||||||
# Add Md5Sigature
|
# Add Md5Sigature
|
||||||
#
|
#
|
||||||
DistPkg.Header.Signature = md5.new(open(str(ContentFile), 'rb').read()).hexdigest()
|
DistPkg.Header.Signature = md5(open(str(ContentFile), 'rb').read()).hexdigest()
|
||||||
#
|
#
|
||||||
# Add current Date
|
# Add current Date
|
||||||
#
|
#
|
||||||
|
@ -23,7 +23,7 @@ import os.path
|
|||||||
from stat import S_IWUSR
|
from stat import S_IWUSR
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
from platform import python_version
|
from platform import python_version
|
||||||
import md5
|
from hashlib import md5
|
||||||
from sys import stdin
|
from sys import stdin
|
||||||
from sys import platform
|
from sys import platform
|
||||||
|
|
||||||
@ -242,7 +242,7 @@ def RemoveDist(Guid, Version, StoredDistFile, DataBase, WorkspaceDir, ForceRemov
|
|||||||
#
|
#
|
||||||
# check whether modified by users
|
# check whether modified by users
|
||||||
#
|
#
|
||||||
Md5Sigature = md5.new(open(str(Path), 'rb').read())
|
Md5Sigature = md5(open(str(Path), 'rb').read())
|
||||||
if Md5Sum != Md5Sigature.hexdigest():
|
if Md5Sum != Md5Sigature.hexdigest():
|
||||||
Logger.Info(ST.MSG_CONFIRM_REMOVE2 % Path)
|
Logger.Info(ST.MSG_CONFIRM_REMOVE2 % Path)
|
||||||
Input = stdin.readline()
|
Input = stdin.readline()
|
||||||
|
@ -21,7 +21,7 @@ import Common.LongFilePathOs as os
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import copy
|
import copy
|
||||||
import md5
|
from hashlib import md5
|
||||||
|
|
||||||
import Common.EdkLogger as EdkLogger
|
import Common.EdkLogger as EdkLogger
|
||||||
import Common.GlobalData as GlobalData
|
import Common.GlobalData as GlobalData
|
||||||
@ -1929,10 +1929,10 @@ class DecParser(MetaFileParser):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self._include_flag:
|
if self._include_flag:
|
||||||
self._ValueList[1] = "<HeaderFiles>_" + md5.new(self._CurrentLine).hexdigest()
|
self._ValueList[1] = "<HeaderFiles>_" + md5(self._CurrentLine).hexdigest()
|
||||||
self._ValueList[2] = self._CurrentLine
|
self._ValueList[2] = self._CurrentLine
|
||||||
if self._package_flag and "}" != self._CurrentLine:
|
if self._package_flag and "}" != self._CurrentLine:
|
||||||
self._ValueList[1] = "<Packages>_" + md5.new(self._CurrentLine).hexdigest()
|
self._ValueList[1] = "<Packages>_" + md5(self._CurrentLine).hexdigest()
|
||||||
self._ValueList[2] = self._CurrentLine
|
self._ValueList[2] = self._CurrentLine
|
||||||
if self._CurrentLine == "}":
|
if self._CurrentLine == "}":
|
||||||
self._package_flag = False
|
self._package_flag = False
|
||||||
|
Reference in New Issue
Block a user