Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
trust_p.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <QtCore/QHash>
9#include <sonde/sonde_core_export.h>
10
11#include <QtCore/QList>
12#include <QtCore/QString>
13#include <QtCore/QStringList>
14
15#include <optional>
16
17namespace Sonde::Trust {
18
20enum class Library {
23};
24
26SONDE_CORE_EXPORT QString libraryName(Library library);
27
31SONDE_CORE_EXPORT QString configDirectory();
32
34SONDE_CORE_EXPORT QString canonicalOrClean(const QString &path);
35
37struct SONDE_CORE_EXPORT Locations
38{
39 QString project;
40 QString checkoutRoot;
42 QString user;
43 QString trustFile;
44
46 QString directory(Library library) const
47 {
48 return library == Library::Project ? project : user;
49 }
50
51 QString scopeKey() const;
52};
53
55struct Start
56{
57 QString directory;
58 QString how;
59};
60
66SONDE_CORE_EXPORT Locations locate(const QList<Start> &starts);
67
69SONDE_CORE_EXPORT QString filePath(const QString &directory, const QString &name, bool component);
70
72SONDE_CORE_EXPORT QString sha256(const QByteArray &data);
73
76{
77 QString name;
78 QString path;
79 QString sha256;
80};
81
83struct Entry
84{
85 QString sha256;
86 QString where;
87 QString how;
88 QString date;
89 QString path;
90 QString name;
91
93 bool operator==(const Entry &other) const
94 {
95 return sha256 == other.sha256 && where == other.where && how == other.how
96 && date == other.date && path == other.path && name == other.name;
97 }
98};
99
101class SONDE_CORE_EXPORT TrustStore
102{
103public:
105 explicit TrustStore(QString file) : m_file(std::move(file)) { }
106
109 QString untrustedReason(const QString &path, const QString &hash,
110 const QString &scopeKey) const;
111
115 bool trust(const QList<TrustedFile> &files, bool everywhere, const QString &scopeKey,
116 const QString &how, QString *error) const;
117
120 std::optional<QList<Entry>> entries(QString *error) const;
121
124 int revoke(const QStringList &paths, QString *error) const;
125
129 int repath(const QHash<QString, QString> &moved, QString *error) const;
130
131private:
132 QString m_file;
133};
134
135} // namespace Sonde::Trust
TrustStore(QString file)
The store in file (read on every call: other processes write it too).
Definition trust_p.h:105
QString m_file
The store's file.
Definition trust_p.h:132
TrustStore(QString file)
The store in file (read on every call: other processes write it too).
Definition trust_p.h:105
QString libraryName(Library library)
"project" or "user".
Definition trust.cpp:84
QString canonicalOrClean(const QString &path)
path made canonical if it exists, otherwise only absolute and clean.
Definition trust.cpp:105
One grant in the trust store.
Definition trust_p.h:84
QString how
"user", "app" or "saved".
Definition trust_p.h:87
QString date
When, in UTC (ISO 8601).
Definition trust_p.h:88
bool operator==(const Entry &other) const
Whether every field is the same.
Definition trust_p.h:93
QString name
Its name then.
Definition trust_p.h:90
QString sha256
The trusted content's hash.
Definition trust_p.h:85
QString where
"everywhere", or the checkout (or executable) it applies to.
Definition trust_p.h:86
QString path
The file's path when it was trusted.
Definition trust_p.h:89
Where the libraries and the trust file are.
Definition trust_p.h:38
QString projectFoundBy
How the project library was found, for the reply.
Definition trust_p.h:41
QString user
The user library's directory (may not exist yet).
Definition trust_p.h:42
QString trustFile
The trust store's file (may not exist yet).
Definition trust_p.h:43
QString checkoutRoot
The checkout's directory (canonical), or empty if none was found.
Definition trust_p.h:40
QString directory(Library library) const
The directory of library (empty for a project library that wasn't found).
Definition trust_p.h:46
QString project
The project library's directory (may not exist yet), or empty.
Definition trust_p.h:39
A directory to search upwards from for the project library, and how to say so.
Definition trust_p.h:56
QString how
For the reply, e.g. "above the working directory".
Definition trust_p.h:58
QString directory
Where the search starts.
Definition trust_p.h:57
A file to trust: how it is named, where it is, and its content's hash.
Definition trust_p.h:76
QString name
A template's name, or the file's path in its library.
Definition trust_p.h:77
QString sha256
The SHA-256 of its content, in hex.
Definition trust_p.h:79
QString path
The full path on disk.
Definition trust_p.h:78
QString sha256(const QByteArray &data)
The SHA-256 of data, in hex.
Definition trust.cpp:162
Locations locate(const QList< Start > &starts)
Finds the libraries and the trust file now (the environment may change).
Definition trust.cpp:117
QString filePath(const QString &directory, const QString &name, bool component)
The file of template or component name in directory.
Definition trust.cpp:156
Library
The two libraries.
Definition trust_p.h:20
@ User
sonde/qml/ in the user's configuration directory.
Definition trust_p.h:22
@ Project
.sonde/qml/ in the checkout.
Definition trust_p.h:21