diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-05-26 08:51:22 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-05-29 08:17:56 +0200 |
commit | 0b5e72a2c6502f22a752b72b4df5fa25746fdd25 (patch) | |
tree | dba7f9d9030f884f37253c3a1d370784707726f1 /autotests | |
parent | 729ba7da174eacc88bf9bd4e2e80eeab3fc92716 (diff) | |
download | libquotient-0b5e72a2c6502f22a752b72b4df5fa25746fdd25.tar.gz libquotient-0b5e72a2c6502f22a752b72b4df5fa25746fdd25.zip |
Refactor EncryptedFile and EC::FileInfo::file
Besides having a misleading name (and it goes back to the spec),
EncryptedFile under `file` key preempts the `url` (or `thumbnail_url`)
string value so only one of the two should exist. This is a case for
using std::variant<> - despite its clumsy syntax, it can actually
simplify and streamline code when all the necessary bits are in place
(such as conversion to JSON and getting the common piece - the URL -
out of it). This commit replaces `FileInfo::url` and `FileInfo::file`
with a common field `source` of type `FileSourceInfo` that is an alias
for a variant type covering both underlying types; and `url()` is
reintroduced as a function instead, to allow simplified access
to whichever URL is available inside the variant.
Oh, and EncryptedFile is EncryptedFileMetadata now, to clarify that it
does not represent the file payload itself but rather the data necessary
to obtain that payload.
Diffstat (limited to 'autotests')
-rw-r--r-- | autotests/testfilecrypto.cpp | 6 | ||||
-rw-r--r-- | autotests/testolmaccount.cpp | 5 |
2 files changed, 6 insertions, 5 deletions
diff --git a/autotests/testfilecrypto.cpp b/autotests/testfilecrypto.cpp index f9212376..b86114a4 100644 --- a/autotests/testfilecrypto.cpp +++ b/autotests/testfilecrypto.cpp @@ -3,14 +3,16 @@ // SPDX-License-Identifier: LGPL-2.1-or-later #include "testfilecrypto.h" -#include "events/encryptedfile.h" + +#include "events/filesourceinfo.h" + #include <qtest.h> using namespace Quotient; void TestFileCrypto::encryptDecryptData() { QByteArray data = "ABCDEF"; - auto [file, cipherText] = EncryptedFile::encryptFile(data); + auto [file, cipherText] = EncryptedFileMetadata::encryptFile(data); auto decrypted = file.decryptFile(cipherText); // AES CTR produces ciphertext of the same size as the original QCOMPARE(cipherText.size(), data.size()); diff --git a/autotests/testolmaccount.cpp b/autotests/testolmaccount.cpp index e31ff6d3..b509d12f 100644 --- a/autotests/testolmaccount.cpp +++ b/autotests/testolmaccount.cpp @@ -10,7 +10,7 @@ #include <e2ee/qolmaccount.h> #include <e2ee/qolmutility.h> #include <events/encryptionevent.h> -#include <events/encryptedfile.h> +#include <events/filesourceinfo.h> #include <networkaccessmanager.h> #include <room.h> @@ -156,8 +156,7 @@ void TestOlmAccount::encryptedFile() "sha256": "fdSLu/YkRx3Wyh3KQabP3rd6+SFiKg5lsJZQHtkSAYA" }})"); - EncryptedFile file; - JsonObjectConverter<EncryptedFile>::fillFrom(doc.object(), file); + const auto file = fromJson<EncryptedFileMetadata>(doc); QCOMPARE(file.v, "v2"); QCOMPARE(file.iv, "w+sE15fzSc0AAAAAAAAAAA"); |