File: katesecuretextbuffer_p.h

package info (click to toggle)
kf6-ktexteditor 6.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,676 kB
  • sloc: cpp: 93,343; javascript: 20,925; xml: 237; sh: 20; ansic: 16; makefile: 8
file content (55 lines) | stat: -rw-r--r-- 1,475 bytes parent folder | download | duplicates (2)
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
50
51
52
53
54
55
/*
    SPDX-FileCopyrightText: 2017 KDE Developers

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#ifndef KATE_SECURE_TEXTBUFFER_P_H
#define KATE_SECURE_TEXTBUFFER_P_H

#include <QCryptographicHash>
#include <QObject>
#include <QString>

#include <KAuth/ActionReply>

using namespace KAuth;

/**
 * Class used as KAuth helper binary.
 * It is supposed to be called through KAuth action.
 *
 * It also contains couple of common methods intended to be used
 * directly by TextBuffer as well as from helper binary.
 *
 * This class should only be used by TextBuffer.
 */
class SecureTextBuffer : public QObject
{
    Q_OBJECT

public:
    /**
     * Common helper method
     */
    static void setOwner(const int filedes, const uint ownerId, const uint groupId);

    static const QCryptographicHash::Algorithm checksumAlgorithm = QCryptographicHash::Algorithm::Sha512;

private:
    /**
     * Saves file contents using sets permissions.
     */
    static bool saveFileInternal(const QString &sourceFile, const QString &targetFile, const QByteArray &checksum, const uint ownerId, const uint groupId);

    static bool moveFile(const QString &sourceFile, const QString &targetFile);

public Q_SLOTS:
    /**
     * KAuth action to perform both prepare or move work based on given parameters.
     * We keep this code in one method to prevent multiple KAuth user queries during one save action.
     */
    static ActionReply savefile(const QVariantMap &args);
};

#endif