mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-07 18:43:26 -08:00
[Client] DeckSyncProfile + sidecar + DeckDiff with tests
This commit is contained in:
parent
d8581d5abf
commit
248f5f165c
12 changed files with 740 additions and 0 deletions
31
cockatrice/src/interface/deck_sync/deck_sync_profile.cpp
Normal file
31
cockatrice/src/interface/deck_sync/deck_sync_profile.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#include "deck_sync_profile.h"
|
||||
|
||||
#include <QCryptographicHash>
|
||||
|
||||
DeckSyncProfile::DeckSyncProfile(const QString &_host, int _port, const QString &_username)
|
||||
: host(_host), port(_port), username(_username)
|
||||
{
|
||||
}
|
||||
|
||||
bool DeckSyncProfile::isValid() const
|
||||
{
|
||||
return !host.isEmpty() && port > 0 && !username.isEmpty();
|
||||
}
|
||||
|
||||
QString DeckSyncProfile::key() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
return {};
|
||||
}
|
||||
// NUL separators keep the triple injective: neither IPv6 hosts nor
|
||||
// usernames containing ':' can collide two profiles into one file.
|
||||
// Lowercasing is safe on both parts: DNS names are case-insensitive, and
|
||||
// Servatrice usernames are unique under a case-insensitive collation
|
||||
// (cockatrice_users uses utf8mb4_unicode_ci), so both spellings are one account.
|
||||
QByteArray blob = host.trimmed().toLower().toUtf8();
|
||||
blob.append('\0');
|
||||
blob.append(QByteArray::number(port));
|
||||
blob.append('\0');
|
||||
blob.append(username.trimmed().toLower().toUtf8());
|
||||
return QCryptographicHash::hash(blob, QCryptographicHash::Sha1).toHex();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue