| 1 | // Copyright (C) 2023 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 <QtCore/qfile.h> |
| 6 | #include "qqmlsslkey_p.h" |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | QSslKey QQmlSslKey::getSslKey() const |
| 11 | { |
| 12 | if (m_keyFile.isEmpty()) { |
| 13 | qWarning() << "SslConfiguration::getSslKey: No key paths set"; |
| 14 | return QSslKey(); |
| 15 | } |
| 16 | |
| 17 | QFile file(m_keyFile); |
| 18 | if (!file.open(flags: QIODevice::ReadOnly)) { |
| 19 | qWarning() << "SslConfiguration::getSslKey: Couldn't open file:"<< m_keyFile; |
| 20 | return QSslKey(); |
| 21 | } |
| 22 | |
| 23 | return QSslKey(file.readAll(), |
| 24 | m_keyAlgorithm, |
| 25 | m_keyFormat, |
| 26 | m_keyType, |
| 27 | m_keyPassPhrase); |
| 28 | } |
| 29 | |
| 30 | void QQmlSslKey::setKeyFile(const QString &key) |
| 31 | { |
| 32 | if (m_keyFile == key) |
| 33 | return; |
| 34 | |
| 35 | m_keyFile = key; |
| 36 | } |
| 37 | |
| 38 | void QQmlSslKey::setKeyAlgorithm(QSsl::KeyAlgorithm value) |
| 39 | { |
| 40 | if (m_keyAlgorithm == value) |
| 41 | return; |
| 42 | |
| 43 | m_keyAlgorithm = value; |
| 44 | } |
| 45 | |
| 46 | void QQmlSslKey::setKeyFormat(QSsl::EncodingFormat value) |
| 47 | { |
| 48 | if (m_keyFormat == value) |
| 49 | return; |
| 50 | |
| 51 | m_keyFormat = value; |
| 52 | } |
| 53 | |
| 54 | void QQmlSslKey::setKeyPassPhrase(const QByteArray &value) |
| 55 | { |
| 56 | if (m_keyPassPhrase == value) |
| 57 | return; |
| 58 | |
| 59 | m_keyPassPhrase = value; |
| 60 | } |
| 61 | |
| 62 | void QQmlSslKey::setKeyType(QSsl::KeyType type) |
| 63 | { |
| 64 | if (m_keyType == type) |
| 65 | return; |
| 66 | m_keyType = type; |
| 67 | } |
| 68 | |
| 69 | QT_END_NAMESPACE |
| 70 |
