diff options
| -rw-r--r-- | include/erebos/contact.h | 2 | ||||
| -rw-r--r-- | include/erebos/identity.h | 31 | ||||
| -rw-r--r-- | src/contact.cpp | 14 | ||||
| -rw-r--r-- | src/identity.h | 31 | 
4 files changed, 41 insertions, 37 deletions
| diff --git a/include/erebos/contact.h b/include/erebos/contact.h index 963e22a..9008ce7 100644 --- a/include/erebos/contact.h +++ b/include/erebos/contact.h @@ -57,7 +57,7 @@ struct ContactData  	Ref store(const Storage &) const;  	vector<Stored<ContactData>> prev; -	vector<Stored<Signed<IdentityData>>> identity; +	vector<StoredIdentityPart> identity;  	optional<string> name;  }; diff --git a/include/erebos/identity.h b/include/erebos/identity.h index 7829361..4792330 100644 --- a/include/erebos/identity.h +++ b/include/erebos/identity.h @@ -71,6 +71,37 @@ private:  	Identity(std::shared_ptr<const Priv> && p);  }; +struct IdentityData; +struct IdentityExtension; + +struct StoredIdentityPart +{ +	using Part = variant< +		Stored<Signed<IdentityData>>, +		Stored<Signed<IdentityExtension>>>; + +	StoredIdentityPart(Part p): part(move(p)) {} + +	static StoredIdentityPart load(const Ref &); +	Ref store(const Storage & st) const; + +	bool operator==(const StoredIdentityPart & other) const +	{ return part == other.part; } +	bool operator<(const StoredIdentityPart & other) const +	{ return part < other.part; } + +	const Ref & ref() const; +	const Stored<Signed<IdentityData>> & base() const; + +	vector<StoredIdentityPart> previous() const; +	vector<Digest> roots() const; +	optional<string> name() const; +	optional<StoredIdentityPart> owner() const; +	bool isSignedBy(const Stored<PublicKey> &) const; + +	Part part; +}; +  DECLARE_SHARED_TYPE(optional<Identity>)  } diff --git a/src/contact.cpp b/src/contact.cpp index 01aa710..9ab5699 100644 --- a/src/contact.cpp +++ b/src/contact.cpp @@ -91,7 +91,7 @@ Digest Contact::leastRoot() const  void Contact::Priv::init()  {  	std::call_once(initFlag, [this]() { -		vector<Stored<Signed<IdentityData>>> idata; +		vector<StoredIdentityPart> idata;  		for (const auto & c : findPropertyComponents<Contact>(data, "identity"))  			for (const auto & i : c->identity)  				idata.push_back(i); @@ -111,9 +111,13 @@ ContactData ContactData::load(const Ref & ref)  	if (!rec)  		return ContactData(); +	vector<StoredIdentityPart> identity; +	for (const auto & r : rec->items("identity").asRef()) +		identity.push_back(StoredIdentityPart::load(r)); +  	return ContactData {  		.prev = rec->items("PREV").as<ContactData>(), -		.identity = rec->items("identity").as<Signed<IdentityData>>(), +		.identity = move(identity),  		.name = rec->item("name").asText(),  	};  } @@ -125,7 +129,7 @@ Ref ContactData::store(const Storage & st) const  	for (const auto & prev : prev)  		items.emplace_back("PREV", prev.ref());  	for (const auto & idt : identity) -		items.emplace_back("identity", idt); +		items.emplace_back("identity", idt.ref());  	if (name)  		items.emplace_back("name", *name); @@ -155,7 +159,7 @@ Stored<ContactAccepted> ContactService::handlePairingComplete(const Peer & peer)  	server.localHead().update([&] (const Stored<LocalState> & local) {  		auto cdata = local.ref().storage().store(ContactData {  			.prev = {}, -			.identity = peer.identity()->finalOwner().data(), +			.identity = peer.identity()->finalOwner().extData(),  			.name = std::nullopt,  		}); @@ -176,7 +180,7 @@ void ContactService::handlePairingResult(Context & ctx, Stored<ContactAccepted>)  {  	auto cdata = ctx.local().ref().storage().store(ContactData {  		.prev = {}, -		.identity = ctx.peer().identity()->finalOwner().data(), +		.identity = ctx.peer().identity()->finalOwner().extData(),  		.name = std::nullopt,  	}); diff --git a/src/identity.h b/src/identity.h index c3d9e2c..1653f51 100644 --- a/src/identity.h +++ b/src/identity.h @@ -15,37 +15,6 @@ using std::vector;  namespace erebos { -struct IdentityData; -struct IdentityExtension; - -struct StoredIdentityPart -{ -	using Part = variant< -		Stored<Signed<IdentityData>>, -		Stored<Signed<IdentityExtension>>>; - -	StoredIdentityPart(Part p): part(move(p)) {} - -	static StoredIdentityPart load(const Ref &); -	Ref store(const Storage & st) const; - -	bool operator==(const StoredIdentityPart & other) const -	{ return part == other.part; } -	bool operator<(const StoredIdentityPart & other) const -	{ return part < other.part; } - -	const Ref & ref() const; -	const Stored<Signed<IdentityData>> & base() const; - -	vector<StoredIdentityPart> previous() const; -	vector<Digest> roots() const; -	optional<string> name() const; -	optional<StoredIdentityPart> owner() const; -	bool isSignedBy(const Stored<PublicKey> &) const; - -	Part part; -}; -  struct IdentityData  {  	static IdentityData load(const Ref &); |