Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ContractSharedSecretState.cs
1using System;
2using System.Text;
9
11{
15 [CollectionName("ContractSharedSecretStates")]
16 [TypeName(TypeNameSerialization.None)]
17 [Index("BareJid", "ContractId")]
19 {
20 private static ICallStackCheck[] approvedSources = null;
21
22 private string objectId = null;
24 private string contractId = string.Empty;
25 private string creatorJid = string.Empty;
26 private SymmetricCipherAlgorithms keyAlgorithm = SymmetricCipherAlgorithms.Aes256;
27 private byte[] sharedSecret = null;
28
33 {
34 }
35
41 {
42 this.contractId = ContractId;
43 }
44
48 [ObjectId]
49 public string ObjectId
50 {
51 get => this.objectId;
52 set => this.objectId = value;
53 }
54
59 {
60 get => this.bareJid;
61 set => this.bareJid = value;
62 }
63
67 public string ContractId
68 {
69 get => this.contractId;
70 set => this.contractId = value;
71 }
72
76 [DefaultValueStringEmpty]
77 public string CreatorJid
78 {
79 get => this.creatorJid;
80 set => this.creatorJid = value;
81 }
82
87 {
88 get => this.keyAlgorithm;
89 set => this.keyAlgorithm = value;
90 }
91
95 public bool HasSharedSecret => !(this.sharedSecret is null);
96
100 [DefaultValueNull]
101 [Encrypted(32)]
102 public byte[] SharedSecret
103 {
104 get
105 {
106 AssertAllowed();
107 return this.sharedSecret;
108 }
109
110 set
111 {
112 if (!(this.sharedSecret is null))
113 AssertAllowed();
114
115 this.sharedSecret = value;
116 }
117 }
118
122 public string[] EncryptedProperties => new string[]
123 {
124 nameof(this.SharedSecret)
125 };
126
132 public static void SetAllowedSources(ICallStackCheck[] ApprovedSources)
133 {
134 if (!(approvedSources is null))
135 throw new NotSupportedException("Changing approved sources not permitted.");
136
137 approvedSources = ApprovedSources;
138 }
139
140 private static void AssertAllowed()
141 {
142 if (!(approvedSources is null))
143 Assert.CallFromSource(approvedSources);
144 }
145
147 public override string ToString()
148 {
149 StringBuilder sb = new StringBuilder();
150
151 sb.Append(this.bareJid);
152 sb.Append(", ");
153 sb.Append(this.contractId);
154 sb.Append(", ");
155 sb.Append(this.creatorJid);
156 sb.Append(", ");
157 sb.Append(this.keyAlgorithm.ToString());
158
159 if (!(this.sharedSecret is null))
160 sb.Append(", SharedSecret");
161
162 return sb.ToString();
163 }
164 }
165}
Contains a persisted shared secret associated with a smart contract.
bool HasSharedSecret
If a shared secret snapshot is available for the contract.
SymmetricCipherAlgorithms KeyAlgorithm
Symmetric encryption algorithm used with the shared secret.
string[] EncryptedProperties
Array of properties that are encrypted.
byte[] SharedSecret
Shared secret snapshot stored with the contract state.
ContractSharedSecretState(string ContractId)
Contains a persisted shared secret associated with a smart contract.
static void SetAllowedSources(ICallStackCheck[] ApprovedSources)
If access to sensitive properties is only accessible from a set of approved sources.
CaseInsensitiveString BareJid
Bare JID of the client owning the contract state.
ContractSharedSecretState()
Contains a persisted shared secret associated with a smart contract.
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.
SymmetricCipherAlgorithms
Enumeration of symmetric cipher algorithms available in the library.
TypeNameSerialization
How the type name should be serialized.