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 "qopcuax509extensionextendedkeyusage.h" |
5 | #include "qopcuax509extension_p.h" |
6 | #include <QSet> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | /*! |
11 | \class QOpcUaX509ExtensionExtendedKeyUsage |
12 | \inmodule QtOpcUa |
13 | \since 5.14 |
14 | |
15 | \brief Class for X509 extended key usage. |
16 | |
17 | This class is currently available as a Technology Preview, and therefore the API |
18 | and functionality provided by the class may be subject to change at any time without |
19 | prior notice. |
20 | */ |
21 | |
22 | /*! |
23 | \enum QOpcUaX509ExtensionExtendedKeyUsage::KeyUsage |
24 | |
25 | Enum with entry types for X509ExtensionExtendedKeyUsage. |
26 | |
27 | \value TlsWebServerAuthentication |
28 | Permits TLS webserver Authentication |
29 | \value TlsWebClientAuthentication |
30 | Permits TLS client authentication |
31 | \value SignExecutableCode |
32 | Permits signature of executable code |
33 | \value EmailProtection |
34 | Permits signing emails |
35 | */ |
36 | |
37 | class QOpcUaX509ExtensionExtendedKeyUsageData : public QOpcUaX509ExtensionData |
38 | { |
39 | public: |
40 | ~QOpcUaX509ExtensionExtendedKeyUsageData() override = default; |
41 | QSet<QOpcUaX509ExtensionExtendedKeyUsage::KeyUsage> keyUsage; |
42 | }; |
43 | |
44 | /*! |
45 | Constructs a X509ExtensionExtendedKeyUsage. |
46 | */ |
47 | QOpcUaX509ExtensionExtendedKeyUsage::QOpcUaX509ExtensionExtendedKeyUsage() |
48 | : QOpcUaX509Extension(new QOpcUaX509ExtensionExtendedKeyUsageData) |
49 | { |
50 | |
51 | } |
52 | |
53 | /*! |
54 | Constructs a X509ExtensionExtendedKeyUsage from \a rhs. |
55 | */ |
56 | QOpcUaX509ExtensionExtendedKeyUsage::QOpcUaX509ExtensionExtendedKeyUsage(const QOpcUaX509ExtensionExtendedKeyUsage &rhs) |
57 | : QOpcUaX509Extension(rhs.data) |
58 | { |
59 | } |
60 | |
61 | /*! |
62 | Returns \c true if this X509ExtensionExtendedKeyUsage has the same value as \a rhs. |
63 | */ |
64 | bool QOpcUaX509ExtensionExtendedKeyUsage::operator==(const QOpcUaX509ExtensionExtendedKeyUsage &rhs) const |
65 | { |
66 | return data->critical == rhs.data->critical; |
67 | } |
68 | |
69 | /*! |
70 | Destructs a X509ExtensionExtendedKeyUsage. |
71 | */ |
72 | QOpcUaX509ExtensionExtendedKeyUsage::~QOpcUaX509ExtensionExtendedKeyUsage() |
73 | { |
74 | } |
75 | |
76 | /*! |
77 | Sets the values from \a rhs in this X509ExtensionExtendedKeyUsage. |
78 | */ |
79 | QOpcUaX509ExtensionExtendedKeyUsage &QOpcUaX509ExtensionExtendedKeyUsage::operator=(const QOpcUaX509ExtensionExtendedKeyUsage &rhs) |
80 | { |
81 | if (this != &rhs) |
82 | data.operator=(o: rhs.data); |
83 | return *this; |
84 | } |
85 | |
86 | /*! |
87 | Sets the key usage flag in \a keyUsage to \a enable. |
88 | */ |
89 | void QOpcUaX509ExtensionExtendedKeyUsage::setKeyUsage(KeyUsage keyUsage, bool enable) |
90 | { |
91 | QOpcUaX509ExtensionExtendedKeyUsageData *d = static_cast<QOpcUaX509ExtensionExtendedKeyUsageData*>(data.data()); |
92 | |
93 | if (enable) |
94 | d->keyUsage.insert(value: keyUsage); |
95 | else |
96 | d->keyUsage.remove(value: keyUsage); |
97 | } |
98 | |
99 | /*! |
100 | Returns the key usage flag for \a keyUsage. |
101 | */ |
102 | bool QOpcUaX509ExtensionExtendedKeyUsage::keyUsage(QOpcUaX509ExtensionExtendedKeyUsage::KeyUsage keyUsage) const |
103 | { |
104 | const QOpcUaX509ExtensionExtendedKeyUsageData *d = static_cast<const QOpcUaX509ExtensionExtendedKeyUsageData*>(data.data()); |
105 | return d->keyUsage.contains(value: keyUsage); |
106 | } |
107 | |
108 | QT_END_NAMESPACE |
109 |