]> Some of my projects - anidbudpclient.git/commitdiff
ed2k hashing changes for edge cases.
authorAPTX <marek321@gmail.com>
Sat, 18 Feb 2012 15:36:48 +0000 (16:36 +0100)
committerAPTX <marek321@gmail.com>
Sat, 18 Feb 2012 15:36:48 +0000 (16:36 +0100)
hashconsumer.cpp

index ce383ec21d434c0a18c210d7646489f81e07d128..7ef292a06b63cb3379ea51208b21975f0e84fbaf 100644 (file)
@@ -58,13 +58,23 @@ qDebug() << "Thread consumer id is: " << QThread::currentThreadId();
 
                        while (!(buffer->get(&data) || abort));
 
-                       hash.addData(QCryptographicHash::hash(data, QCryptographicHash::Md4));
+                       // If file is one chunk don't hash it twice
+                       if (totalSize < ED2K_PART_SIZE)
+                               hash.addData(data);
+                       else
+                               hash.addData(QCryptographicHash::hash(data, QCryptographicHash::Md4));
 
                        read += data.size();
                        emit progress(read, totalSize);
                }
                buffer->reset();
 
+               // The "red" ed2k hash
+               if (totalSize % ED2K_PART_SIZE == 0)
+               {
+                       hash.addData(QCryptographicHash::hash(QByteArray(), QCryptographicHash::Md4));
+               }
+
                if (abort)
                        return;