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