File indexing completed on 2024-09-08 04:18:38
0001 /* 0002 Copyright (C) 2007 Justin Karneges <justin@affinix.com> 0003 0004 Permission is hereby granted, free of charge, to any person obtaining a copy 0005 of this software and associated documentation files (the "Software"), to deal 0006 in the Software without restriction, including without limitation the rights 0007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0008 copies of the Software, and to permit persons to whom the Software is 0009 furnished to do so, subject to the following conditions: 0010 0011 The above copyright notice and this permission notice shall be included in 0012 all copies or substantial portions of the Software. 0013 0014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0017 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 0018 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 0019 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 0020 */ 0021 0022 #ifndef CERTITEM_H 0023 #define CERTITEM_H 0024 0025 #include <QAbstractListModel> 0026 #include <QSharedDataPointer> 0027 0028 class QString; 0029 class QStringList; 0030 0031 namespace QCA { 0032 class PrivateKey; 0033 class CertificateChain; 0034 class KeyStoreEntry; 0035 } 0036 0037 class CertItemStore; 0038 class CertItemStorePrivate; 0039 class CertItemPrivateLoaderPrivate; 0040 0041 class CertItem 0042 { 0043 public: 0044 enum StorageType 0045 { 0046 File, 0047 KeyStore 0048 }; 0049 0050 CertItem(); 0051 CertItem(const CertItem &from); 0052 ~CertItem(); 0053 CertItem &operator=(const CertItem &from); 0054 0055 QString name() const; 0056 QCA::CertificateChain certificateChain() const; 0057 bool havePrivate() const; 0058 StorageType storageType() const; // private key storage type 0059 bool isUsable() const; // file/provider present 0060 0061 private: 0062 class Private; 0063 QSharedDataPointer<Private> d; 0064 0065 friend class CertItemStore; 0066 friend class CertItemStorePrivate; 0067 friend class CertItemPrivateLoader; 0068 friend class CertItemPrivateLoaderPrivate; 0069 }; 0070 0071 class CertItemStore : public QAbstractListModel 0072 { 0073 Q_OBJECT 0074 public: 0075 enum IconType 0076 { 0077 IconCert, 0078 IconCrl, 0079 IconKeyBundle, 0080 IconPgpPub, 0081 IconPgpSec 0082 }; 0083 0084 CertItemStore(QObject *parent = nullptr); 0085 ~CertItemStore(); 0086 0087 int idFromRow(int row) const; 0088 int rowFromId(int id) const; 0089 CertItem itemFromId(int id) const; 0090 CertItem itemFromRow(int row) const; 0091 0092 QList<CertItem> items() const; 0093 0094 QStringList save() const; 0095 bool load(const QStringList &in); 0096 0097 // returns a reqId 0098 int addFromFile(const QString &fileName); 0099 int addFromKeyStore(const QCA::KeyStoreEntry &entry); 0100 int addUser(const QCA::CertificateChain &chain); 0101 0102 void updateChain(int id, const QCA::CertificateChain &chain); 0103 0104 void removeItem(int id); 0105 0106 void setIcon(IconType type, const QPixmap &icon); 0107 0108 // reimplemented 0109 int rowCount(const QModelIndex &parent = QModelIndex()) const; 0110 QVariant data(const QModelIndex &index, int role) const; 0111 Qt::ItemFlags flags(const QModelIndex &index) const; 0112 bool setData(const QModelIndex &index, const QVariant &value, int role); 0113 0114 Q_SIGNALS: 0115 void addSuccess(int reqId, int id); 0116 void addFailed(int reqId); 0117 0118 private: 0119 friend class CertItemStorePrivate; 0120 CertItemStorePrivate *d; 0121 0122 friend class CertItemPrivateLoader; 0123 friend class CertItemPrivateLoaderPrivate; 0124 }; 0125 0126 class CertItemPrivateLoader : public QObject 0127 { 0128 Q_OBJECT 0129 public: 0130 explicit CertItemPrivateLoader(CertItemStore *store, QObject *parent = nullptr); 0131 ~CertItemPrivateLoader(); 0132 0133 void start(int id); 0134 0135 QCA::PrivateKey privateKey() const; 0136 0137 Q_SIGNALS: 0138 void finished(); 0139 0140 private: 0141 friend class CertItemPrivateLoaderPrivate; 0142 CertItemPrivateLoaderPrivate *d; 0143 }; 0144 0145 #endif