| 1 | // Copyright (C) 2019 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qopcuax509distinguishedname.h" |
| 5 | #include <QtCore/QMap> |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | using namespace Qt::Literals::StringLiterals; |
| 10 | |
| 11 | /*! |
| 12 | \class QOpcUaX509DistinguishedName |
| 13 | \inmodule QtOpcUa |
| 14 | \since 5.14 |
| 15 | |
| 16 | \brief Information about a distinguished name item. |
| 17 | |
| 18 | This class is currently available as a Technology Preview, and therefore the API |
| 19 | and functionality provided by the class may be subject to change at any time without |
| 20 | prior notice. |
| 21 | |
| 22 | \code |
| 23 | QOpcUaX509DistinguishedName dn; |
| 24 | dn.setEntry(QOpcUaX509DistinguishedName::Type::CommonName, "QtOpcUaViewer"); |
| 25 | dn.setEntry(QOpcUaX509DistinguishedName::Type::CountryName, "DE"); |
| 26 | dn.setEntry(QOpcUaX509DistinguishedName::Type::LocalityName, "Berlin"); |
| 27 | dn.setEntry(QOpcUaX509DistinguishedName::Type::StateOrProvinceName, "Berlin"); |
| 28 | dn.setEntry(QOpcUaX509DistinguishedName::Type::OrganizationName, "The Qt Company"); |
| 29 | \endcode |
| 30 | |
| 31 | \sa QOpcUaX509CertificateSigningRequest |
| 32 | */ |
| 33 | |
| 34 | /*! |
| 35 | \enum QOpcUaX509DistinguishedName::Type |
| 36 | |
| 37 | Enum with entry types for X509DistinguishedName. |
| 38 | |
| 39 | \value CommonName |
| 40 | Common name |
| 41 | \value CountryName |
| 42 | Country name |
| 43 | \value LocalityName |
| 44 | Locality name |
| 45 | \value StateOrProvinceName |
| 46 | State or province name |
| 47 | \value OrganizationName |
| 48 | Organization name |
| 49 | */ |
| 50 | |
| 51 | class QOpcUaX509DistinguishedNameData : public QSharedData |
| 52 | { |
| 53 | public: |
| 54 | QMap<QOpcUaX509DistinguishedName::Type, QString> entries; |
| 55 | }; |
| 56 | |
| 57 | /*! |
| 58 | Constructs an empty X509DistinguishedName. |
| 59 | */ |
| 60 | QOpcUaX509DistinguishedName::QOpcUaX509DistinguishedName() |
| 61 | : data(new QOpcUaX509DistinguishedNameData) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | /*! |
| 66 | Destructs a X509DistinguishedName. |
| 67 | */ |
| 68 | QOpcUaX509DistinguishedName::~QOpcUaX509DistinguishedName() |
| 69 | { |
| 70 | } |
| 71 | |
| 72 | /*! |
| 73 | Constructs a X509DistinguishedName from \a rhs. |
| 74 | */ |
| 75 | QOpcUaX509DistinguishedName::QOpcUaX509DistinguishedName(const QOpcUaX509DistinguishedName &rhs) |
| 76 | : data(rhs.data) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | /*! |
| 81 | Sets the values from \a rhs in this X509DistinguishedName. |
| 82 | */ |
| 83 | QOpcUaX509DistinguishedName &QOpcUaX509DistinguishedName::operator=(const QOpcUaX509DistinguishedName &rhs) |
| 84 | { |
| 85 | if (this != &rhs) |
| 86 | data.operator=(o: rhs.data); |
| 87 | return *this; |
| 88 | } |
| 89 | |
| 90 | /*! |
| 91 | Returns \c true if this X509DistinguishedName has the same value as \a rhs. |
| 92 | */ |
| 93 | bool QOpcUaX509DistinguishedName::operator==(const QOpcUaX509DistinguishedName &rhs) const |
| 94 | { |
| 95 | return data->entries == rhs.data->entries; |
| 96 | } |
| 97 | |
| 98 | /*! |
| 99 | Sets the entry of \a type to \a value. |
| 100 | Already existing types will be overwritten. |
| 101 | */ |
| 102 | void QOpcUaX509DistinguishedName::setEntry(QOpcUaX509DistinguishedName::Type type, const QString &value) |
| 103 | { |
| 104 | data->entries.insert(key: type, value); |
| 105 | } |
| 106 | |
| 107 | /*! |
| 108 | Returns the object id string for \a type. |
| 109 | */ |
| 110 | QString QOpcUaX509DistinguishedName::typeToOid(QOpcUaX509DistinguishedName::Type type) |
| 111 | { |
| 112 | switch (type) { |
| 113 | case Type::CommonName: |
| 114 | return u"2.5.4.3"_s; |
| 115 | case Type::CountryName: |
| 116 | return u"2.5.4.6"_s; |
| 117 | case Type::LocalityName: |
| 118 | return u"2.5.4.7"_s; |
| 119 | case Type::StateOrProvinceName: |
| 120 | return u"2.5.4.8"_s; |
| 121 | case Type::OrganizationName: |
| 122 | return u"2.5.4.10"_s; |
| 123 | default: |
| 124 | return QString(); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | /*! |
| 129 | Returns value for a \a type. |
| 130 | */ |
| 131 | QString QOpcUaX509DistinguishedName::entry(QOpcUaX509DistinguishedName::Type type) const |
| 132 | { |
| 133 | return data->entries.value(key: type); |
| 134 | } |
| 135 | |
| 136 | QT_END_NAMESPACE |
| 137 |
