File indexing completed on 2024-09-15 03:40:09
0001 /* 0002 SPDX-FileCopyrightText: 2017 KDE Developers 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KATE_SECURE_TEXTBUFFER_P_H 0008 #define KATE_SECURE_TEXTBUFFER_P_H 0009 0010 #include <QCryptographicHash> 0011 #include <QObject> 0012 #include <QString> 0013 0014 #include <KAuth/ActionReply> 0015 0016 using namespace KAuth; 0017 0018 /** 0019 * Class used as KAuth helper binary. 0020 * It is supposed to be called through KAuth action. 0021 * 0022 * It also contains couple of common methods intended to be used 0023 * directly by TextBuffer as well as from helper binary. 0024 * 0025 * This class should only be used by TextBuffer. 0026 */ 0027 class SecureTextBuffer : public QObject 0028 { 0029 Q_OBJECT 0030 0031 public: 0032 /** 0033 * Common helper method 0034 */ 0035 static void setOwner(const int filedes, const uint ownerId, const uint groupId); 0036 0037 static const QCryptographicHash::Algorithm checksumAlgorithm = QCryptographicHash::Algorithm::Sha512; 0038 0039 private: 0040 /** 0041 * Saves file contents using sets permissions. 0042 */ 0043 static bool saveFileInternal(const QString &sourceFile, const QString &targetFile, const QByteArray &checksum, const uint ownerId, const uint groupId); 0044 0045 static bool moveFile(const QString &sourceFile, const QString &targetFile); 0046 0047 public Q_SLOTS: 0048 /** 0049 * KAuth action to perform both prepare or move work based on given parameters. 0050 * We keep this code in one method to prevent multiple KAuth user queries during one save action. 0051 */ 0052 static ActionReply savefile(const QVariantMap &args); 0053 }; 0054 0055 #endif