1 | /* |
2 | This file is part of the KContacts framework. |
3 | SPDX-FileCopyrightText: 2002 Tobias Koenig <tokoe@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef KCONTACTS_KEY_H |
9 | #define KCONTACTS_KEY_H |
10 | |
11 | #include "kcontacts_export.h" |
12 | |
13 | #include <QDataStream> |
14 | #include <QSharedDataPointer> |
15 | |
16 | namespace KContacts |
17 | { |
18 | /** |
19 | * @short A class to store an encryption key. |
20 | */ |
21 | class KCONTACTS_EXPORT Key |
22 | { |
23 | friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const Key &); |
24 | friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, Key &); |
25 | |
26 | public: |
27 | /** |
28 | List of keys. |
29 | */ |
30 | typedef QList<Key> List; |
31 | |
32 | /** |
33 | Key types |
34 | */ |
35 | enum Type { |
36 | X509, /**< X509 key */ |
37 | PGP, /**< Pretty Good Privacy key */ |
38 | Custom, /**< Custom or IANA conform key */ |
39 | }; |
40 | |
41 | /** |
42 | List of key types. |
43 | */ |
44 | typedef QList<Type> TypeList; |
45 | |
46 | /** |
47 | Creates a new key. |
48 | |
49 | @param text The text data. |
50 | @param type The key type, see Types. |
51 | */ |
52 | explicit Key(const QString &text = QString(), Type type = PGP); |
53 | |
54 | /** |
55 | Copy constructor. |
56 | */ |
57 | Key(const Key &other); |
58 | |
59 | /** |
60 | Destroys the key. |
61 | */ |
62 | ~Key(); |
63 | |
64 | /** |
65 | Equality operator. |
66 | */ |
67 | Q_REQUIRED_RESULT bool operator==(const Key &other) const; |
68 | |
69 | /** |
70 | Not-equal operator. |
71 | */ |
72 | Q_REQUIRED_RESULT bool operator!=(const Key &other) const; |
73 | |
74 | /** |
75 | Assignment operator. |
76 | |
77 | @param other The Key instance to assign to @c this |
78 | */ |
79 | Key &operator=(const Key &other); |
80 | |
81 | /** |
82 | Sets the unique @p identifier. |
83 | */ |
84 | void setId(const QString &identifier); |
85 | |
86 | /** |
87 | Returns the unique identifier. |
88 | */ |
89 | Q_REQUIRED_RESULT QString id() const; |
90 | |
91 | /** |
92 | Sets binary @p data. |
93 | */ |
94 | void setBinaryData(const QByteArray &data); |
95 | |
96 | /** |
97 | Returns the binary data. |
98 | */ |
99 | Q_REQUIRED_RESULT QByteArray binaryData() const; |
100 | |
101 | /** |
102 | Sets text @p data. |
103 | */ |
104 | void setTextData(const QString &data); |
105 | |
106 | /** |
107 | Returns the text data. |
108 | */ |
109 | Q_REQUIRED_RESULT QString textData() const; |
110 | |
111 | /** |
112 | Returns whether the key contains binary or text data. |
113 | */ |
114 | Q_REQUIRED_RESULT bool isBinary() const; |
115 | |
116 | /** |
117 | Sets the @p type. |
118 | |
119 | @param type The type of the key |
120 | |
121 | @see Type |
122 | */ |
123 | void setType(Type type); |
124 | |
125 | /** |
126 | Sets custom @p type string. |
127 | */ |
128 | void setCustomTypeString(const QString &type); |
129 | |
130 | /** |
131 | Returns the type, see Type. |
132 | */ |
133 | Q_REQUIRED_RESULT Type type() const; |
134 | |
135 | /** |
136 | Returns the custom type string. |
137 | */ |
138 | Q_REQUIRED_RESULT QString customTypeString() const; |
139 | |
140 | /** |
141 | Returns a string representation of the key. |
142 | */ |
143 | Q_REQUIRED_RESULT QString toString() const; |
144 | |
145 | /** |
146 | Returns a list of all available key types. |
147 | */ |
148 | Q_REQUIRED_RESULT static TypeList typeList(); |
149 | |
150 | /** |
151 | Returns a translated label for a given key @p type. |
152 | */ |
153 | Q_REQUIRED_RESULT static QString typeLabel(Type type); |
154 | |
155 | private: |
156 | class Private; |
157 | QSharedDataPointer<Private> d; |
158 | }; |
159 | |
160 | /** |
161 | Serializes the @p key object into the @p stream. |
162 | */ |
163 | KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const Key &key); |
164 | |
165 | /** |
166 | Initializes the @p key object from the @p stream. |
167 | */ |
168 | KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, Key &key); |
169 | } |
170 | Q_DECLARE_TYPEINFO(KContacts::Key, Q_RELOCATABLE_TYPE); |
171 | #endif |
172 | |