Warning, file /utilities/kgpg/core/KGpgKeyNode.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2008, 2009, 2010, 2012, 2013 Rolf Eike Beer <kde@opensource.sf-tec.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #ifndef KGPGKEYNODE_H 0008 #define KGPGKEYNODE_H 0009 0010 #include "KGpgSignableNode.h" 0011 #include "KGpgSignNode.h" 0012 0013 #include "kgpgkey.h" 0014 0015 class KGpgRefNode; 0016 0017 /** 0018 * @brief A public key with or without corresponding secret key 0019 */ 0020 class KGpgKeyNode : public KGpgSignableNode 0021 { 0022 Q_OBJECT 0023 0024 friend class KGpgGroupMemberNode; 0025 0026 private: 0027 KgpgCore::KgpgKey *m_key; 0028 int m_signs; 0029 0030 protected: 0031 void readChildren() override; 0032 0033 QList<KGpgRefNode *> m_refs; 0034 QList<KGpgRefNode *> getRefsOfType(const KgpgCore::KgpgItemType &type) const; 0035 0036 public: 0037 typedef QList<KGpgKeyNode *> List; 0038 typedef QList<const KGpgKeyNode *> ConstList; 0039 0040 explicit KGpgKeyNode(KGpgRootNode *parent, const KgpgCore::KgpgKey &k); 0041 ~KGpgKeyNode() override; 0042 0043 bool hasChildren() const override; 0044 0045 static KgpgCore::KgpgItemType getType(const KgpgCore::KgpgKey *k); 0046 0047 KgpgCore::KgpgItemType getType() const override; 0048 KgpgCore::KgpgKeyTrust getTrust() const override; 0049 const QString &getFingerprint() const; 0050 QString getSize() const override; 0051 QString getName() const override; 0052 QString getEmail() const override; 0053 QDateTime getExpiration() const override; 0054 QDateTime getCreation() const override; 0055 QString getId() const override; 0056 KGpgKeyNode *getKeyNode(void) override; 0057 const KGpgKeyNode *getKeyNode(void) const override; 0058 /** 0059 * @brief Return if this key has a private key 0060 */ 0061 bool isSecret() const; 0062 /** 0063 * @brief Print the full key fingerprint with spaces inserted 0064 * 0065 * For display purposes you normally don't want to print the full 0066 * fingerprint as is because it's too many hex characters at once. 0067 * This function returns the fingerprint in the format usually used 0068 * for printing this out, i.e. with a space after each fourth hex 0069 * character. 0070 * 0071 * @return the full fingerprint with spaces inserted 0072 */ 0073 QString getBeautifiedFingerprint() const; 0074 QString getComment() const override; 0075 /** 0076 * @brief Return the number of signatures of the primary user id 0077 * 0078 * This is different from the number of children of this node as there 0079 * is usually at least one subkey and there may also be additional 0080 * user ids or attributes. This does not count the signatures to those 0081 * slave objects, only the ones that are direct children of this node. 0082 * 0083 * @return the number of signatures to the primary user id 0084 */ 0085 QString getSignCount() const override; 0086 /** 0087 * @brief Creates a copy of the KgpgKey that belongs to this class 0088 */ 0089 virtual KgpgCore::KgpgKey *copyKey() const; 0090 /** 0091 * @brief Replaces the current key information with the new one. 0092 * All sub-items (i.e. signatures, user ids ...) will be deleted. This must 0093 * only be used when the id of both new and old key is the same. 0094 */ 0095 void setKey(const KgpgCore::KgpgKey &key); 0096 /** 0097 * @brief Returns a reference to the key used in this object. 0098 * This allows direct access to the values of the key e.g. for KgpgKeyInfo. 0099 */ 0100 const KgpgCore::KgpgKey *getKey() const; 0101 0102 /** 0103 * @brief Returns the size of the signing key. 0104 * @return signing key size in bits 0105 */ 0106 virtual unsigned int getSignKeySize() const; 0107 /** 0108 * @brief Returns the size of the first encryption subkey. 0109 * @return encryption key size in bits 0110 */ 0111 virtual unsigned int getEncryptionKeySize() const; 0112 /** 0113 * @brief Notify this key that a KGpgRefNode now references this key. 0114 * @param node object that takes the reference 0115 */ 0116 void addRef(KGpgRefNode *node); 0117 /** 0118 * @brief Remove a reference to this object 0119 * @param node node that no longer has the reference 0120 * 0121 * Note that this must not be called as reply when this object 0122 * emits updated(nullptr) 0123 */ 0124 void delRef(KGpgRefNode *node); 0125 /** 0126 * @brief returns a list of all groups this key is member of 0127 */ 0128 QList<KGpgGroupNode *> getGroups(void) const; 0129 /** 0130 * @brief returns a list of all group member nodes that reference this key 0131 */ 0132 QList<KGpgGroupMemberNode *> getGroupRefs(void) const; 0133 /** 0134 * @brief returns a list of all sign nodes that reference this key 0135 */ 0136 KGpgSignNode::List getSignRefs(void) const; 0137 /** 0138 * @brief returns a list of signatures to this key 0139 * @param subkeys if signatures on subkeys should be included 0140 */ 0141 KGpgSignNode::List getSignatures(const bool subkeys) const; 0142 /** 0143 * @brief get the user id or user attribute with the given number 0144 * @param index the index of the user id to return 0145 * @return the requested subitem or nullptr if that is not present 0146 * 0147 * User ids indexes are 1-based, so 0 is not a valid index. Passing 0148 * 1 as index will return the object itself, representing the primary 0149 * user id. 0150 */ 0151 const KGpgSignableNode *getUid(const unsigned int index) const; 0152 0153 /** 0154 * @brief compare the id of this node to the given other node 0155 * @param other key id to compare to 0156 * @return if ids are identical 0157 * 0158 * This handles different length of the id string. 0159 */ 0160 bool compareId(const QString &other) const; 0161 0162 /** 0163 * @brief return if this key can be used for encryption 0164 */ 0165 bool canEncrypt() const; 0166 0167 Q_SIGNALS: 0168 void expanded(); 0169 0170 public Q_SLOTS: 0171 /** 0172 * @brief read all subitems 0173 * 0174 * This will read in all subitems (e.g. subkeys, signatures). When 0175 * this is done the expanded() signal is emitted. The signal is emitted 0176 * immediately if the key has been expanded before. 0177 * 0178 * This will not update the child items in case they are already present. 0179 * Use KGpgItemModel::refreshKey() instead. 0180 */ 0181 void expand(); 0182 }; 0183 0184 #endif /* KGPGKEYNODE_H */