33#include " wsauthenticator_p.h"
44#include " wsremoteconnector_p.h"
55
6+ #include < QtCore/QJsonDocument>
7+
68using namespace QtDataSync ;
79
810WsAuthenticator::WsAuthenticator (WsRemoteConnector *connector, Defaults *defaults, QObject *parent) :
@@ -18,6 +20,34 @@ WsAuthenticator::WsAuthenticator(WsRemoteConnector *connector, Defaults *default
1820
1921WsAuthenticator::~WsAuthenticator () {}
2022
23+ void WsAuthenticator::exportUserData (QIODevice *device) const
24+ {
25+ QJsonObject data;
26+ data[QStringLiteral (" key" )] = QString::fromUtf8 (d->connector ->cryptor ()->key ().toBase64 ());
27+ data[QStringLiteral (" identity" )] = QString::fromUtf8 (userIdentity ());
28+
29+ device->write (QJsonDocument (data).toJson (QJsonDocument::Indented));
30+ }
31+
32+ GenericTask<void > WsAuthenticator::importUserData (QIODevice *device)
33+ {
34+ QJsonParseError error;
35+ auto data = QJsonDocument::fromJson (device->readAll (), &error);
36+ if (error.error != QJsonParseError::NoError) {
37+ QFutureInterface<QVariant> futureInterface;
38+ futureInterface.reportStarted ();
39+ futureInterface.reportException (InvalidDataException (error.errorString ()));
40+ futureInterface.reportFinished ();
41+ return futureInterface;
42+ }
43+
44+ auto obj = data.object ();
45+ auto key = QByteArray::fromBase64 (obj[QStringLiteral (" key" )].toString ().toUtf8 ());
46+ QMetaObject::invokeMethod (d->connector ->cryptor (), " setKey" , Qt::QueuedConnection,
47+ Q_ARG (QByteArray, key));
48+ return setUserIdentity (obj[QStringLiteral (" identity" )].toString ().toUtf8 ());
49+ }
50+
2151bool WsAuthenticator::isRemoteEnabled () const
2252{
2353 return d->settings ->value (WsRemoteConnector::keyRemoteEnabled, true ).toBool ();
0 commit comments