1 /* 2 dn.h 3 4 This file is part of qgpgme, the Qt API binding for gpgme 5 Copyright (c) 2004 Klarälvdalens Datakonsult AB 6 Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik 7 Software engineering by Intevation GmbH 8 9 QGpgME is free software; you can redistribute it and/or 10 modify it under the terms of the GNU General Public License as 11 published by the Free Software Foundation; either version 2 of the 12 License, or (at your option) any later version. 13 14 QGpgME is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 23 In addition, as a special exception, the copyright holders give 24 permission to link the code of this program with any edition of 25 the Qt library by Trolltech AS, Norway (or with modified versions 26 of Qt that use the same license as Qt), and distribute linked 27 combinations including the two. You must obey the GNU General 28 Public License in all respects for all of the code used other than 29 Qt. If you modify this file, you may extend this exception to 30 your version of the file, but you are not obligated to do so. If 31 you do not wish to do so, delete this exception statement from 32 your version. 33 */ 34 #ifndef QGPGME_DN_H 35 #define QGPGME_DN_H 36 37 #include "qgpgme_export.h" 38 39 #include <QString> 40 #include <QStringList> 41 42 #include <QVector> 43 44 namespace QGpgME 45 { 46 47 /** 48 @short DN parser and reorderer 49 */ 50 class QGPGME_EXPORT DN 51 { 52 public: 53 class Attribute; 54 typedef QVector<Attribute> AttributeList; 55 typedef AttributeList::const_iterator const_iterator; 56 57 DN(); 58 explicit DN(const QString &dn); 59 explicit DN(const char *utf8DN); 60 DN(const DN &other); 61 ~DN(); 62 63 const DN &operator=(const DN &other); 64 65 /** @return the value in rfc-2253-escaped form */ 66 static QString escape(const QString &value); 67 68 /** @return the DN in a reordered form, according to the settings in 69 the [DN] group of the application's config file */ 70 QString prettyDN() const; 71 /** @return the DN in the original form */ 72 QString dn() const; 73 /** 74 \overload 75 Uses \a sep as separator (default: ,) 76 */ 77 QString dn(const QString &sep) const; 78 79 QString operator[](const QString &attr) const; 80 81 void append(const Attribute &attr); 82 83 const_iterator begin() const; 84 const_iterator end() const; 85 86 /** Set the order in which prettyDN will reorder the Attributes. */ 87 void setAttributeOrder(const QStringList &order) const; 88 89 /** Get the used attribute order. */ 90 const QStringList & attributeOrder() const; 91 92 private: 93 void detach(); 94 private: 95 class Private; 96 Private *d; 97 }; 98 99 class QGPGME_EXPORT DN::Attribute 100 { 101 public: 102 typedef DN::AttributeList List; 103 104 explicit Attribute(const QString &name = QString(), const QString &value = QString()) 105 : mName(name.toUpper()), mValue(value) {} Attribute(const Attribute & other)106 Attribute(const Attribute &other) 107 : mName(other.name()), mValue(other.value()) {} 108 109 const Attribute &operator=(const Attribute &other) 110 { 111 if (this != &other) { 112 mName = other.name(); 113 mValue = other.value(); 114 } 115 return *this; 116 } 117 name()118 const QString &name() const 119 { 120 return mName; 121 } value()122 const QString &value() const 123 { 124 return mValue; 125 } 126 setValue(const QString & value)127 void setValue(const QString &value) 128 { 129 mValue = value; 130 } 131 132 private: 133 QString mName; 134 QString mValue; 135 }; 136 } // namespace QGpgME 137 #endif // QGPGME_DN_H 138