Libkleo

expirychecker.h
1/*
2 This file is part of libkleopatra, the KDE keymanagement library
3 SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB
4 SPDX-FileCopyrightText: 2021 Sandro Knauß <sknauss@kde.org>
5 SPDX-FileCopyrightText: 2023 g10 Code GmbH
6 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
7
8 Based on kpgp.h
9 Copyright (C) 2001,2002 the KPGP authors
10 See file libkdenetwork/AUTHORS.kpgp for details
11
12 SPDX-License-Identifier: LGPL-2.0-or-later
13*/
14
15#pragma once
16
17#include "kleo_export.h"
18
19#include <Libkleo/Chrono>
20
21#include <QDate>
22#include <QObject>
23
24#include <gpgme++/key.h>
25
26#include <memory>
27
28namespace Kleo
29{
30
31class ExpiryCheckerPrivate;
32class ExpiryCheckerSettings;
33
34class KLEO_EXPORT TimeProvider
35{
36public:
37 virtual ~TimeProvider() = default;
38
39 virtual qint64 currentTime() const = 0;
40 virtual QDate currentDate() const = 0;
41 virtual QTimeZone timeZone() const = 0;
42};
43
44class KLEO_EXPORT ExpiryChecker : public QObject
45{
46 Q_OBJECT
47public:
48 enum CheckFlag {
49 EncryptionKey = 0x01,
50 SigningKey = 0x02,
51 CertificationKey = 0x04,
52 OwnKey = 0x08,
53 OwnEncryptionKey = OwnKey | EncryptionKey,
54 OwnSigningKey = OwnKey | SigningKey,
55 CheckChain = 0x10,
56 UsageMask = EncryptionKey | SigningKey | CertificationKey,
57 };
58 Q_FLAG(CheckFlag)
59 Q_DECLARE_FLAGS(CheckFlags, CheckFlag)
60 Q_FLAG(CheckFlags)
61
62 enum ExpirationStatus {
63 NotNearExpiry,
64 ExpiresSoon,
65 Expired,
66 NoSuitableSubkey,
67 InvalidKey,
68 InvalidCheckFlags,
69 };
70 Q_ENUM(ExpirationStatus)
71
72 struct Expiration {
73 GpgME::Key certificate;
74 ExpirationStatus status;
75 // duration is days until expiry if status is ExpiresSoon (i.e. 0
76 // if expiry is today, 1 if it's tomorrow, etc.),
77 // days since expiry if status is Expired, and
78 // undefined otherwise
79 Kleo::chrono::days duration;
80 };
81
82 struct Result {
83 CheckFlags checkFlags;
84 Expiration expiration; // result for the checked certificate
85 std::vector<Expiration> chainExpiration; // results for expired or soon expiring chain certificates
86 };
87
88 explicit ExpiryChecker(const ExpiryCheckerSettings &settings, QObject *parent = nullptr);
89
90 ~ExpiryChecker() override;
91
92 [[nodiscard]] ExpiryCheckerSettings settings() const;
93
94 enum ExpiryInformation {
95 OwnKeyExpired,
96 OwnKeyNearExpiry,
97 OtherKeyExpired,
98 OtherKeyNearExpiry,
99 };
100 Q_ENUM(ExpiryInformation)
101
102 Result checkKey(const GpgME::Key &key, CheckFlags flags) const;
103
104Q_SIGNALS:
105 void expiryMessage(const GpgME::Key &key, QString msg, Kleo::ExpiryChecker::ExpiryInformation info, bool isNewMessage) const;
106
107public:
108 void setTimeProviderForTest(const std::shared_ptr<TimeProvider> &);
109
110private:
111 std::unique_ptr<ExpiryCheckerPrivate> const d;
112};
113}
114
115Q_DECLARE_OPERATORS_FOR_FLAGS(Kleo::ExpiryChecker::CheckFlags)
116Q_DECLARE_METATYPE(Kleo::ExpiryChecker::CheckFlags)
117Q_DECLARE_METATYPE(Kleo::ExpiryChecker::ExpiryInformation)
Q_SCRIPTABLE CaptureState status()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:11:57 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.