1 | /* |
2 | This file is part of libkabc. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #ifndef KABC_KEY_H |
22 | #define KABC_KEY_H |
23 | |
24 | #include "kabc_export.h" |
25 | |
26 | #include <QtCore/QDataStream> |
27 | #include <QtCore/QSharedDataPointer> |
28 | |
29 | namespace KABC { |
30 | |
31 | /** |
32 | * @short A class to store an encryption key. |
33 | */ |
34 | class KABC_EXPORT Key |
35 | { |
36 | friend KABC_EXPORT QDataStream &operator<<( QDataStream &, const Key & ); |
37 | friend KABC_EXPORT QDataStream &operator>>( QDataStream &, Key & ); |
38 | |
39 | public: |
40 | /** |
41 | List of keys. |
42 | */ |
43 | typedef QList<Key> List; |
44 | |
45 | /** |
46 | Key types |
47 | */ |
48 | enum Type { |
49 | X509, /**< X509 key */ |
50 | PGP, /**< Pretty Good Privacy key */ |
51 | Custom /**< Custom or IANA conform key */ |
52 | }; |
53 | |
54 | /** |
55 | List of key types. |
56 | */ |
57 | typedef QList<Type> TypeList; |
58 | |
59 | /** |
60 | Creates a new key. |
61 | |
62 | @param text The text data. |
63 | @param type The key type, see Types. |
64 | */ |
65 | explicit Key( const QString &text = QString(), Type type = PGP ); |
66 | |
67 | /** |
68 | Copy constructor. |
69 | */ |
70 | Key( const Key &other ); |
71 | |
72 | /** |
73 | Destroys the key. |
74 | */ |
75 | ~Key(); |
76 | |
77 | /** |
78 | Equality operator. |
79 | */ |
80 | bool operator==( const Key & ) const; |
81 | |
82 | /** |
83 | Not-equal operator. |
84 | */ |
85 | bool operator!=( const Key & ) const; |
86 | |
87 | /** |
88 | Assignment operator. |
89 | |
90 | @param other The Key instance to assign to @c this |
91 | */ |
92 | Key &operator=( const Key &other ); |
93 | |
94 | /** |
95 | Sets the unique @p identifier. |
96 | */ |
97 | void setId( const QString &identifier ); |
98 | |
99 | /** |
100 | Returns the unique identifier. |
101 | */ |
102 | QString id() const; |
103 | |
104 | /** |
105 | Sets binary @p data. |
106 | */ |
107 | void setBinaryData( const QByteArray &data ); |
108 | |
109 | /** |
110 | Returns the binary data. |
111 | */ |
112 | QByteArray binaryData() const; |
113 | |
114 | /** |
115 | Sets text @p data. |
116 | */ |
117 | void setTextData( const QString &data ); |
118 | |
119 | /** |
120 | Returns the text data. |
121 | */ |
122 | QString textData() const; |
123 | |
124 | /** |
125 | Returns whether the key contains binary or text data. |
126 | */ |
127 | bool isBinary() const; |
128 | |
129 | /** |
130 | Sets the @p type. |
131 | |
132 | @param type The type of the key |
133 | |
134 | @see Type |
135 | */ |
136 | void setType( Type type ); |
137 | |
138 | /** |
139 | Sets custom @p type string. |
140 | */ |
141 | void setCustomTypeString( const QString &type ); |
142 | |
143 | /** |
144 | Returns the type, see Type. |
145 | */ |
146 | Type type() const; |
147 | |
148 | /** |
149 | Returns the custom type string. |
150 | */ |
151 | QString customTypeString() const; |
152 | |
153 | /** |
154 | Returns a string representation of the key. |
155 | */ |
156 | QString toString() const; |
157 | |
158 | /** |
159 | Returns a list of all available key types. |
160 | */ |
161 | static TypeList typeList(); |
162 | |
163 | /** |
164 | Returns a translated label for a given key @p type. |
165 | */ |
166 | static QString typeLabel( Type type ); |
167 | |
168 | private: |
169 | class Private; |
170 | QSharedDataPointer<Private> d; |
171 | }; |
172 | |
173 | /** |
174 | Serializes the @p key object into the @p stream. |
175 | */ |
176 | KABC_EXPORT QDataStream &operator<<( QDataStream &stream, const Key &key ); |
177 | |
178 | /** |
179 | Initializes the @p key object from the @p stream. |
180 | */ |
181 | KABC_EXPORT QDataStream &operator>>( QDataStream &stream, Key &key ); |
182 | |
183 | } |
184 | |
185 | #endif |
186 | |