| 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 | |
| 6 | QT_BEGIN_NAMESPACE |
| 7 | |
| 8 | void QDtlsBasePrivate::setDtlsError(QDtlsError code, const QString &description) |
| 9 | { |
| 10 | errorCode = code; |
| 11 | errorDescription = description; |
| 12 | } |
| 13 | |
| 14 | QDtlsError QDtlsBasePrivate::error() const |
| 15 | { |
| 16 | return errorCode; |
| 17 | } |
| 18 | |
| 19 | QString QDtlsBasePrivate::errorString() const |
| 20 | { |
| 21 | return errorDescription; |
| 22 | } |
| 23 | |
| 24 | void QDtlsBasePrivate::clearDtlsError() |
| 25 | { |
| 26 | errorCode = QDtlsError::NoError; |
| 27 | errorDescription.clear(); |
| 28 | } |
| 29 | |
| 30 | QSslConfiguration QDtlsBasePrivate::configuration() const |
| 31 | { |
| 32 | return dtlsConfiguration; |
| 33 | } |
| 34 | |
| 35 | void QDtlsBasePrivate::setConfiguration(const QSslConfiguration &configuration) |
| 36 | { |
| 37 | dtlsConfiguration = configuration; |
| 38 | clearDtlsError(); |
| 39 | } |
| 40 | |
| 41 | bool QDtlsBasePrivate::setCookieGeneratorParameters(const GenParams ¶ms) |
| 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 | |
| 57 | QDtlsClientVerifier::GeneratorParameters |
| 58 | QDtlsBasePrivate::cookieGeneratorParameters() const |
| 59 | { |
| 60 | return {hashAlgorithm, secret}; |
| 61 | } |
| 62 | |
| 63 | bool QDtlsBasePrivate::isDtlsProtocol(QSsl::SslProtocol protocol) |
| 64 | { |
| 65 | switch (protocol) { |
| 66 | QT_WARNING_PUSH |
| 67 | QT_WARNING_DISABLE_DEPRECATED |
| 68 | case QSsl::DtlsV1_0: |
| 69 | case QSsl::DtlsV1_0OrLater: |
| 70 | QT_WARNING_POP |
| 71 | case QSsl::DtlsV1_2: |
| 72 | case QSsl::DtlsV1_2OrLater: |
| 73 | return true; |
| 74 | default: |
| 75 | return false; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | QT_END_NAMESPACE |
| 80 |
