aboutsummaryrefslogtreecommitdiff
path: root/src/base/QXmppEncryptedFileSource.cpp
diff options
context:
space:
mode:
authorJonah BrĂ¼chert <jbb@kaidan.im>2022-09-24 17:58:44 +0200
committerGitHub <noreply@github.com>2022-09-24 17:58:44 +0200
commiteb63b18dcbb2ccdf811461a42f120e5d0ab82e88 (patch)
treec640d0a4e663912fbcb8b4bf1971874bd5f295b3 /src/base/QXmppEncryptedFileSource.cpp
parent9f474d28ffeb6e2a55fe1fb688463e1156c8fcb6 (diff)
EncryptedFileSource: Make public (#469)
The sources possibly need to be saved by clients.
Diffstat (limited to 'src/base/QXmppEncryptedFileSource.cpp')
-rw-r--r--src/base/QXmppEncryptedFileSource.cpp81
1 files changed, 59 insertions, 22 deletions
diff --git a/src/base/QXmppEncryptedFileSource.cpp b/src/base/QXmppEncryptedFileSource.cpp
index d2c2b592..37170492 100644
--- a/src/base/QXmppEncryptedFileSource.cpp
+++ b/src/base/QXmppEncryptedFileSource.cpp
@@ -3,8 +3,9 @@
//
// SPDX-License-Identifier: LGPL-2.1-or-later
+#include "QXmppEncryptedFileSource.h"
+
#include "QXmppConstants_p.h"
-#include "QXmppEncryptedFileSource_p.h"
#include "QXmppHttpFileSource.h"
#include <optional>
@@ -13,6 +14,19 @@
#include <QXmlStreamWriter>
/// \cond
+
+class QXmppEncryptedFileSourcePrivate : public QSharedData
+{
+public:
+ QXmppEncryptedFileSource::Cipher cipher = QXmppEncryptedFileSource::Aes128GcmNopadding;
+ QByteArray key;
+ QByteArray iv;
+ QVector<QXmppHash> hashes;
+ QVector<QXmppHttpFileSource> httpSources;
+};
+
+QXMPP_PRIVATE_DEFINE_RULE_OF_SIX(QXmppEncryptedFileSource)
+
static QString cipherToString(QXmppEncryptedFileSource::Cipher cipher)
{
switch (cipher) {
@@ -37,64 +51,87 @@ static std::optional<QXmppEncryptedFileSource::Cipher> cipherFromString(const QS
}
return {};
}
+/// \endcond
-QXmppEncryptedFileSource::QXmppEncryptedFileSource() = default;
+///
+/// \class QXmppEncryptedFileSource
+///
+/// \brief Represents an encrypted file source for file sharing.
+///
+/// \since QXmpp 1.5
+///
+QXmppEncryptedFileSource::QXmppEncryptedFileSource()
+ : d(new QXmppEncryptedFileSourcePrivate())
+{
+}
+
+/// Returns the cipher that was used to encrypt the data in this file source
QXmppEncryptedFileSource::Cipher QXmppEncryptedFileSource::cipher() const
{
- return m_cipher;
+ return d->cipher;
}
+/// Sets the cipher that was used to encrypt the data in this file source
void QXmppEncryptedFileSource::setCipher(Cipher newCipher)
{
- m_cipher = newCipher;
+ d->cipher = newCipher;
}
+/// Returns the key that can be used to decrypt the data in this file source
const QByteArray &QXmppEncryptedFileSource::key() const
{
- return m_key;
+ return d->key;
}
+/// Sets the key that was used to encrypt the data in this file source
void QXmppEncryptedFileSource::setKey(const QByteArray &newKey)
{
- m_key = newKey;
+ d->key = newKey;
}
+/// Returns the Initialization vector that can be used to decrypt the data in this file source
const QByteArray &QXmppEncryptedFileSource::iv() const
{
- return m_iv;
+ return d->iv;
}
+/// Sets the initialization vector that was used to encrypt the data in this file source
void QXmppEncryptedFileSource::setIv(const QByteArray &newIv)
{
- m_iv = newIv;
+ d->iv = newIv;
}
+/// Returns the hashes of the file contained in this file source
const QVector<QXmppHash> &QXmppEncryptedFileSource::hashes() const
{
- return m_hashes;
+ return d->hashes;
}
+/// Sets the hashes of the file contained in this file source
void QXmppEncryptedFileSource::setHashes(const QVector<QXmppHash> &newHashes)
{
- m_hashes = newHashes;
+ d->hashes = newHashes;
}
+/// Returns the http sources that can be used to retrieve the encrypted data
const QVector<QXmppHttpFileSource> &QXmppEncryptedFileSource::httpSources() const
{
- return m_httpSources;
+ return d->httpSources;
}
+/// Sets the http sources containing the encrypted data
void QXmppEncryptedFileSource::setHttpSources(const QVector<QXmppHttpFileSource> &newHttpSources)
{
- m_httpSources = newHttpSources;
+ d->httpSources = newHttpSources;
}
+/// \cond
bool QXmppEncryptedFileSource::parse(const QDomElement &el)
{
QString cipher = el.attribute(QStringLiteral("cipher"));
if (auto parsedCipher = cipherFromString(cipher)) {
- m_cipher = *parsedCipher;
+ d->cipher = *parsedCipher;
} else {
return false;
}
@@ -103,13 +140,13 @@ bool QXmppEncryptedFileSource::parse(const QDomElement &el)
if (keyEl.isNull()) {
return false;
}
- m_key = QByteArray::fromBase64(keyEl.text().toUtf8());
+ d->key = QByteArray::fromBase64(keyEl.text().toUtf8());
auto ivEl = el.firstChildElement(QStringLiteral("iv"));
if (ivEl.isNull()) {
return false;
}
- m_iv = QByteArray::fromBase64(ivEl.text().toUtf8());
+ d->iv = QByteArray::fromBase64(ivEl.text().toUtf8());
for (auto childEl = el.firstChildElement(QStringLiteral("hash"));
!childEl.isNull();
@@ -118,7 +155,7 @@ bool QXmppEncryptedFileSource::parse(const QDomElement &el)
if (!hash.parse(childEl)) {
return false;
}
- m_hashes.push_back(std::move(hash));
+ d->hashes.push_back(std::move(hash));
}
auto sourcesEl = el.firstChildElement(QStringLiteral("sources"));
@@ -130,7 +167,7 @@ bool QXmppEncryptedFileSource::parse(const QDomElement &el)
childEl = childEl.nextSiblingElement(QStringLiteral("url-data"))) {
QXmppHttpFileSource source;
source.parse(childEl);
- m_httpSources.push_back(std::move(source));
+ d->httpSources.push_back(std::move(source));
}
return true;
@@ -140,15 +177,15 @@ void QXmppEncryptedFileSource::toXml(QXmlStreamWriter *writer) const
{
writer->writeStartElement(QStringLiteral("encrypted"));
writer->writeDefaultNamespace(ns_esfs);
- writer->writeAttribute(QStringLiteral("cipher"), cipherToString(m_cipher));
- writer->writeTextElement(QStringLiteral("key"), m_key.toBase64());
- writer->writeTextElement(QStringLiteral("iv"), m_iv.toBase64());
- for (const auto &hash : m_hashes) {
+ writer->writeAttribute(QStringLiteral("cipher"), cipherToString(d->cipher));
+ writer->writeTextElement(QStringLiteral("key"), d->key.toBase64());
+ writer->writeTextElement(QStringLiteral("iv"), d->iv.toBase64());
+ for (const auto &hash : d->hashes) {
hash.toXml(writer);
}
writer->writeStartElement(QStringLiteral("sources"));
writer->writeDefaultNamespace(ns_sfs);
- for (const auto &source : m_httpSources) {
+ for (const auto &source : d->httpSources) {
source.toXml(writer);
}
writer->writeEndElement();