mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-16 01:47:17 -05:00
Expose libresapi for GXS contacts import/export
To import contact /identity/import_key {"radix":"AgIRBAAABd..."} To export contact /identity/export_key {"gxs_id":"ffffffffffffffffffffffffffffffff"} In both cases if everithing went fine the answer is something like {"data":{"radix":"AgIRBAAABd...", "gxs_id":"fff..."}, "returncode":"ok"} Some retrocompatible adaptations were necessary to libretroshare RsGenExchange::deserializeGroupData p3IdService::deserialiseIdentityFromMemory Now accept an extra optional pointer parameter to return the id of the key so we can return it back from libresapi too and can be used to request more information about the key to the API.
This commit is contained in:
parent
17edf3c8de
commit
5ee517b64f
@ -1,3 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* libresapi
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 electron128 <electron128@yahoo.com>
|
||||||
|
* Copyright (C) 2017 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "IdentityHandler.h"
|
#include "IdentityHandler.h"
|
||||||
|
|
||||||
#include <retroshare/rsidentity.h>
|
#include <retroshare/rsidentity.h>
|
||||||
@ -97,19 +117,25 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
IdentityHandler::IdentityHandler(StateTokenServer *sts, RsNotify *notify, RsIdentity *identity):
|
IdentityHandler::IdentityHandler(StateTokenServer *sts, RsNotify *notify,
|
||||||
|
RsIdentity *identity) :
|
||||||
mStateTokenServer(sts), mNotify(notify), mRsIdentity(identity),
|
mStateTokenServer(sts), mNotify(notify), mRsIdentity(identity),
|
||||||
mMtx("IdentityHandler Mtx"), mStateToken(sts->getNewToken())
|
mMtx("IdentityHandler Mtx"), mStateToken(sts->getNewToken())
|
||||||
{
|
{
|
||||||
mNotify->registerNotifyClient(this);
|
mNotify->registerNotifyClient(this);
|
||||||
|
|
||||||
addResourceHandler("*", this, &IdentityHandler::handleWildcard);
|
addResourceHandler("*", this, &IdentityHandler::handleWildcard);
|
||||||
addResourceHandler("own", this, &IdentityHandler::handleOwn);
|
addResourceHandler("own", this, &IdentityHandler::handleOwn);
|
||||||
|
|
||||||
addResourceHandler("own_ids", this, &IdentityHandler::handleOwnIdsRequest);
|
addResourceHandler("own_ids", this, &IdentityHandler::handleOwnIdsRequest);
|
||||||
addResourceHandler("notown_ids", this, &IdentityHandler::handleNotOwnIdsRequest);
|
addResourceHandler("notown_ids", this,
|
||||||
|
&IdentityHandler::handleNotOwnIdsRequest);
|
||||||
|
|
||||||
addResourceHandler("create_identity", this, &IdentityHandler::handleCreateIdentity);
|
addResourceHandler("create_identity", this,
|
||||||
|
&IdentityHandler::handleCreateIdentity);
|
||||||
|
|
||||||
|
addResourceHandler("export_key", this, &IdentityHandler::handleExportKey);
|
||||||
|
addResourceHandler("import_key", this, &IdentityHandler::handleImportKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentityHandler::~IdentityHandler()
|
IdentityHandler::~IdentityHandler()
|
||||||
@ -119,12 +145,10 @@ IdentityHandler::~IdentityHandler()
|
|||||||
|
|
||||||
void IdentityHandler::notifyGxsChange(const RsGxsChanges &changes)
|
void IdentityHandler::notifyGxsChange(const RsGxsChanges &changes)
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mMtx); // ********** LOCKED **********
|
RS_STACK_MUTEX(mMtx);
|
||||||
// if changes come from identity service, invalidate own state token
|
// if changes come from identity service, invalidate own state token
|
||||||
if(changes.mService == mRsIdentity->getTokenService())
|
if(changes.mService == mRsIdentity->getTokenService())
|
||||||
{
|
mStateTokenServer->replaceToken(mStateToken);
|
||||||
mStateTokenServer->replaceToken(mStateToken);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IdentityHandler::handleWildcard(Request & /*req*/, Response &resp)
|
void IdentityHandler::handleWildcard(Request & /*req*/, Response &resp)
|
||||||
@ -138,30 +162,31 @@ void IdentityHandler::handleWildcard(Request & /*req*/, Response &resp)
|
|||||||
RsTokReqOptions opts;
|
RsTokReqOptions opts;
|
||||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||||
uint32_t token;
|
uint32_t token;
|
||||||
mRsIdentity->getTokenService()->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts);
|
mRsIdentity->getTokenService()->requestGroupInfo(
|
||||||
|
token, RS_TOKREQ_ANSTYPE_DATA, opts);
|
||||||
|
|
||||||
time_t start = time(NULL);
|
time_t timeout = time(NULL)+10;
|
||||||
while((mRsIdentity->getTokenService()->requestStatus(token) != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
uint8_t rStatus = mRsIdentity->getTokenService()->requestStatus(token);
|
||||||
&&(mRsIdentity->getTokenService()->requestStatus(token) != RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
|
while( rStatus != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE &&
|
||||||
&&((time(NULL) < (start+10)))
|
rStatus != RsTokenService::GXS_REQUEST_V2_STATUS_FAILED &&
|
||||||
)
|
time(NULL) < timeout )
|
||||||
{
|
{
|
||||||
#ifdef WINDOWS_SYS
|
|
||||||
Sleep(50);
|
|
||||||
#else
|
|
||||||
usleep(50*1000);
|
usleep(50*1000);
|
||||||
#endif
|
rStatus = mRsIdentity->getTokenService()->requestStatus(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mRsIdentity->getTokenService()->requestStatus(token) == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
if(rStatus == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
||||||
{
|
{
|
||||||
std::vector<RsGxsIdGroup> grps;
|
std::vector<RsGxsIdGroup> grps;
|
||||||
ok &= mRsIdentity->getGroupData(token, grps);
|
ok &= mRsIdentity->getGroupData(token, grps);
|
||||||
for(std::vector<RsGxsIdGroup>::iterator vit = grps.begin(); vit != grps.end(); vit++)
|
for( std::vector<RsGxsIdGroup>::iterator vit = grps.begin();
|
||||||
|
vit != grps.end(); ++vit )
|
||||||
{
|
{
|
||||||
RsGxsIdGroup& grp = *vit;
|
RsGxsIdGroup& grp = *vit;
|
||||||
//electron: not very happy about this, i think the flags should stay hidden in rsidentities
|
/* electron: not very happy about this, i think the flags should
|
||||||
bool own = (grp.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN);
|
* stay hidden in rsidentities */
|
||||||
|
bool own = (grp.mMeta.mSubscribeFlags &
|
||||||
|
GXS_SERV::GROUP_SUBSCRIBE_ADMIN);
|
||||||
bool pgp_linked = (grp.mMeta.mGroupFlags &
|
bool pgp_linked = (grp.mMeta.mGroupFlags &
|
||||||
RSGXSID_GROUPFLAG_REALID_kept_for_compatibility);
|
RSGXSID_GROUPFLAG_REALID_kept_for_compatibility);
|
||||||
resp.mDataStream.getStreamToMember()
|
resp.mDataStream.getStreamToMember()
|
||||||
@ -182,7 +207,6 @@ void IdentityHandler::handleWildcard(Request & /*req*/, Response &resp)
|
|||||||
else resp.setFail();
|
else resp.setFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void IdentityHandler::handleNotOwnIdsRequest(Request & /*req*/, Response &resp)
|
void IdentityHandler::handleNotOwnIdsRequest(Request & /*req*/, Response &resp)
|
||||||
{
|
{
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
@ -194,38 +218,38 @@ void IdentityHandler::handleNotOwnIdsRequest(Request & /*req*/, Response &resp)
|
|||||||
RsTokReqOptions opts;
|
RsTokReqOptions opts;
|
||||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||||
uint32_t token;
|
uint32_t token;
|
||||||
mRsIdentity->getTokenService()->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts);
|
mRsIdentity->getTokenService()->requestGroupInfo(
|
||||||
|
token, RS_TOKREQ_ANSTYPE_DATA, opts);
|
||||||
|
|
||||||
time_t start = time(NULL);
|
time_t timeout = time(NULL)+10;
|
||||||
while((mRsIdentity->getTokenService()->requestStatus(token) != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
uint8_t rStatus = mRsIdentity->getTokenService()->requestStatus(token);
|
||||||
&&(mRsIdentity->getTokenService()->requestStatus(token) != RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
|
while( rStatus != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE &&
|
||||||
&&((time(NULL) < (start+10)))
|
rStatus != RsTokenService::GXS_REQUEST_V2_STATUS_FAILED &&
|
||||||
)
|
time(NULL) < timeout )
|
||||||
{
|
{
|
||||||
#ifdef WINDOWS_SYS
|
usleep(50*1000);
|
||||||
Sleep(500);
|
rStatus = mRsIdentity->getTokenService()->requestStatus(token);
|
||||||
#else
|
|
||||||
usleep(500*1000);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mRsIdentity->getTokenService()->requestStatus(token) == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
if(rStatus == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
||||||
{
|
{
|
||||||
std::vector<RsGxsIdGroup> grps;
|
std::vector<RsGxsIdGroup> grps;
|
||||||
ok &= mRsIdentity->getGroupData(token, grps);
|
ok &= mRsIdentity->getGroupData(token, grps);
|
||||||
for(std::vector<RsGxsIdGroup>::iterator vit = grps.begin(); vit != grps.end(); vit++)
|
for(std::vector<RsGxsIdGroup>::iterator vit = grps.begin();
|
||||||
|
vit != grps.end(); vit++)
|
||||||
{
|
{
|
||||||
RsGxsIdGroup& grp = *vit;
|
RsGxsIdGroup& grp = *vit;
|
||||||
//electron: not very happy about this, i think the flags should stay hidden in rsidentities
|
if(!(grp.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN))
|
||||||
if(!(grp.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN) && grp.mIsAContact)
|
|
||||||
{
|
{
|
||||||
bool pgp_linked = (grp.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID_kept_for_compatibility ) ;
|
bool pgp_linked = (
|
||||||
|
grp.mMeta.mGroupFlags &
|
||||||
|
RSGXSID_GROUPFLAG_REALID_kept_for_compatibility );
|
||||||
resp.mDataStream.getStreamToMember()
|
resp.mDataStream.getStreamToMember()
|
||||||
<< makeKeyValueReference("id", grp.mMeta.mGroupId) /// @deprecated using "id" as key can cause problems in some JS based languages like Qml @see gxs_id instead
|
|
||||||
<< makeKeyValueReference("gxs_id", grp.mMeta.mGroupId)
|
<< makeKeyValueReference("gxs_id", grp.mMeta.mGroupId)
|
||||||
<< makeKeyValueReference("pgp_id",grp.mPgpId )
|
<< makeKeyValueReference("pgp_id",grp.mPgpId )
|
||||||
<< makeKeyValueReference("name", grp.mMeta.mGroupName)
|
<< makeKeyValueReference("name", grp.mMeta.mGroupName)
|
||||||
<< makeKeyValueReference("pgp_linked", pgp_linked);
|
<< makeKeyValueReference("pgp_linked", pgp_linked)
|
||||||
|
<< makeKeyValueReference("is_contact", grp.mIsAContact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -308,4 +332,47 @@ ResponseTask* IdentityHandler::handleCreateIdentity(Request & /* req */, Respons
|
|||||||
return new CreateIdentityTask(mRsIdentity);
|
return new CreateIdentityTask(mRsIdentity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IdentityHandler::handleExportKey(Request& req, Response& resp)
|
||||||
|
{
|
||||||
|
RsGxsId gxs_id;
|
||||||
|
req.mStream << makeKeyValueReference("gxs_id", gxs_id);
|
||||||
|
|
||||||
|
std::string radix;
|
||||||
|
time_t timeout = time(NULL)+2;
|
||||||
|
bool found = mRsIdentity->serialiseIdentityToMemory(gxs_id, radix);
|
||||||
|
while(!found && time(nullptr) < timeout)
|
||||||
|
{
|
||||||
|
usleep(5000);
|
||||||
|
found = mRsIdentity->serialiseIdentityToMemory(gxs_id, radix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(found)
|
||||||
|
{
|
||||||
|
resp.mDataStream << makeKeyValueReference("gxs_id", gxs_id)
|
||||||
|
<< makeKeyValueReference("radix", radix);
|
||||||
|
|
||||||
|
resp.setOk();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.setFail();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IdentityHandler::handleImportKey(Request& req, Response& resp)
|
||||||
|
{
|
||||||
|
std::string radix;
|
||||||
|
req.mStream << makeKeyValueReference("radix", radix);
|
||||||
|
|
||||||
|
RsGxsId gxs_id;
|
||||||
|
if(mRsIdentity->deserialiseIdentityFromMemory(radix, &gxs_id))
|
||||||
|
{
|
||||||
|
resp.mDataStream << makeKeyValueReference("gxs_id", gxs_id)
|
||||||
|
<< makeKeyValueReference("radix", radix);
|
||||||
|
resp.setOk();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.setFail();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace resource_api
|
} // namespace resource_api
|
||||||
|
@ -1,4 +1,23 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
/*
|
||||||
|
* libresapi
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 electron128 <electron128@yahoo.com>
|
||||||
|
* Copyright (C) 2017 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <retroshare/rsnotify.h>
|
#include <retroshare/rsnotify.h>
|
||||||
#include <util/rsthreads.h>
|
#include <util/rsthreads.h>
|
||||||
@ -22,10 +41,15 @@ public:
|
|||||||
virtual void notifyGxsChange(const RsGxsChanges &changes);
|
virtual void notifyGxsChange(const RsGxsChanges &changes);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleWildcard(Request& req, Response& resp);
|
void handleWildcard(Request& req, Response& resp);
|
||||||
void handleNotOwnIdsRequest(Request& req, Response& resp);
|
void handleNotOwnIdsRequest(Request& req, Response& resp);
|
||||||
void handleOwnIdsRequest(Request& req, Response& resp);
|
void handleOwnIdsRequest(Request& req, Response& resp);
|
||||||
|
|
||||||
|
void handlePubKey(Request& req, Response& resp);
|
||||||
|
|
||||||
|
void handleExportKey(Request& req, Response& resp);
|
||||||
|
void handleImportKey(Request& req, Response& resp);
|
||||||
|
|
||||||
ResponseTask *handleOwn(Request& req, Response& resp);
|
ResponseTask *handleOwn(Request& req, Response& resp);
|
||||||
ResponseTask *handleCreateIdentity(Request& req, Response& resp);
|
ResponseTask *handleCreateIdentity(Request& req, Response& resp);
|
||||||
|
|
||||||
|
@ -1270,7 +1270,9 @@ bool RsGenExchange::getMsgRelatedMeta(const uint32_t &token, GxsMsgRelatedMetaMa
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsGenExchange::getSerializedGroupData(const uint32_t &token, RsGxsGroupId& id,unsigned char *& data,uint32_t& size)
|
bool RsGenExchange::getSerializedGroupData(uint32_t token, RsGxsGroupId& id,
|
||||||
|
unsigned char *& data,
|
||||||
|
uint32_t& size)
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mGenMtx) ;
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
@ -1303,24 +1305,30 @@ bool RsGenExchange::getSerializedGroupData(const uint32_t &token, RsGxsGroupId&
|
|||||||
return nxs_grp->serialise(data,size) ;
|
return nxs_grp->serialise(data,size) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsGenExchange::deserializeGroupData(unsigned char *data,uint32_t size)
|
bool RsGenExchange::deserializeGroupData(unsigned char *data, uint32_t size,
|
||||||
|
RsGxsGroupId* gId /*= nullptr*/)
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mGenMtx) ;
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
RsItem *item = RsNxsSerialiser(mServType).deserialise(data, &size);
|
RsItem *item = RsNxsSerialiser(mServType).deserialise(data, &size);
|
||||||
|
|
||||||
RsNxsGrp *nxs_grp = dynamic_cast<RsNxsGrp*>(item) ;
|
RsNxsGrp *nxs_grp = dynamic_cast<RsNxsGrp*>(item);
|
||||||
|
|
||||||
if(item == NULL)
|
if(item == NULL)
|
||||||
{
|
{
|
||||||
std::cerr << "(EE) RsGenExchange::deserializeGroupData(): cannot deserialise this data. Something's wrong." << std::endl;
|
std::cerr << "(EE) RsGenExchange::deserializeGroupData(): cannot "
|
||||||
delete item ;
|
<< "deserialise this data. Something's wrong." << std::endl;
|
||||||
return false ;
|
delete item;
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
mReceivedGrps.push_back( GxsPendingItem<RsNxsGrp*, RsGxsGroupId>(nxs_grp, nxs_grp->grpId,time(NULL)) );
|
mReceivedGrps.push_back(
|
||||||
|
GxsPendingItem<RsNxsGrp*, RsGxsGroupId>(
|
||||||
|
nxs_grp, nxs_grp->grpId,time(NULL)) );
|
||||||
|
|
||||||
return true ;
|
if(gId) *gId = nxs_grp->grpId;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem *>& grpItem)
|
bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem *>& grpItem)
|
||||||
|
@ -299,8 +299,10 @@ protected:
|
|||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool getSerializedGroupData(const uint32_t &token, RsGxsGroupId &id, unsigned char *& data, uint32_t& size);
|
bool getSerializedGroupData(uint32_t token, RsGxsGroupId &id,
|
||||||
bool deserializeGroupData(unsigned char *data, uint32_t size);
|
unsigned char *& data, uint32_t& size);
|
||||||
|
bool deserializeGroupData(unsigned char *data, uint32_t size,
|
||||||
|
RsGxsGroupId* gId = nullptr);
|
||||||
|
|
||||||
template<class GrpType>
|
template<class GrpType>
|
||||||
bool getGroupDataT(const uint32_t &token, std::vector<GrpType*>& grpItem)
|
bool getGroupDataT(const uint32_t &token, std::vector<GrpType*>& grpItem)
|
||||||
|
@ -305,8 +305,10 @@ public:
|
|||||||
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) = 0 ;
|
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) = 0 ;
|
||||||
virtual bool isARegularContact(const RsGxsId& id) = 0 ;
|
virtual bool isARegularContact(const RsGxsId& id) = 0 ;
|
||||||
|
|
||||||
virtual bool serialiseIdentityToMemory(const RsGxsId& id,std::string& radix_string)=0;
|
virtual bool serialiseIdentityToMemory( const RsGxsId& id,
|
||||||
virtual bool deserialiseIdentityFromMemory(const std::string& radix_string)=0;
|
std::string& radix_string ) = 0;
|
||||||
|
virtual bool deserialiseIdentityFromMemory( const std::string& radix_string,
|
||||||
|
RsGxsId* id = nullptr ) = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief overallReputationLevel
|
* \brief overallReputationLevel
|
||||||
|
@ -698,9 +698,10 @@ bool p3IdService::getOwnIds(std::list<RsGxsId> &ownIds)
|
|||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3IdService::serialiseIdentityToMemory(const RsGxsId& id,std::string& radix_string)
|
bool p3IdService::serialiseIdentityToMemory( const RsGxsId& id,
|
||||||
|
std::string& radix_string )
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
|
RS_STACK_MUTEX(mIdMtx);
|
||||||
|
|
||||||
// look into cache. If available, return the data. If not, request it.
|
// look into cache. If available, return the data. If not, request it.
|
||||||
|
|
||||||
@ -758,23 +759,27 @@ void p3IdService::handle_get_serialized_grp(uint32_t token)
|
|||||||
mSerialisedIdentities[RsGxsId(id)] = s ;
|
mSerialisedIdentities[RsGxsId(id)] = s ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3IdService::deserialiseIdentityFromMemory(const std::string& radix_string)
|
bool p3IdService::deserialiseIdentityFromMemory(const std::string& radix_string,
|
||||||
|
RsGxsId* id /* = nullptr */)
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> mem = Radix64::decode(radix_string) ;
|
std::vector<uint8_t> mem = Radix64::decode(radix_string);
|
||||||
|
|
||||||
if(mem.empty())
|
if(mem.empty())
|
||||||
{
|
{
|
||||||
std::cerr << "Cannot decode radix string \"" << radix_string << "\"" << std::endl;
|
std::cerr << __PRETTY_FUNCTION__ << "Cannot decode radix string \""
|
||||||
return false ;
|
<< radix_string << "\"" << std::endl;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!RsGenExchange::deserializeGroupData(mem.data(),mem.size()))
|
if( !RsGenExchange::deserializeGroupData(
|
||||||
{
|
mem.data(), mem.size(), reinterpret_cast<RsGxsGroupId*>(id)) )
|
||||||
std::cerr << "Cannot load identity from radix string \"" << radix_string << "\"" << std::endl;
|
{
|
||||||
return false ;
|
std::cerr << __PRETTY_FUNCTION__ << "Cannot load identity from radix "
|
||||||
}
|
<< "string \"" << radix_string << "\"" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true ;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters ¶ms)
|
bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters ¶ms)
|
||||||
|
@ -350,8 +350,10 @@ public:
|
|||||||
const RsIdentityUsage &use_info );
|
const RsIdentityUsage &use_info );
|
||||||
virtual bool requestPrivateKey(const RsGxsId &id);
|
virtual bool requestPrivateKey(const RsGxsId &id);
|
||||||
|
|
||||||
virtual bool serialiseIdentityToMemory(const RsGxsId& id,std::string& radix_string);
|
virtual bool serialiseIdentityToMemory(const RsGxsId& id,
|
||||||
virtual bool deserialiseIdentityFromMemory(const std::string& radix_string);
|
std::string& radix_string);
|
||||||
|
virtual bool deserialiseIdentityFromMemory(const std::string& radix_string,
|
||||||
|
RsGxsId* id = nullptr);
|
||||||
|
|
||||||
/**************** RsGixsReputation Implementation ****************/
|
/**************** RsGixsReputation Implementation ****************/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user