summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <dvratil@kde.org>2016-08-09 12:30:31 (GMT)
committerDaniel Vrátil <dvratil@kde.org>2016-08-09 12:31:07 (GMT)
commit58cd95577c4c16f303d0481e1cd3a59a18307590 (patch)
treecfc691c45d6a84a2a6f2727d551290f9172e4e06
parent7700169686a8597ba8b59f9d6c3fd9ece9d27ef3 (diff)
Move utils/classify to libkleo
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/commands/command.cpp2
-rw-r--r--src/commands/decryptverifyclipboardcommand.cpp3
-rw-r--r--src/commands/exportcertificatecommand.cpp9
-rw-r--r--src/commands/importcertificatefromclipboardcommand.cpp2
-rw-r--r--src/commands/importcertificatefromfilecommand.cpp2
-rw-r--r--src/crypto/autodecryptverifyfilescontroller.cpp3
-rw-r--r--src/crypto/createchecksumscontroller.cpp2
-rw-r--r--src/crypto/decryptverifyemailcontroller.cpp2
-rw-r--r--src/crypto/decryptverifyfilescontroller.cpp3
-rw-r--r--src/crypto/decryptverifytask.cpp2
-rw-r--r--src/crypto/gui/resultitemwidget.cpp2
-rw-r--r--src/crypto/signencryptfilescontroller.cpp7
-rw-r--r--src/crypto/verifychecksumscontroller.cpp2
-rw-r--r--src/kleopatraapplication.cpp2
-rw-r--r--src/mainwindow.cpp2
-rw-r--r--src/utils/classify.cpp457
-rw-r--r--src/utils/classify.h154
-rw-r--r--src/utils/input.cpp2
20 files changed, 29 insertions, 632 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7a061fa..12fff7f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,7 +9,7 @@ option(DISABLE_KWATCHGNUPG "Don't build the kwatchgnupg tool [default=OFF]" OFF)
set(KF5_VERSION "5.17.0")
set(GPGMEPP_VERSION "5.2.81")
set(KMIME_VERSION "5.1.40")
-set(LIBKLEO_VERSION "5.3.42")
+set(LIBKLEO_VERSION "5.3.43")
set(QT_REQUIRED_VERSION "5.4.0")
find_package(ECM ${KF5_VERSION} REQUIRED NO_MODULE)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 82e643d..5fbda9e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -75,7 +75,6 @@ set(_kleopatra_SRCS
utils/output.cpp
utils/validation.cpp
utils/wsastarter.cpp
- utils/classify.cpp
utils/iodevicelogger.cpp
utils/log.cpp
utils/action_data.cpp
diff --git a/src/commands/command.cpp b/src/commands/command.cpp
index f60fdab..3533f0b 100644
--- a/src/commands/command.cpp
+++ b/src/commands/command.cpp
@@ -43,8 +43,8 @@
#include "checksumverifyfilescommand.h"
#include <Libkleo/KeyCache>
+#include <Libkleo/Classify>
-#include "utils/classify.h"
#include <view/tabwidget.h>
diff --git a/src/commands/decryptverifyclipboardcommand.cpp b/src/commands/decryptverifyclipboardcommand.cpp
index 69b22fc..3a06ef4 100644
--- a/src/commands/decryptverifyclipboardcommand.cpp
+++ b/src/commands/decryptverifyclipboardcommand.cpp
@@ -43,10 +43,11 @@
#include <utils/input.h>
#include <utils/output.h>
-#include <utils/classify.h>
+
#include <utils/types.h>
#include <Libkleo/Stl_Util>
+#include <Libkleo/Classify>
#include <KLocalizedString>
#include "kleopatra_debug.h"
diff --git a/src/commands/exportcertificatecommand.cpp b/src/commands/exportcertificatecommand.cpp
index 5bc89c3..1b0dfaf 100644
--- a/src/commands/exportcertificatecommand.cpp
+++ b/src/commands/exportcertificatecommand.cpp
@@ -33,17 +33,18 @@
#include <config-kleopatra.h>
#include "exportcertificatecommand.h"
+#include "fileoperationspreferences.h"
#include "command_p.h"
#include <dialogs/exportcertificatesdialog.h>
-#include <utils/classify.h>
#include <utils/filedialog.h>
#include <Libkleo/CryptoBackend>
#include <Libkleo/CryptoBackendFactory>
#include <Libkleo/ExportJob>
+#include <Libkleo/Classify>
#include <gpgme++/key.h>
@@ -208,14 +209,16 @@ bool ExportCertificateCommand::Private::requestFileNames(GpgME::Protocol protoco
}
QString proposedFileName;
- if (keys().size() == 1)
+ if (keys().size() == 1) {
+ const bool usePGPFileExt = FileOperationsPreferences().usePGPFileExt();
proposedFileName
= QString::fromLatin1(keys().front().primaryFingerprint())
+ QLatin1Char('.')
+ QString::fromLatin1(outputFileExtension(protocol == OpenPGP
? Class::OpenPGP | Class::Ascii | Class::Certificate
- : Class::CMS | Class::Ascii | Class::Certificate))
+ : Class::CMS | Class::Ascii | Class::Certificate, usePGPFileExt))
;
+ }
const QString fname = FileDialog::getSaveFileNameEx(parentWidgetOrView(),
i18n("Export Certificates"),
diff --git a/src/commands/importcertificatefromclipboardcommand.cpp b/src/commands/importcertificatefromclipboardcommand.cpp
index 90a5579..6459320 100644
--- a/src/commands/importcertificatefromclipboardcommand.cpp
+++ b/src/commands/importcertificatefromclipboardcommand.cpp
@@ -38,7 +38,7 @@
#include "importcertificatescommand_p.h"
-#include "utils/classify.h"
+#include <Libkleo/Classify>
#include <gpgme++/global.h>
diff --git a/src/commands/importcertificatefromfilecommand.cpp b/src/commands/importcertificatefromfilecommand.cpp
index cd08f92..1a1a67b 100644
--- a/src/commands/importcertificatefromfilecommand.cpp
+++ b/src/commands/importcertificatefromfilecommand.cpp
@@ -35,11 +35,11 @@
#include "importcertificatefromfilecommand.h"
#include "importcertificatescommand_p.h"
-#include "utils/classify.h"
#include "utils/filedialog.h"
#include <Libkleo/CryptoBackendFactory>
#include <Libkleo/ImportJob>
+#include <Libkleo/Classify>
#include <gpgme++/global.h>
#include <gpgme++/importresult.h>
diff --git a/src/crypto/autodecryptverifyfilescontroller.cpp b/src/crypto/autodecryptverifyfilescontroller.cpp
index fb840eb..d058c22 100644
--- a/src/crypto/autodecryptverifyfilescontroller.cpp
+++ b/src/crypto/autodecryptverifyfilescontroller.cpp
@@ -42,7 +42,6 @@
#include "commands/decryptverifyfilescommand.h"
-#include <utils/classify.h>
#include <utils/gnupg-helper.h>
#include <utils/path-helper.h>
#include <utils/input.h>
@@ -50,6 +49,8 @@
#include <utils/kleo_assert.h>
#include <utils/archivedefinition.h>
+#include <Libkleo/Classify>
+
#include <KLocalizedString>
#include <KMessageBox>
#include "kleopatra_debug.h"
diff --git a/src/crypto/createchecksumscontroller.cpp b/src/crypto/createchecksumscontroller.cpp
index bdb6c47..2e9b2f8 100644
--- a/src/crypto/createchecksumscontroller.cpp
+++ b/src/crypto/createchecksumscontroller.cpp
@@ -36,11 +36,11 @@
#include <utils/input.h>
#include <utils/output.h>
-#include <utils/classify.h>
#include <utils/kleo_assert.h>
#include <Libkleo/Stl_Util>
#include <Libkleo/ChecksumDefinition>
+#include <Libkleo/Classify>
#include <KLocalizedString>
#include "kleopatra_debug.h"
diff --git a/src/crypto/decryptverifyemailcontroller.cpp b/src/crypto/decryptverifyemailcontroller.cpp
index deba1cc..a5ac056 100644
--- a/src/crypto/decryptverifyemailcontroller.cpp
+++ b/src/crypto/decryptverifyemailcontroller.cpp
@@ -40,7 +40,6 @@
#include <crypto/decryptverifytask.h>
#include <crypto/taskcollection.h>
-#include <utils/classify.h>
#include <utils/gnupg-helper.h>
#include <utils/input.h>
#include <utils/output.h>
@@ -48,6 +47,7 @@
#include <Libkleo/CryptoBackendFactory>
#include <Libkleo/Formatting>
+#include <Libkleo/Classify>
#include <kmime/kmime_header_parsing.h>
diff --git a/src/crypto/decryptverifyfilescontroller.cpp b/src/crypto/decryptverifyfilescontroller.cpp
index bd118c8..e26db00 100644
--- a/src/crypto/decryptverifyfilescontroller.cpp
+++ b/src/crypto/decryptverifyfilescontroller.cpp
@@ -39,7 +39,6 @@
#include <crypto/decryptverifytask.h>
#include <crypto/taskcollection.h>
-#include <utils/classify.h>
#include <utils/gnupg-helper.h>
#include <utils/path-helper.h>
#include <utils/input.h>
@@ -47,6 +46,8 @@
#include <utils/kleo_assert.h>
#include <utils/archivedefinition.h>
+#include <Libkleo/Classify>
+
#include <KLocalizedString>
#include "kleopatra_debug.h"
diff --git a/src/crypto/decryptverifytask.cpp b/src/crypto/decryptverifytask.cpp
index 673f820..7695677 100644
--- a/src/crypto/decryptverifytask.cpp
+++ b/src/crypto/decryptverifytask.cpp
@@ -45,11 +45,11 @@
#include <Libkleo/KeyCache>
#include <Libkleo/Predicates>
#include <Libkleo/Formatting>
+#include <Libkleo/Classify>
#include <utils/detail_p.h>
#include <utils/input.h>
#include <utils/output.h>
-#include <utils/classify.h>
#include <utils/kleo_assert.h>
#include <utils/auditlog.h>
diff --git a/src/crypto/gui/resultitemwidget.cpp b/src/crypto/gui/resultitemwidget.cpp
index cc8ba91..774cc8b 100644
--- a/src/crypto/gui/resultitemwidget.cpp
+++ b/src/crypto/gui/resultitemwidget.cpp
@@ -35,10 +35,10 @@
#include "resultitemwidget.h"
#include "utils/auditlog.h"
-#include "utils/classify.h"
#include "commands/command.h"
#include <libkleo/messagebox.h>
+#include <Libkleo/Classify>
#include <KLocalizedString>
#include <QPushButton>
diff --git a/src/crypto/signencryptfilescontroller.cpp b/src/crypto/signencryptfilescontroller.cpp
index d529a00..b2faad5 100644
--- a/src/crypto/signencryptfilescontroller.cpp
+++ b/src/crypto/signencryptfilescontroller.cpp
@@ -40,9 +40,10 @@
#include "crypto/gui/signencryptfileswizard.h"
#include "crypto/taskcollection.h"
+#include "fileoperationspreferences.h"
+
#include "utils/input.h"
#include "utils/output.h"
-#include "utils/classify.h"
#include "utils/kleo_assert.h"
#include "utils/archivedefinition.h"
#include "utils/path-helper.h"
@@ -51,6 +52,7 @@
#include <Libkleo/Stl_Util>
#include <Libkleo/Exception>
+#include <Libkleo/Classify>
#include <kmime/kmime_header_parsing.h>
@@ -280,7 +282,8 @@ static const char *extension(bool pgp, bool sign, bool encrypt, bool ascii, bool
cls |= detached ? Class::DetachedSignature : Class::OpaqueSignature;
}
cls |= ascii ? Class::Ascii : Class::Binary;
- if (const char *const ext = outputFileExtension(cls)) {
+ const bool usePGPFileExt = FileOperationsPreferences().usePGPFileExt();
+ if (const char *const ext = outputFileExtension(cls, usePGPFileExt)) {
return ext;
} else {
return "out";
diff --git a/src/crypto/verifychecksumscontroller.cpp b/src/crypto/verifychecksumscontroller.cpp
index a1833b2..58b0661 100644
--- a/src/crypto/verifychecksumscontroller.cpp
+++ b/src/crypto/verifychecksumscontroller.cpp
@@ -40,11 +40,11 @@
#include <utils/input.h>
#include <utils/output.h>
-#include <utils/classify.h>
#include <utils/kleo_assert.h>
#include <Libkleo/Stl_Util>
#include <Libkleo/ChecksumDefinition>
+#include <Libkleo/Classify>
#include <KLocalizedString>
diff --git a/src/kleopatraapplication.cpp b/src/kleopatraapplication.cpp
index 38424e3..f3e8ec5 100644
--- a/src/kleopatraapplication.cpp
+++ b/src/kleopatraapplication.cpp
@@ -44,12 +44,12 @@
#include <utils/kdpipeiodevice.h>
#include <utils/log.h>
#include <utils/getpid.h>
-#include "utils/classify.h"
#include <gpgme++/key.h>
#include <Libkleo/FileSystemWatcher>
#include <Libkleo/KeyCache>
+#include <Libkleo/Classify>
#ifdef HAVE_USABLE_ASSUAN
# include <uiserver/uiserver.h>
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 6c7c0ac..6b5ab0a 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -49,7 +49,6 @@
#include "utils/detail_p.h"
#include "utils/gnupg-helper.h"
#include "utils/action_data.h"
-#include "utils/classify.h"
#include "utils/filedialog.h"
#include "utils/clipboardmenu.h"
@@ -85,6 +84,7 @@
#include <Libkleo/CryptoConfig>
#include <Libkleo/Stl_Util>
#include <Libkleo/CryptoBackendFactory>
+#include <Libkleo/Classify>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
diff --git a/src/utils/classify.cpp b/src/utils/classify.cpp
deleted file mode 100644
index 2199f3f..0000000
--- a/src/utils/classify.cpp
+++ /dev/null
@@ -1,457 +0,0 @@
-/* -*- mode: c++; c-basic-offset:4 -*-
- utils/classify.cpp
-
- This file is part of Kleopatra, the KDE keymanager
- Copyright (c) 2007 Klarälvdalens Datakonsult AB
-
- Kleopatra is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- Kleopatra is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
- In addition, as a special exception, the copyright holders give
- permission to link the code of this program with any edition of
- the Qt library by Trolltech AS, Norway (or with modified versions
- of Qt that use the same license as Qt), and distribute linked
- combinations including the two. You must obey the GNU General
- Public License in all respects for all of the code used other than
- Qt. If you modify this file, you may extend this exception to
- your version of the file, but you are not obligated to do so. If
- you do not wish to do so, delete this exception statement from
- your version.
-*/
-
-#include <config-kleopatra.h>
-
-#include "classify.h"
-
-#include "fileoperationspreferences.h"
-
-#include "kleopatra_debug.h"
-
-#include <QString>
-#include <QStringList>
-#include <QFile>
-#include <QFileInfo>
-#include <QtAlgorithms>
-#include <QByteArrayMatcher>
-#include <QMap>
-#include <QRegularExpression>
-
-#include <boost/range.hpp>
-
-#include <gpgme++/data.h>
-#include <qgpgme/dataprovider.h>
-
-#ifdef __GLIBCXX__
-# include <ext/algorithm>
-#endif
-
-#include <functional>
-
-#include <Libkleo/ChecksumDefinition>
-
-using namespace boost;
-using namespace Kleo::Class;
-
-namespace
-{
-
-const unsigned int ExamineContentHint = 0x8000;
-
-static const struct _classification {
- char extension[4];
- unsigned int classification;
-} classifications[] = {
- // ordered by extension
- { "arl", CMS | Binary | CertificateRevocationList },
- { "asc", OpenPGP | Ascii | OpaqueSignature | DetachedSignature | CipherText | AnyCertStoreType | ExamineContentHint },
- { "cer", CMS | Binary | Certificate },
- { "crl", CMS | Binary | CertificateRevocationList },
- { "crt", CMS | Binary | Certificate },
- { "der", CMS | Binary | Certificate | CertificateRevocationList },
- { "gpg", OpenPGP | Binary | OpaqueSignature | CipherText | AnyCertStoreType | ExamineContentHint},
- { "p10", CMS | Ascii | CertificateRequest },
- { "p12", CMS | Binary | ExportedPSM },
- { "p7c", CMS | Binary | Certificate },
- { "p7m", CMS | Binary | CipherText },
- { "p7s", CMS | Binary | AnySignature },
- { "pem", CMS | Ascii | AnyType | ExamineContentHint },
- { "pfx", CMS | Binary | Certificate },
- { "pgp", OpenPGP | Binary | OpaqueSignature | CipherText | AnyCertStoreType | ExamineContentHint},
- { "sig", OpenPGP | AnyFormat | DetachedSignature },
-};
-
-static const QMap<GpgME::Data::Type, unsigned int> gpgmeTypeMap {
- { GpgME::Data::PGPSigned, OpenPGP | OpaqueSignature },
- /* PGPOther might be just an unencrypted unsigned pgp message. Decrypt
- * would yield the plaintext anyway so for us this is CipherText. */
- { GpgME::Data::PGPOther, OpenPGP | CipherText },
- { GpgME::Data::PGPKey, OpenPGP | Certificate },
- { GpgME::Data::CMSSigned, CMS | AnySignature },
- { GpgME::Data::CMSEncrypted, CMS | CipherText },
- /* See PGPOther */
- { GpgME::Data::CMSOther, CMS | CipherText },
- { GpgME::Data::X509Cert, CMS | Certificate},
- { GpgME::Data::PKCS12, CMS | Binary | ExportedPSM },
- { GpgME::Data::PGPEncrypted, OpenPGP | CipherText },
- { GpgME::Data::PGPSignature, OpenPGP | DetachedSignature },
-};
-
-static const unsigned int defaultClassification = NoClass;
-
-template <template <typename U> class Op>
-struct ByExtension {
- typedef bool result_type;
-
- template <typename T>
- bool operator()(const T &lhs, const T &rhs) const
- {
- return Op<int>()(qstricmp(lhs.extension, rhs.extension), 0);
- }
- template <typename T>
- bool operator()(const T &lhs, const char *rhs) const
- {
- return Op<int>()(qstricmp(lhs.extension, rhs), 0);
- }
- template <typename T>
- bool operator()(const char *lhs, const T &rhs) const
- {
- return Op<int>()(qstricmp(lhs, rhs.extension), 0);
- }
- bool operator()(const char *lhs, const char *rhs) const
- {
- return Op<int>()(qstricmp(lhs, rhs), 0);
- }
-};
-
-static const struct _content_classification {
- char content[28];
- unsigned int classification;
-} content_classifications[] = {
- { "CERTIFICATE", Certificate },
- { "ENCRYPTED MESSAGE", CipherText },
- { "MESSAGE", OpaqueSignature | CipherText },
- { "PKCS12", ExportedPSM },
- { "PRIVATE KEY BLOCK", ExportedPSM },
- { "PUBLIC KEY BLOCK", Certificate },
- { "SIGNATURE", DetachedSignature },
- { "SIGNED MESSAGE", ClearsignedMessage | DetachedSignature },
-};
-
-template <template <typename U> class Op>
-struct ByContent {
- typedef bool result_type;
-
- const unsigned int N;
- explicit ByContent(unsigned int n) : N(n) {}
-
- template <typename T>
- bool operator()(const T &lhs, const T &rhs) const
- {
- return Op<int>()(qstrncmp(lhs.content, rhs.content, N), 0);
- }
- template <typename T>
- bool operator()(const T &lhs, const char *rhs) const
- {
- return Op<int>()(qstrncmp(lhs.content, rhs, N), 0);
- }
- template <typename T>
- bool operator()(const char *lhs, const T &rhs) const
- {
- return Op<int>()(qstrncmp(lhs, rhs.content, N), 0);
- }
- bool operator()(const char *lhs, const char *rhs) const
- {
- return Op<int>()(qstrncmp(lhs, rhs, N), 0);
- }
-};
-
-}
-
-unsigned int Kleo::classify(const QStringList &fileNames)
-{
- if (fileNames.empty()) {
- return 0;
- }
- unsigned int result = classify(fileNames.front());
- Q_FOREACH (const QString &fileName, fileNames) {
- result &= classify(fileName);
- }
- return result;
-}
-
-static unsigned int classifyExtension(const QFileInfo fi)
-{
- const _classification *const it = qBinaryFind(begin(classifications), end(classifications),
- fi.suffix().toLatin1().constData(),
- ByExtension<std::less>());
- if (it != end(classifications))
- if (!(it->classification & ExamineContentHint)) {
- return it->classification;
- }
-
- return it == end(classifications) ? defaultClassification
- : it->classification;
-}
-
-unsigned int Kleo::classify(const QString &filename)
-{
-#ifdef __GLIBCXX__
- assert(__gnu_cxx::is_sorted(begin(classifications), end(classifications), ByExtension<std::less>()));
-#endif
-
- const QFileInfo fi(filename);
-
- if (!fi.exists()) {
- return 0;
- }
-
- QFile file(filename);
- /* The least reliable but always availabe classification */
- const unsigned int extClass = classifyExtension(fi);
- if (!GpgME::hasFeature(0, GpgME::BinaryAndFineGrainedIdentify) &&
- !(extClass & ExamineContentHint)) {
- /* GpgME's identfiy and our internal Classify were so incomplete
- * before BinaryAndFineGrainedIdentify that we are better of
- * to just use the file extension if ExamineContentHint is not set. */
- qCDebug(KLEOPATRA_LOG) << "Classified based only on extension.";
- return extClass;
- }
-
- if (!file.open(QIODevice::ReadOnly)) {
- qCDebug(KLEOPATRA_LOG) << "Failed to open file: " << filename << " for classification.";
- return extClass;
- }
-
- /* More reliable */
- const unsigned int contentClass = classifyContent(file.read(4096));
- if (contentClass != defaultClassification) {
- qCDebug(KLEOPATRA_LOG) << "Classified based on content.";
- return contentClass;
- }
-
- /* Probably some X509 Stuff that GpgME in it's wisdom does not handle. Again
- * file extension is probably more reliable as the last resort. */
- qCDebug(KLEOPATRA_LOG) << "No classification based on content.";
- return extClass;
-}
-
-static unsigned int classifyContentInteral(const QByteArray &data)
-{
-#ifdef __GLIBCXX__
- assert(__gnu_cxx::is_sorted(begin(content_classifications), end(content_classifications), ByContent<std::less>(100)));
-#endif
-
- static const char beginString[] = "-----BEGIN ";
- static const QByteArrayMatcher beginMatcher(beginString);
- int pos = beginMatcher.indexIn(data);
- if (pos < 0) {
- return defaultClassification;
- }
- pos += sizeof beginString - 1;
-
- const bool pgp = qstrncmp(data.data() + pos, "PGP ", 4) == 0;
- if (pgp) {
- pos += 4;
- }
-
- const int epos = data.indexOf("-----\n", pos);
- if (epos < 0) {
- return defaultClassification;
- }
-
- const _content_classification *const cit
- = qBinaryFind(begin(content_classifications), end(content_classifications),
- data.data() + pos, ByContent<std::less>(epos - pos));
-
- if (cit != end(content_classifications)) {
- return cit->classification | (pgp ? OpenPGP : CMS);
- }
- return defaultClassification;
-}
-
-unsigned int Kleo::classifyContent(const QByteArray &data)
-{
- /* As of Version 1.6.0 GpgME does not distinguish between detached
- * signatures and signatures. So we prefer kleo's classification and
- * only use gpgme as fallback.
- * With newer versions we have a better identify that really inspects
- * the PGP Packages. Which is by far the most reliable classification.
- * So this is already used for the default classification. File extensions
- * and our classifyinternal is only used as a fallback.
- */
- if (!GpgME::hasFeature(0, GpgME::BinaryAndFineGrainedIdentify)) {
- unsigned int ourClassification = classifyContentInteral(data);
- if (ourClassification != defaultClassification) {
- return ourClassification;
- }
- }
- QGpgME::QByteArrayDataProvider dp(data);
- GpgME::Data gpgmeData(&dp);
- GpgME::Data::Type type = gpgmeData.type();
-
- return gpgmeTypeMap.value(type, defaultClassification);
-}
-
-QString Kleo::printableClassification(unsigned int classification)
-{
- QStringList parts;
- if (classification & CMS) {
- parts.push_back(QStringLiteral("CMS"));
- }
- if (classification & OpenPGP) {
- parts.push_back(QStringLiteral("OpenPGP"));
- }
- if (classification & Binary) {
- parts.push_back(QStringLiteral("Binary"));
- }
- if (classification & Ascii) {
- parts.push_back(QStringLiteral("Ascii"));
- }
- if (classification & DetachedSignature) {
- parts.push_back(QStringLiteral("DetachedSignature"));
- }
- if (classification & OpaqueSignature) {
- parts.push_back(QStringLiteral("OpaqueSignature"));
- }
- if (classification & ClearsignedMessage) {
- parts.push_back(QStringLiteral("ClearsignedMessage"));
- }
- if (classification & CipherText) {
- parts.push_back(QStringLiteral("CipherText"));
- }
- if (classification & Certificate) {
- parts.push_back(QStringLiteral("Certificate"));
- }
- if (classification & ExportedPSM) {
- parts.push_back(QStringLiteral("ExportedPSM"));
- }
- if (classification & CertificateRequest) {
- parts.push_back(QStringLiteral("CertificateRequest"));
- }
- return parts.join(QStringLiteral(", "));
-}
-
-static QString chopped(QString s, unsigned int n)
-{
- s.chop(n);
- return s;
-}
-
-/*!
- \return the data file that corresponds to the signature file \a
- signatureFileName, or QString(), if no such file can be found.
-*/
-QString Kleo::findSignedData(const QString &signatureFileName)
-{
- if (!mayBeDetachedSignature(signatureFileName)) {
- return QString();
- }
- const QString baseName = chopped(signatureFileName, 4);
- return QFile::exists(baseName) ? baseName : QString();
-}
-
-/*!
- \return all (existing) candiate signature files for \a signedDataFileName
-
- Note that there can very well be more than one such file, e.g. if
- the same data file was signed by both CMS and OpenPGP certificates.
-*/
-QStringList Kleo::findSignatures(const QString &signedDataFileName)
-{
- QStringList result;
- for (unsigned int i = 0, end = size(classifications); i < end; ++i)
- if (classifications[i].classification & DetachedSignature) {
- const QString candiate = signedDataFileName + QLatin1Char('.') + QLatin1String(classifications[i].extension);
- if (QFile::exists(candiate)) {
- result.push_back(candiate);
- }
- }
- return result;
-}
-
-/*!
- \return the (likely) output filename for \a inputFileName, or
- "inputFileName.out" if none can be determined.
-*/
-QString Kleo::outputFileName(const QString &inputFileName)
-{
- const QFileInfo fi(inputFileName);
-
- if (qBinaryFind(begin(classifications), end(classifications),
- fi.suffix().toLatin1().constData(),
- ByExtension<std::less>()) == end(classifications)) {
- return inputFileName + QLatin1String(".out");
- } else {
- return chopped(inputFileName, 4);
- }
-}
-
-/*!
- \return the commonly used extension for files of type
- \a classification, or NULL if none such exists.
-*/
-const char *Kleo::outputFileExtension(unsigned int classification)
-{
-
- if (classification & OpenPGP) {
- FileOperationsPreferences filePrefs;
- if (filePrefs.usePGPFileExt()) {
- return "pgp";
- }
- }
-
- for (unsigned int i = 0; i < sizeof classifications / sizeof * classifications; ++i)
- if ((classifications[i].classification & classification) == classification) {
- return classifications[i].extension;
- }
- return 0;
-}
-
-bool Kleo::isFingerprint(const QString &fpr)
-{
- static QRegularExpression fprRegex("[0-9a-fA-F]{40}");
- return fprRegex.match(fpr).hasMatch();
-}
-
-bool Kleo::isChecksumFile(const QString &file)
-{
- static bool initialized;
- static QList<QRegExp> patterns;
- const QFileInfo fi(file);
- if (!fi.exists()) {
- return false;
- }
- if (!initialized) {
- Q_FOREACH (const shared_ptr<ChecksumDefinition> &cd, ChecksumDefinition::getChecksumDefinitions()) {
- if (cd) {
- Q_FOREACH (const QString &pattern, cd->patterns()) {
-#ifdef Q_OS_WIN
- patterns << QRegExp(pattern, Qt::CaseInsensitive);
-#else
- patterns << QRegExp(pattern, Qt::CaseSensitive);
-#endif
- }
- }
- }
- initialized = true;
- }
-
- const QString fileName = fi.fileName();
- Q_FOREACH (const QRegExp &pattern, patterns) {
- if (pattern.exactMatch(fileName)) {
- return true;
- }
- }
- return false;
-}
diff --git a/src/utils/classify.h b/src/utils/classify.h
deleted file mode 100644
index a978c57..0000000
--- a/src/utils/classify.h
+++ /dev/null
@@ -1,154 +0,0 @@
-/* -*- mode: c++; c-basic-offset:4 -*-
- utils/classify.h
-
- This file is part of Kleopatra, the KDE keymanager
- Copyright (c) 2007 Klarälvdalens Datakonsult AB
-
- Kleopatra is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- Kleopatra is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
- In addition, as a special exception, the copyright holders give
- permission to link the code of this program with any edition of
- the Qt library by Trolltech AS, Norway (or with modified versions
- of Qt that use the same license as Qt), and distribute linked
- combinations including the two. You must obey the GNU General
- Public License in all respects for all of the code used other than
- Qt. If you modify this file, you may extend this exception to
- your version of the file, but you are not obligated to do so. If
- you do not wish to do so, delete this exception statement from
- your version.
-*/
-
-#include <gpgme++/global.h>
-
-#ifndef __KLEOPATRA_UISERVER_CLASSIFY_H__
-#define __KLEOPATRA_UISERVER_CLASSIFY_H__
-
-#include <QByteArray>
-
-class QString;
-class QStringList;
-
-namespace Kleo
-{
-
-namespace Class
-{
-enum {
- NoClass = 0,
-
- // protocol:
- CMS = 0x01,
- OpenPGP = 0x02,
-
- AnyProtocol = OpenPGP | CMS,
- ProtocolMask = AnyProtocol,
-
- // format:
- Binary = 0x04,
- Ascii = 0x08,
-
- AnyFormat = Binary | Ascii,
- FormatMask = AnyFormat,
-
- // type:
- DetachedSignature = 0x010,
- OpaqueSignature = 0x020,
- ClearsignedMessage = 0x040,
-
- AnySignature = DetachedSignature | OpaqueSignature | ClearsignedMessage,
-
- CipherText = 0x080,
-
- AnyMessageType = AnySignature | CipherText,
-
- Importable = 0x100,
- Certificate = 0x200 | Importable,
- ExportedPSM = 0x400 | Importable,
-
- AnyCertStoreType = Certificate | ExportedPSM,
-
- CertificateRequest = 0x800,
-
- CertificateRevocationList = 0x1000,
-
- AnyType = AnyMessageType | AnyCertStoreType | CertificateRequest | CertificateRevocationList,
- TypeMask = AnyType
-};
-}
-
-unsigned int classify(const QString &filename);
-unsigned int classify(const QStringList &fileNames);
-unsigned int classifyContent(const QByteArray &data);
-
-QString findSignedData(const QString &signatureFileName);
-QStringList findSignatures(const QString &signedDataFileName);
-QString outputFileName(const QString &input);
-
-/** Check if a string looks like a fingerprint (SHA1 sum) */
-bool isFingerprint(const QString &fpr);
-
-/** Check if a filename matches a ChecksumDefinition pattern */
-bool isChecksumFile(const QString &file);
-
-const char *outputFileExtension(unsigned int classification);
-
-QString printableClassification(unsigned int classification);
-
-#define make_convenience( What, Mask ) \
- inline bool is##What( const QString & filename ) { \
- return ( classify( filename ) & Class::Mask ) == Class::What ; \
- } \
- inline bool is##What( const unsigned int classifcation ) { \
- return ( classifcation & Class::Mask ) == Class::What ; \
- } \
- inline bool mayBe##What( const QString & filename ) { \
- return classify( filename ) & Class::What ; \
- } \
- inline bool mayBe##What( const unsigned int classifcation ) { \
- return classifcation & Class::What ; \
- }
-
-make_convenience(CMS, ProtocolMask)
-make_convenience(OpenPGP, ProtocolMask)
-
-make_convenience(Binary, FormatMask)
-make_convenience(Ascii, FormatMask)
-
-make_convenience(DetachedSignature, TypeMask)
-make_convenience(OpaqueSignature, TypeMask)
-make_convenience(CipherText, TypeMask)
-make_convenience(AnyMessageType, TypeMask)
-make_convenience(CertificateRevocationList, TypeMask)
-make_convenience(AnyCertStoreType, TypeMask)
-#undef make_convenience
-
-inline GpgME::Protocol findProtocol(const unsigned int classifcation)
-{
- if (isOpenPGP(classifcation)) {
- return GpgME::OpenPGP;
- } else if (isCMS(classifcation)) {
- return GpgME::CMS;
- } else {
- return GpgME::UnknownProtocol;
- }
-}
-inline GpgME::Protocol findProtocol(const QString &filename)
-{
- return findProtocol(classify(filename));
-}
-
-}
-
-#endif /* __KLEOPATRA_UISERVER_CLASSIFY_H__ */
diff --git a/src/utils/input.cpp b/src/utils/input.cpp
index e6202bd..2195ba1 100644
--- a/src/utils/input.cpp
+++ b/src/utils/input.cpp
@@ -35,13 +35,13 @@
#include "input.h"
#include "detail_p.h"
-#include "classify.h"
#include "kdpipeiodevice.h"
#include "log.h"
#include "kleo_assert.h"
#include "cached.h"
#include <Libkleo/Exception>
+#include <Libkleo/Classify>
#include "kleopatra_debug.h"
#include <KLocalizedString>