summaryrefslogtreecommitdiff
path: root/include/erebos/identity.h
blob: 888f16239cc2545d652a98a91afac5424c141e28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once

#include <erebos/state.h>
#include <erebos/storage.h>

namespace erebos {

using std::optional;
using std::vector;

template<class T> class Signed;
struct IdentityData;

class Identity
{
public:
	Identity(const Identity &) = default;
	Identity(Identity &&) = default;
	Identity & operator=(const Identity &) = default;
	Identity & operator=(Identity &&) = default;

	static std::optional<Identity> load(const Ref &);
	static std::optional<Identity> load(const std::vector<Ref> &);
	static std::optional<Identity> load(const std::vector<Stored<Signed<IdentityData>>> &);
	std::vector<Ref> store() const;
	std::vector<Ref> store(const Storage & st) const;
	const vector<Stored<Signed<IdentityData>>> & data() const;

	std::optional<std::string> name() const;
	std::optional<Identity> owner() const;
	const Identity & finalOwner() const;

	Stored<class PublicKey> keyIdentity() const;
	Stored<class PublicKey> keyMessage() const;

	bool sameAs(const Identity &) const;
	bool operator==(const Identity & other) const;
	bool operator!=(const Identity & other) const;

	std::optional<Ref> ref() const;

	class Builder
	{
	public:
		Identity commit() const;

		void name(const std::string &);
		void owner(const Identity &);

	private:
		friend class Identity;
		struct Priv;
		const std::shared_ptr<Priv> p;
		Builder(Priv * p);
	};

	static Builder create(const Storage &);
	Builder modify() const;

private:
	struct Priv;
	std::shared_ptr<const Priv> p;
	Identity(const Priv * p);
	Identity(std::shared_ptr<const Priv> && p);
};

DECLARE_SHARED_TYPE(optional<Identity>)

}