Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
LegalIdentityState.cs
1using System;
2using System.Text;
7
9{
13 [CollectionName("LegalIdentityStates")]
14 [TypeName(TypeNameSerialization.None)]
15 [Index("BareJid", "LegalId")]
16 [Index("BareJid", "State", "Timestamp")]
17 [Singleton]
19 {
20 private static ICallStackCheck[] approvedSources = null;
21
22 private string objectId = null;
25 private byte[] publicKey = null;
26 private string keyName = null;
27 private string keyNamespace = null;
28 private byte[] privateKey = null;
29 private IdentityState state = IdentityState.Created;
30 private DateTime timestamp = DateTime.MinValue;
31
36 {
37 }
38
44 {
45 this.legalId = LegalId;
46 }
47
51 [ObjectId]
52 public string ObjectId
53 {
54 get => this.objectId;
55 set => this.objectId = value;
56 }
57
62 {
63 get => this.bareJid;
64 set => this.bareJid = value;
65 }
66
71 {
72 get => this.legalId;
73 set => this.legalId = value;
74 }
75
79 [DefaultValueNull]
80 public byte[] PublicKey
81 {
82 get => this.publicKey;
83 set => this.publicKey = value;
84 }
85
89 [DefaultValueNull]
90 public string KeyName
91 {
92 get => this.keyName;
93 set => this.keyName = value;
94 }
95
99 [DefaultValueNull]
100 public string KeyNamespace
101 {
102 get => this.keyNamespace;
103 set => this.keyNamespace = value;
104 }
105
109 public bool HasPrivateKey => !(this.privateKey is null);
110
114 [DefaultValueNull]
115 [Encrypted(32)]
116 public byte[] PrivateKey
117 {
118 get
119 {
120 AssertAllowed();
121 return this.privateKey;
122 }
123
124 set
125 {
126 if (!(this.privateKey is null))
127 AssertAllowed();
128
129 this.privateKey = value;
130 }
131 }
132
137 {
138 get => this.state;
139 set => this.state = value;
140 }
141
145 public DateTime Timestamp
146 {
147 get => this.timestamp;
148 set => this.timestamp = value;
149 }
150
154 public string[] EncryptedProperties => new string[]
155 {
156 nameof(this.PrivateKey)
157 };
158
164 public static void SetAllowedSources(ICallStackCheck[] ApprovedSources)
165 {
166 if (!(approvedSources is null))
167 throw new NotSupportedException("Changing approved sources not permitted.");
168
169 approvedSources = ApprovedSources;
170 }
171
172 private static void AssertAllowed()
173 {
174 if (!(approvedSources is null))
175 Assert.CallFromSource(approvedSources);
176 }
177
179 public override string ToString()
180 {
181 StringBuilder sb = new StringBuilder();
182
183 sb.Append(this.bareJid);
184 sb.Append(", ");
185 sb.Append(this.legalId);
186 sb.Append(", ");
187 sb.Append(this.state.ToString());
188 sb.Append(", ");
189 sb.Append(this.timestamp.ToString());
190
191 if (!(this.publicKey is null))
192 {
193 sb.Append(", ");
194 sb.Append(Convert.ToBase64String(this.publicKey));
195 }
196
197 if (!string.IsNullOrEmpty(this.keyName))
198 {
199 sb.Append(", ");
200 sb.Append(this.keyName);
201 }
202
203 if (!string.IsNullOrEmpty(this.keyNamespace))
204 {
205 sb.Append(", ");
206 sb.Append(this.keyNamespace);
207 }
208
209 if (!(this.privateKey is null))
210 {
211 sb.Append(", PrivateKey");
212 }
213
214 return sb.ToString();
215 }
216 }
217}
Represents a case-insensitive string.
static readonly CaseInsensitiveString Empty
Empty case-insensitive string
Static class containing methods that can be used to make sure calls are made from appropriate locatio...
Definition: Assert.cs:15
static void CallFromSource(params string[] Sources)
Makes sure the call is made from one of the listed sources.
Definition: Assert.cs:54
Interface for objects containing encrypted properties. Mark the properties that are encrypted with th...
Interface for call stack checks.
IdentityState
Lists recognized legal identity states.
TypeNameSerialization
How the type name should be serialized.