diff options
author | Miguel Costa <miguel.costa@qt.io> | 2019-01-30 17:58:23 +0100 |
---|---|---|
committer | Miguel Costa <miguel.costa@qt.io> | 2019-01-31 08:01:19 +0000 |
commit | 0675fc4d46001fb1c0936bd0354f20c9a3e66063 (patch) | |
tree | 48d1e268b77b5a5df99055a9d45d6ea84d7c7d64 /src | |
parent | 5f6642915d67ed67df8d375e67202e19194513ff (diff) |
Use different hash calculation for Qt work items
Will now calculate the hash of Qt work items (i.e. MSBuild items that
represent in-build processing with Qt tools moc, rcc, etc.) using a
a combination of Deflate and Base64. Previously, the hash relied on the
SHA1 implementation in .NET cryptography. The new approach entails a
slight (i.e. non-significant) performance degradation, and has some
advantages over using SHA1:
* Deflate's lossless compression eliminates the (extremely unlikely)
possibility of an hash collision.
* Avoids any current or future restrictions imposed on the use of
cryptographic functions -- as is the case with the enforcement of
FIPS compliance (cf. bug report).
Task-number: QTVSADDINBUG-618
Change-Id: I70017cacfb093377bed07da207fd2e10ddf5fe2b
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qtmsbuild/qt_globals.targets | 2 | ||||
-rw-r--r-- | src/qtmsbuild/qt_tasks.targets | 19 |
2 files changed, 12 insertions, 9 deletions
diff --git a/src/qtmsbuild/qt_globals.targets b/src/qtmsbuild/qt_globals.targets index e9eaf5ca..972047a5 100644 --- a/src/qtmsbuild/qt_globals.targets +++ b/src/qtmsbuild/qt_globals.targets @@ -118,7 +118,7 @@ <!-- /////////////////////////////////////////////////////////////////////////////////////////////// - // Calculate hash (SHA1) for the requested work item, based on its associated tool and options + // Calculate hash for the requested work item, based on its associated tool and options // --> <GetItemHash Condition="'@(QtWork)' != ''" Item="@(QtWork)" Keys="Identity;WorkType;ToolPath;Options"> diff --git a/src/qtmsbuild/qt_tasks.targets b/src/qtmsbuild/qt_tasks.targets index 5eb961c3..fc65771c 100644 --- a/src/qtmsbuild/qt_tasks.targets +++ b/src/qtmsbuild/qt_tasks.targets @@ -39,11 +39,11 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// /// TASK GetItemHash ///////////////////////////////////////////////////////////////////////////////////////////////// - // Calculate an hash code (SHA1) for an item, given a list of metadata to use as key + // Calculate an hash code (Deflate + Base64) for an item, given a list of metadata to use as key // Parameters: // in ITaskItem Item: item for which the hash will be calculated // in string[] Keys: list of names of the metadata to use as item key - // out string Hash: hash code (SHA1 in hexadecimal format) + // out string Hash: hash code (Base64 representation of Deflate'd UTF-8 item key) // --> <UsingTask TaskName="GetItemHash" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> @@ -55,14 +55,17 @@ <Task> <Using Namespace="System"/> <Using Namespace="System.Text"/> - <Using Namespace="System.Security.Cryptography"/> + <Using Namespace="System.IO"/> + <Using Namespace="System.IO.Compression"/> <Code Type="Fragment" Language="cs"> <![CDATA[ - var data = string.Concat(Keys.OrderBy(x => x) - .Select(x => string.Format("[{0}={1}]", x, Item.GetMetadata(x)))); - using (var sha1 = new SHA1Managed()) { - Hash = string.Concat(sha1.ComputeHash(Encoding.UTF8.GetBytes(data)) - .Select(x => x.ToString("x2"))); + var data = Encoding.UTF8.GetBytes(string.Concat(Keys.OrderBy(x => x) + .Select(x => string.Format("[{0}={1}]", x, Item.GetMetadata(x)))) + .ToUpper()); + using (var dataZipped = new MemoryStream()) { + using (var zip = new DeflateStream(dataZipped, CompressionLevel.Fastest)) + zip.Write(data, 0, data.Length); + Hash = Convert.ToBase64String(dataZipped.ToArray()); } ]]> </Code> |