1// Copyright (C) 2021 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 "qdtls_base_p.h"
5
6QT_BEGIN_NAMESPACE
7
8void QDtlsBasePrivate::setDtlsError(QDtlsError code, const QString &description)
9{
10 errorCode = code;
11 errorDescription = description;
12}
13
14QDtlsError QDtlsBasePrivate::error() const
15{
16 return errorCode;
17}
18
19QString QDtlsBasePrivate::errorString() const
20{
21 return errorDescription;
22}
23
24void QDtlsBasePrivate::clearDtlsError()
25{
26 errorCode = QDtlsError::NoError;
27 errorDescription.clear();
28}
29
30QSslConfiguration QDtlsBasePrivate::configuration() const
31{
32 return dtlsConfiguration;
33}
34
35void QDtlsBasePrivate::setConfiguration(const QSslConfiguration &configuration)
36{
37 dtlsConfiguration = configuration;
38 clearDtlsError();
39}
40
41bool QDtlsBasePrivate::setCookieGeneratorParameters(const GenParams &params)
42{
43 if (!params.secret.size()) {
44 setDtlsError(code: QDtlsError::InvalidInputParameters,
45 description: QDtls::tr(s: "Invalid (empty) secret"));
46 return false;
47 }
48
49 clearDtlsError();
50
51 hashAlgorithm = params.hash;
52 secret = params.secret;
53
54 return true;
55}
56
57QDtlsClientVerifier::GeneratorParameters
58QDtlsBasePrivate::cookieGeneratorParameters() const
59{
60 return {hashAlgorithm, secret};
61}
62
63bool QDtlsBasePrivate::isDtlsProtocol(QSsl::SslProtocol protocol)
64{
65 switch (protocol) {
66QT_WARNING_PUSH
67QT_WARNING_DISABLE_DEPRECATED
68 case QSsl::DtlsV1_0:
69 case QSsl::DtlsV1_0OrLater:
70QT_WARNING_POP
71 case QSsl::DtlsV1_2:
72 case QSsl::DtlsV1_2OrLater:
73 return true;
74 default:
75 return false;
76 }
77}
78
79QT_END_NAMESPACE
80

source code of qtbase/src/plugins/tls/shared/qdtls_base.cpp