From: Olivier Goffart Date: Thu, 5 Jul 2018 12:36:10 +0000 (+0200) Subject: Checksum: Add support for SHA256 and SHA3 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~513 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d81ccbb0c1b34d4e73ddc3e8db8c45b9ee77f794;p=nextcloud-desktop.git Checksum: Add support for SHA256 and SHA3 In case, some day, the server also supports it --- diff --git a/src/common/checksums.cpp b/src/common/checksums.cpp index a2bfdabc7..49ac2eafb 100644 --- a/src/common/checksums.cpp +++ b/src/common/checksums.cpp @@ -78,6 +78,8 @@ * - Adler32 (requires zlib) * - MD5 * - SHA1 + * - SHA256 + * - SHA3-256 (requires Qt 5.9) * */ @@ -146,7 +148,9 @@ QByteArray findBestChecksum(const QByteArray &checksums) { int i = 0; // The order of the searches here defines the preference ordering. - if (-1 != (i = checksums.indexOf("SHA1:")) + if (-1 != (i = checksums.indexOf("SHA3-256:")) + || -1 != (i = checksums.indexOf("SHA256:")) + || -1 != (i = checksums.indexOf("SHA1:")) || -1 != (i = checksums.indexOf("MD5:")) || -1 != (i = checksums.indexOf("Adler32:"))) { // Now i is the start of the best checksum @@ -243,7 +247,14 @@ QByteArray ComputeChecksum::computeNow(const QString &filePath, const QByteArray return calcMd5(filePath); } else if (checksumType == checkSumSHA1C) { return calcSha1(filePath); + } else if (checksumType == checkSumSHA2C) { + return calcCryptoHash(filePath, QCryptographicHash::Sha256); } +#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0) + else if (checksumType == checkSumSHA3C) { + return calcCryptoHash(filePath, QCryptographicHash::Sha3_256); + } +#endif #ifdef ZLIB_FOUND else if (checksumType == checkSumAdlerC) { return calcAdler32(filePath); diff --git a/src/common/checksums.h b/src/common/checksums.h index 765e4659b..f00a31cf8 100644 --- a/src/common/checksums.h +++ b/src/common/checksums.h @@ -33,6 +33,8 @@ namespace OCC { */ static const char checkSumMD5C[] = "MD5"; static const char checkSumSHA1C[] = "SHA1"; +static const char checkSumSHA2C[] = "SHA256"; +static const char checkSumSHA3C[] = "SHA3-256"; static const char checkSumAdlerC[] = "Adler32"; class SyncJournalDb; diff --git a/src/csync/csync_util.cpp b/src/csync/csync_util.cpp index 57b992387..696aa41fe 100644 --- a/src/csync/csync_util.cpp +++ b/src/csync/csync_util.cpp @@ -195,6 +195,6 @@ time_t oc_httpdate_parse( const char *date ) { bool csync_is_collision_safe_hash(const QByteArray &checksum_header) { - return checksum_header.startsWith("SHA1:") + return checksum_header.startsWith("SHA") || checksum_header.startsWith("MD5:"); }