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

source code of kcontacts/src/key.h