aboutsummaryrefslogtreecommitdiff
path: root/lib/pluginloader/pluginloader.h
blob: bb5e1e0aa5bfe3bf3734d9e3ef3a3807fd1549c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * This file is part of smolbote. It's copyrighted by the contributors recorded
 * in the version control history of the file, available from its original
 * location: https://library.iserlohn-fortress.net/aqua/smolbote.git
 *
 * SPDX-License-Identifier: GPL-3.0
 */

#include <QPluginLoader>

class PluginLoader : public QPluginLoader
{
public:
    enum signature_level {
        SigIgnored = 1,
        SigChecked = (1 << 1),
        SigEnforced = (1 << 2),
    };
    static constexpr signature_level signature_state(bool ignore, bool check, bool enforce)
    {
        return enforce ? signature_level::SigEnforced : (check ? signature_level::SigChecked : signature_level::SigIgnored);
    }

    PluginLoader(const QString &fileName, const signature_level state, QObject *parent = nullptr)
        : QPluginLoader(fileName, parent)
        , m_state(state)
    {
    }
    ~PluginLoader() override = default;

    PluginLoader(const PluginLoader &) = delete;
    PluginLoader &operator=(const PluginLoader &) = delete;
    PluginLoader(PluginLoader &&) = delete;
    PluginLoader &operator=(PluginLoader &&) = delete;

    [[nodiscard]] QString errorString() const
    {
        if(!m_sigError.isEmpty()) {
            return m_sigError;
        }
        return QPluginLoader::errorString();
    }

    bool verify(const char *hashName = "SHA256");

private:
    const signature_level m_state;
    QString m_sigError;
};