mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-23 13:15:51 -04:00
Implement rsIdentity link import/export
This commit is contained in:
parent
d9a8c5c09f
commit
c3fa2c6c1c
3 changed files with 163 additions and 48 deletions
|
@ -817,10 +817,6 @@ bool p3IdService::isKnownId(const RsGxsId& id)
|
|||
std::find(mOwnIds.begin(), mOwnIds.end(),id) != mOwnIds.end();
|
||||
}
|
||||
|
||||
bool p3IdService::identityToBase64( const RsGxsId& id,
|
||||
std::string& base64String )
|
||||
{ return serialiseIdentityToMemory(id, base64String); }
|
||||
|
||||
bool p3IdService::serialiseIdentityToMemory( const RsGxsId& id,
|
||||
std::string& radix_string )
|
||||
{
|
||||
|
@ -882,10 +878,6 @@ void p3IdService::handle_get_serialized_grp(uint32_t token)
|
|||
mSerialisedIdentities[RsGxsId(id)] = s ;
|
||||
}
|
||||
|
||||
bool p3IdService::identityFromBase64(
|
||||
const std::string& base64String, RsGxsId& id )
|
||||
{ return deserialiseIdentityFromMemory(base64String, &id); }
|
||||
|
||||
bool p3IdService::deserialiseIdentityFromMemory(const std::string& radix_string,
|
||||
RsGxsId* id /* = nullptr */)
|
||||
{
|
||||
|
@ -4717,15 +4709,89 @@ void p3IdService::handle_event(uint32_t event_type, const std::string &/*elabel*
|
|||
}
|
||||
}
|
||||
|
||||
/*static*/ const std::string RsIdentity::DEFAULT_IDENTITY_BASE_URL =
|
||||
"retroshare:///identities";
|
||||
/*static*/ const std::string RsIdentity::IDENTITY_URL_NAME_FIELD = "identityName";
|
||||
/*static*/ const std::string RsIdentity::IDENTITY_URL_ID_FIELD = "identityId";
|
||||
/*static*/ const std::string RsIdentity::IDENTITY_URL_DATA_FIELD = "identityData";
|
||||
|
||||
bool p3IdService::exportIdentityLink(
|
||||
std::string& link, const RsGxsId& id, bool includeGxsData,
|
||||
const std::string& baseUrl, std::string& errMsg )
|
||||
{
|
||||
constexpr auto fname = __PRETTY_FUNCTION__;
|
||||
const auto failure = [&](const std::string& err)
|
||||
{
|
||||
errMsg = err;
|
||||
RsErr() << fname << " " << err << std::endl;
|
||||
return false;
|
||||
};
|
||||
|
||||
if(id.isNull()) return failure("id cannot be null");
|
||||
|
||||
const bool outputRadix = baseUrl.empty();
|
||||
if(outputRadix && !includeGxsData) return
|
||||
failure("includeGxsData must be true if format requested is base64");
|
||||
|
||||
if( includeGxsData &&
|
||||
!RsGenExchange::exportGroupBase64(
|
||||
link, reinterpret_cast<const RsGxsGroupId&>(id), errMsg ) )
|
||||
return failure(errMsg);
|
||||
|
||||
if(outputRadix) return true;
|
||||
|
||||
std::vector<RsGxsIdGroup> idsInfo;
|
||||
if( !getIdentitiesInfo(std::set<RsGxsId>({id}), idsInfo )
|
||||
|| idsInfo.empty() )
|
||||
return failure("failure retrieving identity information");
|
||||
|
||||
RsUrl inviteUrl(baseUrl);
|
||||
inviteUrl.setQueryKV(IDENTITY_URL_ID_FIELD, id.toStdString());
|
||||
inviteUrl.setQueryKV(IDENTITY_URL_NAME_FIELD, idsInfo[0].mMeta.mGroupName);
|
||||
if(includeGxsData) inviteUrl.setQueryKV(IDENTITY_URL_DATA_FIELD, link);
|
||||
|
||||
link = inviteUrl.toString();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3IdService::importIdentityLink(
|
||||
const std::string& link, RsGxsId& id, std::string& errMsg )
|
||||
{
|
||||
constexpr auto fname = __PRETTY_FUNCTION__;
|
||||
const auto failure = [&](const std::string& err)
|
||||
{
|
||||
errMsg = err;
|
||||
RsErr() << fname << " " << err << std::endl;
|
||||
return false;
|
||||
};
|
||||
|
||||
if(link.empty()) return failure("link is empty");
|
||||
|
||||
const std::string* radixPtr(&link);
|
||||
|
||||
RsUrl url(link);
|
||||
const auto& query = url.query();
|
||||
const auto qIt = query.find(IDENTITY_URL_DATA_FIELD);
|
||||
if(qIt != query.end()) radixPtr = &qIt->second;
|
||||
|
||||
if(radixPtr->empty()) return failure(IDENTITY_URL_DATA_FIELD + " is empty");
|
||||
|
||||
if(!RsGenExchange::importGroupBase64(
|
||||
*radixPtr, reinterpret_cast<RsGxsGroupId&>(id), errMsg ))
|
||||
return failure(errMsg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void RsGxsIdGroup::serial_process(
|
||||
RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
{
|
||||
RS_SERIAL_PROCESS(mMeta);
|
||||
RS_SERIAL_PROCESS(mPgpIdHash);
|
||||
//RS_SERIAL_PROCESS(mPgpIdSign);
|
||||
RS_SERIAL_PROCESS(mRecognTags);
|
||||
//RS_SERIAL_PROCESS(mImage);
|
||||
RS_SERIAL_PROCESS(mPgpIdSign);
|
||||
RS_SERIAL_PROCESS(mImage);
|
||||
RS_SERIAL_PROCESS(mLastUsageTS);
|
||||
RS_SERIAL_PROCESS(mPgpKnown);
|
||||
RS_SERIAL_PROCESS(mIsAContact);
|
||||
|
@ -4798,3 +4864,6 @@ RsIdentityUsage::RsIdentityUsage() :
|
|||
RsIdentity::~RsIdentity() = default;
|
||||
RsReputationInfo::~RsReputationInfo() = default;
|
||||
RsGixs::~RsGixs() = default;
|
||||
RsIdentityDetails::~RsIdentityDetails() = default;
|
||||
GxsReputation::~GxsReputation() = default;
|
||||
RsGxsIdGroup::~RsGxsIdGroup() = default;
|
||||
|
|
|
@ -293,13 +293,32 @@ public:
|
|||
/// @see RsIdentity
|
||||
bool getOwnPseudonimousIds(std::vector<RsGxsId>& ids) override;
|
||||
|
||||
/// @see RsIdentity
|
||||
bool getOwnIds(
|
||||
std::list<RsGxsId> &ownIds, bool signed_only = false ) override;
|
||||
|
||||
/// @see RsIdentity
|
||||
bool isKnownId(const RsGxsId& id) override;
|
||||
|
||||
/// @see RsIdentity
|
||||
bool isOwnId(const RsGxsId& key_id) override;
|
||||
|
||||
/// @see RsIdentity
|
||||
bool exportIdentityLink(
|
||||
std::string& link, const RsGxsId& id,
|
||||
bool includeGxsData = true,
|
||||
const std::string& baseUrl = DEFAULT_IDENTITY_BASE_URL,
|
||||
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) override;
|
||||
|
||||
/// @see RsIdentity
|
||||
bool importIdentityLink(
|
||||
const std::string& link,
|
||||
RsGxsId& id = RS_DEFAULT_STORAGE_PARAM(RsGxsId),
|
||||
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) override;
|
||||
|
||||
|
||||
virtual bool signData( const uint8_t* data,
|
||||
uint32_t data_size,
|
||||
const RsGxsId& signer_id,
|
||||
|
@ -354,17 +373,10 @@ public:
|
|||
const RsIdentityUsage &use_info );
|
||||
virtual bool requestPrivateKey(const RsGxsId &id);
|
||||
|
||||
|
||||
/// @see RsIdentity
|
||||
bool identityToBase64( const RsGxsId& id,
|
||||
std::string& base64String ) override;
|
||||
|
||||
/// @see RsIdentity
|
||||
bool identityFromBase64( const std::string& base64String,
|
||||
RsGxsId& id ) override;
|
||||
|
||||
RS_DEPRECATED_FOR(exportIdentityLink)
|
||||
virtual bool serialiseIdentityToMemory(const RsGxsId& id,
|
||||
std::string& radix_string);
|
||||
RS_DEPRECATED_FOR(importIdentityLink)
|
||||
virtual bool deserialiseIdentityFromMemory(const std::string& radix_string,
|
||||
RsGxsId* id = nullptr);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue