OSDN Git Service

kget: deal with TODO related to MD4 checksums support
authorIvailo Monev <xakepa10@gmail.com>
Sun, 8 Aug 2021 03:54:50 +0000 (06:54 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Sun, 8 Aug 2021 03:54:50 +0000 (06:54 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
kget/core/verifier.cpp
kget/core/verifier_p.h
kget/transfer-plugins/checksumsearch/kget_checksumsearchfactory.kcfg

index 0e8b6c1..f849ef1 100644 (file)
 #include <KDebug>
 
 //TODO use mutable to make some methods const?
-// TODO: implement md4 support
+// TODO: implement sha256 and sha512 support
 const QStringList VerifierPrivate::SUPPORTED = (QStringList() << "sha1" << "md5" << "md4");
+const QString VerifierPrivate::MD4 = QString("md4");
+const int VerifierPrivate::MD4LENGTH = 16;
 const QString VerifierPrivate::MD5 = QString("md5");
 const int VerifierPrivate::MD5LENGTH = 32;
 const QString VerifierPrivate::SHA1 = QString("sha1");
@@ -63,7 +65,7 @@ QString VerifierPrivate::calculatePartialChecksum(QFile *file, const QString &ty
         pieceLength = fileSize - startOffset;
     }
 
-    if (type != MD5 && type != SHA1) {
+    if (type != MD4 && type != MD5 && type != SHA1) {
         return QString();
     }
 
@@ -77,7 +79,9 @@ QString VerifierPrivate::calculatePartialChecksum(QFile *file, const QString &ty
     }
 
     QCryptographicHash *hash = 0;
-    if (type == MD5) {
+    if (type == MD4) {
+        hash = new QCryptographicHash(QCryptographicHash::Md4);
+    } else if (type == MD5) {
         hash = new QCryptographicHash(QCryptographicHash::Md5);
     } else if (type == SHA1) {
         hash = new QCryptographicHash(QCryptographicHash::Sha1);
@@ -186,9 +190,9 @@ VerificationModel *Verifier::model()
 QStringList Verifier::supportedVerficationTypes()
 {
     QStringList supported;
-    if (!supported.contains(VerifierPrivate::MD5))
+    if (!supported.contains(VerifierPrivate::MD4))
     {
-        supported << VerifierPrivate::MD5 << VerifierPrivate::SHA1;
+        supported << VerifierPrivate::MD4 << VerifierPrivate::MD5 << VerifierPrivate::SHA1;
     }
 
     return supported;
@@ -197,7 +201,9 @@ QStringList Verifier::supportedVerficationTypes()
 
 int Verifier::diggestLength(const QString &type)
 {
-    if (type == VerifierPrivate::MD5) {
+    if (type == VerifierPrivate::MD4) {
+        return VerifierPrivate::MD4LENGTH;
+    } else if (type == VerifierPrivate::MD5) {
         return VerifierPrivate::MD5LENGTH;
     } else if (type == VerifierPrivate::SHA1) {
         return VerifierPrivate::SHA1LENGTH;
@@ -362,7 +368,11 @@ QString Verifier::checksum(const KUrl &dest, const QString &type)
         return QString();
     }
 
-    if (type == VerifierPrivate::MD5) {
+    if (type == VerifierPrivate::MD4) {
+        QByteArray hash = QCryptographicHash::hash(file.readAll(), QCryptographicHash::Md4);
+        file.close();
+        return hash.toHex();
+    } else if (type == VerifierPrivate::MD5) {
         QByteArray hash = QCryptographicHash::hash(file.readAll(), QCryptographicHash::Md5);
         file.close();
         return hash.toHex();
index e73e621..72a283e 100644 (file)
@@ -52,6 +52,8 @@ struct VerifierPrivate
     mutable VerificationThread thread;
 
     static const QStringList SUPPORTED;
+    static const QString MD4;
+    static const int MD4LENGTH;
     static const QString MD5;
     static const int MD5LENGTH;
     static const QString SHA1;
index a6327f9..9d9f8c5 100644 (file)
@@ -8,15 +8,15 @@
    <group name="ChecksumSearch">
     <entry name="SearchStrings" type="StringList">
       <label>List of the available search engines</label>
-      <default>.md5,MD5SUMS,.sha1,SHA1SUMS,-CHECKSUM</default>
+      <default>.md4,MD4SUMS,.md5,MD5SUMS,.sha1,SHA1SUMS,-CHECKSUM</default>
     </entry>
     <entry name="UrlChangeModeList" type="IntList">
       <label>List of the available search engine URLs</label>
-      <default>0,1,0,1,2</default>
+      <default>0,1,0,1,0,1,2</default>
     </entry>
     <entry name="ChecksumTypeList" type="StringList">
       <label>List of the available search engine URLs</label>
-      <default>md5,md5,sha1,sha1,</default>
+      <default>md4,md4,md5,md5,sha1,sha1,</default>
     </entry>
   </group>
 </kcfg>