1
This commit is contained in:
1 parent
26f4da1b7c
commit
712d1b53df
29 files changed
+1029
-1138
No files matched your search
@@ -3,7 +3,8 @@
|
||||
#include <QByteArray>
|
||||
|
||||
QString encodeInviteLink(uint64_t channelId, const QByteArray& pubkey,
|
||||
const QList<NodeAddr>& addrs) {
|
||||
const QList<NodeAddr>& addrs,
|
||||
const QString& password) {
|
||||
if (pubkey.size() != 32) {
|
||||
GUI_ERROR("encodeInviteLink: pubkey must be 32 bytes (got %d)", pubkey.size());
|
||||
return {};
|
||||
@@ -14,9 +15,16 @@ QString encodeInviteLink(uint64_t channelId, const QByteArray& pubkey,
|
||||
}
|
||||
|
||||
QByteArray blob;
|
||||
blob.reserve(1 + 8 + addrs.size() * (1 + 32 + 20));
|
||||
int hasPass = !password.isEmpty() ? 1 : 0;
|
||||
blob.reserve(1 + (hasPass ? 1 + password.size() : 0) + 8 + addrs.size() * (1 + 32 + 20));
|
||||
|
||||
blob.append(static_cast<char>(INVITE_LINK_VERSION));
|
||||
blob.append(static_cast<char>(hasPass ? 0x02 : INVITE_LINK_VERSION));
|
||||
|
||||
if (hasPass) {
|
||||
QByteArray passBytes = password.toUtf8();
|
||||
blob.append(static_cast<char>(passBytes.size()));
|
||||
blob.append(passBytes);
|
||||
}
|
||||
|
||||
/* channel_id: uint64 big-endian */
|
||||
for (int i = 7; i >= 0; i--)
|
||||
@@ -73,12 +81,30 @@ InviteData decodeInviteLink(const QString& link) {
|
||||
}
|
||||
int off = 0;
|
||||
|
||||
if (data[off++] != INVITE_LINK_VERSION) {
|
||||
d.error = QStringLiteral("unsupported version 0x%1").arg(data[off - 1], 2, 16, QLatin1Char('0'));
|
||||
GUI_ERROR("decodeInviteLink: unsupported version %d", data[off - 1]);
|
||||
uint8_t ver = data[off++];
|
||||
if (ver != INVITE_LINK_VERSION && ver != 0x02) {
|
||||
d.error = QStringLiteral("unsupported version 0x%1").arg(ver, 2, 16, QLatin1Char('0'));
|
||||
GUI_ERROR("decodeInviteLink: unsupported version %d", ver);
|
||||
return d;
|
||||
}
|
||||
|
||||
/* v2: password field before channel_id */
|
||||
if (ver == 0x02) {
|
||||
if (off >= len) {
|
||||
d.error = QStringLiteral("truncated at pass_len");
|
||||
return d;
|
||||
}
|
||||
uint8_t plen = data[off++];
|
||||
if (plen > 0) {
|
||||
if (off + plen > len) {
|
||||
d.error = QStringLiteral("truncated at password");
|
||||
return d;
|
||||
}
|
||||
d.password = QString::fromUtf8(reinterpret_cast<const char*>(data + off), plen);
|
||||
off += plen;
|
||||
}
|
||||
}
|
||||
|
||||
/* channel_id: uint64 big-endian */
|
||||
if (off + 8 > len) {
|
||||
d.error = QStringLiteral("truncated at channel_id");
|
||||
|
||||
Reference in new issue
Block a user