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

source code of qtopcua/src/opcua/x509/qopcuax509distinguishedname.cpp