File indexing completed on 2024-04-14 03:51:26

0001 /*
0002     This file is part of the KContacts framework.
0003     SPDX-FileCopyrightText: 2002 Tobias Koenig <tokoe@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KCONTACTS_KEY_H
0009 #define KCONTACTS_KEY_H
0010 
0011 #include "kcontacts_export.h"
0012 
0013 #include <QDataStream>
0014 #include <QSharedDataPointer>
0015 
0016 namespace KContacts
0017 {
0018 /**
0019  * @short A class to store an encryption key.
0020  */
0021 class KCONTACTS_EXPORT Key
0022 {
0023     friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const Key &);
0024     friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, Key &);
0025 
0026 public:
0027     /**
0028       List of keys.
0029     */
0030     typedef QList<Key> List;
0031 
0032     /**
0033       Key types
0034     */
0035     enum Type {
0036         X509, /**< X509 key */
0037         PGP, /**< Pretty Good Privacy key */
0038         Custom, /**< Custom or IANA conform key */
0039     };
0040 
0041     /**
0042       List of key types.
0043     */
0044     typedef QList<Type> TypeList;
0045 
0046     /**
0047       Creates a new key.
0048 
0049       @param text  The text data.
0050       @param type  The key type, see Types.
0051     */
0052     explicit Key(const QString &text = QString(), Type type = PGP);
0053 
0054     /**
0055       Copy constructor.
0056     */
0057     Key(const Key &other);
0058 
0059     /**
0060       Destroys the key.
0061     */
0062     ~Key();
0063 
0064     /**
0065       Equality operator.
0066     */
0067     Q_REQUIRED_RESULT bool operator==(const Key &other) const;
0068 
0069     /**
0070       Not-equal operator.
0071     */
0072     Q_REQUIRED_RESULT bool operator!=(const Key &other) const;
0073 
0074     /**
0075       Assignment operator.
0076 
0077       @param other The Key instance to assign to @c this
0078     */
0079     Key &operator=(const Key &other);
0080 
0081     /**
0082       Sets the unique @p identifier.
0083     */
0084     void setId(const QString &identifier);
0085 
0086     /**
0087       Returns the unique identifier.
0088     */
0089     Q_REQUIRED_RESULT QString id() const;
0090 
0091     /**
0092       Sets binary @p data.
0093     */
0094     void setBinaryData(const QByteArray &data);
0095 
0096     /**
0097       Returns the binary data.
0098     */
0099     Q_REQUIRED_RESULT QByteArray binaryData() const;
0100 
0101     /**
0102       Sets text @p data.
0103     */
0104     void setTextData(const QString &data);
0105 
0106     /**
0107       Returns the text data.
0108     */
0109     Q_REQUIRED_RESULT QString textData() const;
0110 
0111     /**
0112       Returns whether the key contains binary or text data.
0113     */
0114     Q_REQUIRED_RESULT bool isBinary() const;
0115 
0116     /**
0117       Sets the @p type.
0118 
0119       @param type The type of the key
0120 
0121       @see Type
0122     */
0123     void setType(Type type);
0124 
0125     /**
0126       Sets custom @p type string.
0127     */
0128     void setCustomTypeString(const QString &type);
0129 
0130     /**
0131       Returns the type, see Type.
0132     */
0133     Q_REQUIRED_RESULT Type type() const;
0134 
0135     /**
0136       Returns the custom type string.
0137     */
0138     Q_REQUIRED_RESULT QString customTypeString() const;
0139 
0140     /**
0141       Returns a string representation of the key.
0142     */
0143     Q_REQUIRED_RESULT QString toString() const;
0144 
0145     /**
0146       Returns a list of all available key types.
0147     */
0148     Q_REQUIRED_RESULT static TypeList typeList();
0149 
0150     /**
0151       Returns a translated label for a given key @p type.
0152     */
0153     Q_REQUIRED_RESULT static QString typeLabel(Type type);
0154 
0155 private:
0156     class Private;
0157     QSharedDataPointer<Private> d;
0158 };
0159 
0160 /**
0161   Serializes the @p key object into the @p stream.
0162 */
0163 KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const Key &key);
0164 
0165 /**
0166   Initializes the @p key object from the @p stream.
0167 */
0168 KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, Key &key);
0169 }
0170 Q_DECLARE_TYPEINFO(KContacts::Key, Q_RELOCATABLE_TYPE);
0171 #endif