diff options
| author | Melvin Keskin <melvo@olomono.de> | 2022-01-27 16:50:20 +0000 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2022-04-07 19:33:45 +0200 |
| commit | e59434b9085d90628352897c3dfc287766996797 (patch) | |
| tree | 110a4df5802342995a4f188be4472c6a4f9cb559 | |
| parent | ec7a90955bc14905e966b3f08ad2de9f1fc87016 (diff) | |
| download | qxmpp-e59434b9085d90628352897c3dfc287766996797.tar.gz | |
OmemoDeviceBundle: Use methods for adding / removing public pre keys
| -rw-r--r-- | src/base/QXmppOmemoData.cpp | 30 | ||||
| -rw-r--r-- | src/base/QXmppOmemoDeviceBundle.h | 3 | ||||
| -rw-r--r-- | tests/qxmppomemodata/tst_qxmppomemodata.cpp | 8 |
3 files changed, 26 insertions, 15 deletions
diff --git a/src/base/QXmppOmemoData.cpp b/src/base/QXmppOmemoData.cpp index 1ab62b3e..7897731d 100644 --- a/src/base/QXmppOmemoData.cpp +++ b/src/base/QXmppOmemoData.cpp @@ -365,23 +365,27 @@ QHash<uint32_t, QByteArray> QXmppOmemoDeviceBundle::publicPreKeys() const } /// -/// Sets the public pre keys. +/// Adds a public pre key. /// -/// The key of a key-value pair represents the ID of the corresponding public -/// pre key. -/// The ID must be at least 1 and at most 2^32-1, otherwise the corresponding -/// key-value pair is ignored. -/// The value of a key-value pair represents the public pre key. +/// The ID must be at least 1 and at most 2^32-1. /// -/// \param keys public pre keys +/// \param id ID of the public pre key +/// \param key public pre key /// -void QXmppOmemoDeviceBundle::setPublicPreKeys(const QMap<uint32_t, QByteArray> &keys) +void QXmppOmemoDeviceBundle::addPublicPreKey(const uint32_t id, const QByteArray &key) { - for (auto it = keys.cbegin(); it != keys.cend(); it++) { - if (it.key() > 0) { - d->publicPreKeys.insert(it.key(), it.value()); - } - } + d->publicPreKeys.insert(id, key); +} + +/// +/// Removes a public pre key. +/// +/// \param id ID of the public pre key +/// \param key public pre key +/// +void QXmppOmemoDeviceBundle::removePublicPreKey(const uint32_t id) +{ + d->publicPreKeys.remove(id); } /// \cond diff --git a/src/base/QXmppOmemoDeviceBundle.h b/src/base/QXmppOmemoDeviceBundle.h index f36776ca..97c6d2c8 100644 --- a/src/base/QXmppOmemoDeviceBundle.h +++ b/src/base/QXmppOmemoDeviceBundle.h @@ -36,7 +36,8 @@ public: void setSignedPublicPreKeySignature(const QByteArray &signature); QHash<uint32_t, QByteArray> publicPreKeys() const; - void setPublicPreKeys(const QMap<uint32_t, QByteArray> &keys); + void addPublicPreKey(uint32_t id, const QByteArray &key); + void removePublicPreKey(uint32_t id); /// \cond void parse(const QDomElement &element); diff --git a/tests/qxmppomemodata/tst_qxmppomemodata.cpp b/tests/qxmppomemodata/tst_qxmppomemodata.cpp index 7f288441..9f7fb517 100644 --- a/tests/qxmppomemodata/tst_qxmppomemodata.cpp +++ b/tests/qxmppomemodata/tst_qxmppomemodata.cpp @@ -268,13 +268,19 @@ void tst_QXmppOmemoData::testOmemoDeviceBundle() deviceBundle2.setSignedPublicPreKeyId(1); deviceBundle2.setSignedPublicPreKey(QByteArray::fromBase64(QByteArrayLiteral("Oy5TSG9vVVV4Wz9wUkUvI1lUXiVLIU5bbGIsUV0wRngK"))); deviceBundle2.setSignedPublicPreKeySignature(QByteArray::fromBase64(QByteArrayLiteral("PTEoSk91VnRZSXBzcFlPXy4jZ3NKcGVZZ2d3YVJbVj8K"))); - deviceBundle2.setPublicPreKeys(expectedPublicPreKeys); + deviceBundle2.addPublicPreKey(1, expectedPublicPreKeys.value(1)); + deviceBundle2.addPublicPreKey(2, expectedPublicPreKeys.value(2)); QCOMPARE(deviceBundle2.publicIdentityKey().toBase64(), QByteArrayLiteral("a012U0R9WixWKUYhYipucnZOWG06akFOR3Q1NGNOOmUK")); QCOMPARE(deviceBundle2.signedPublicPreKeyId(), uint32_t(1)); QCOMPARE(deviceBundle2.signedPublicPreKey().toBase64(), QByteArrayLiteral("Oy5TSG9vVVV4Wz9wUkUvI1lUXiVLIU5bbGIsUV0wRngK")); QCOMPARE(deviceBundle2.signedPublicPreKeySignature().toBase64(), QByteArrayLiteral("PTEoSk91VnRZSXBzcFlPXy4jZ3NKcGVZZ2d3YVJbVj8K")); QCOMPARE(deviceBundle2.publicPreKeys(), expectedPublicPreKeys); serializePacket(deviceBundle2, xmls); + + deviceBundle2.removePublicPreKey(2); + expectedPublicPreKeys.remove(2); + QCOMPARE(deviceBundle2.publicPreKeys(), expectedPublicPreKeys); + serializePacket(deviceBundle2, xmlWithSinglePreKey); } void tst_QXmppOmemoData::testIsOmemoEnvelope_data() |
