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 "qopcuax509extensionkeyusage.h" |
5 | #include "qopcuax509extension_p.h" |
6 | #include <QSet> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | /*! |
11 | \class QOpcUaX509ExtensionKeyUsage |
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 QOpcUaX509ExtensionKeyUsage::KeyUsage |
24 | |
25 | Enum with entry types for X509ExtensionKeyUsage. |
26 | |
27 | \value DigitalSignature |
28 | Permits digital signatures |
29 | \value NonRepudiation |
30 | Permits non repudiation |
31 | \value KeyEncipherment |
32 | Permits key encipherment |
33 | \value DataEncipherment |
34 | Permits data encipherment |
35 | \value KeyAgreement |
36 | Permits key agreement |
37 | \value CertificateSigning |
38 | Permits certificate signing |
39 | \value CrlSigning |
40 | Permits CRL signing |
41 | \value EnciptherOnly |
42 | Restricts to encipherment only |
43 | \value DecipherOnly |
44 | Restricts to decipher only |
45 | */ |
46 | |
47 | class QOpcUaX509ExtensionKeyUsageData : public QOpcUaX509ExtensionData |
48 | { |
49 | public: |
50 | ~QOpcUaX509ExtensionKeyUsageData() override = default; |
51 | QSet<QOpcUaX509ExtensionKeyUsage::KeyUsage> keyUsage; |
52 | }; |
53 | |
54 | /*! |
55 | Constructs a X509ExtensionKeyUsage. |
56 | */ |
57 | QOpcUaX509ExtensionKeyUsage::QOpcUaX509ExtensionKeyUsage() |
58 | : QOpcUaX509Extension(new QOpcUaX509ExtensionKeyUsageData) |
59 | { |
60 | } |
61 | |
62 | /*! |
63 | Constructs a X509ExtensionKeyUsage from \a rhs. |
64 | */ |
65 | QOpcUaX509ExtensionKeyUsage::QOpcUaX509ExtensionKeyUsage(const QOpcUaX509ExtensionKeyUsage &rhs) |
66 | : QOpcUaX509Extension(rhs.data) |
67 | { |
68 | } |
69 | |
70 | /*! |
71 | Returns \c true if this X509ExtensionKeyUsage has the same value as \a rhs. |
72 | */ |
73 | bool QOpcUaX509ExtensionKeyUsage::operator==(const QOpcUaX509ExtensionKeyUsage &rhs) const |
74 | { |
75 | return data->critical == rhs.data->critical; |
76 | } |
77 | |
78 | /*! |
79 | Destructs a X509ExtensionKeyUsage. |
80 | */ |
81 | QOpcUaX509ExtensionKeyUsage::~QOpcUaX509ExtensionKeyUsage() |
82 | { |
83 | } |
84 | |
85 | /*! |
86 | Sets the values from \a rhs in this X509ExtensionKeyUsage. |
87 | */ |
88 | QOpcUaX509ExtensionKeyUsage &QOpcUaX509ExtensionKeyUsage::operator=(const QOpcUaX509ExtensionKeyUsage &rhs) |
89 | { |
90 | if (this != &rhs) |
91 | data.operator=(o: rhs.data); |
92 | return *this; |
93 | } |
94 | |
95 | /*! |
96 | Sets the key usage flag in \a keyUsage to \a enable. |
97 | */ |
98 | void QOpcUaX509ExtensionKeyUsage::setKeyUsage(KeyUsage keyUsage, bool enable) |
99 | { |
100 | QOpcUaX509ExtensionKeyUsageData *d = static_cast<QOpcUaX509ExtensionKeyUsageData*>(data.data()); |
101 | |
102 | if (enable) |
103 | d->keyUsage.insert(value: keyUsage); |
104 | else |
105 | d->keyUsage.remove(value: keyUsage); |
106 | } |
107 | |
108 | /*! |
109 | Returns the key usage flag for \a keyUsage. |
110 | */ |
111 | bool QOpcUaX509ExtensionKeyUsage::keyUsage(QOpcUaX509ExtensionKeyUsage::KeyUsage keyUsage) const |
112 | { |
113 | const QOpcUaX509ExtensionKeyUsageData *d = static_cast<const QOpcUaX509ExtensionKeyUsageData*>(data.data()); |
114 | return d->keyUsage.contains(value: keyUsage); |
115 | } |
116 | |
117 | QT_END_NAMESPACE |
118 |