Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
VerifyHash.cs
1using System.Threading.Tasks;
7
9{
14 {
23 : base(new ScriptNode[] { Hash }, argumentTypes1Normal, Start, Length, Expression)
24 {
25 }
26
36 : base(new ScriptNode[] { Realm, Hash },
37 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Normal },
39 {
40 }
41
45 public override string FunctionName => nameof(VerifyHash);
46
50 public override string[] DefaultArgumentNames => new string[] { "Realm", "Hash" };
51
56 public override bool IsAsynchronous => true;
57
65 {
66 return this.EvaluateAsync(Arguments, Variables).Result;
67 }
68
75 public override async Task<IElement> EvaluateAsync(IElement[] Arguments, Variables Variables)
76 {
77 int c = Arguments.Length;
78 bool Result;
79
80 if (!(Arguments[c - 1].AssociatedObjectValue is byte[] Hash))
81 throw new ScriptRuntimeException("Expected last argument to be a hash digest.", this);
82
83 if (Arguments.Length > 1)
84 {
85 if (!(Arguments[0].AssociatedObjectValue is string Realm))
86 throw new ScriptRuntimeException("Expected first argument to be string.", this);
87
88 Result = await PersistedHashes.VerifyHash(Realm, Hash);
89 }
90 else
91 Result = await PersistedHashes.VerifyHash(Hash);
92
93 return Result ? BooleanValue.True : BooleanValue.False;
94 }
95 }
96}
Static class managing persistent counters.
static Task< bool > VerifyHash(byte[] Hash)
Verifies if a hash value has been persisted in the database, using the default (empty) realm.
Class managing a script expression.
Definition: Expression.cs:41
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
static readonly ArgumentType[] argumentTypes1Normal
One scalar parameter.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Boolean-valued number.
Definition: BooleanValue.cs:12
static readonly BooleanValue False
Constant false value.
override string FunctionName
Name of the function
Definition: VerifyHash.cs:45
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
Definition: VerifyHash.cs:56
VerifyHash(ScriptNode Hash, int Start, int Length, Expression Expression)
Verifies a hash value
Definition: VerifyHash.cs:22
override string[] DefaultArgumentNames
Default Argument names
Definition: VerifyHash.cs:50
override async Task< IElement > EvaluateAsync(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: VerifyHash.cs:75
VerifyHash(ScriptNode Realm, ScriptNode Hash, int Start, int Length, Expression Expression)
Verifies a hash value
Definition: VerifyHash.cs:35
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: VerifyHash.cs:64
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:21
ArgumentType
Type of parameter used in a function definition or a lambda definition.
Definition: IFunction.cs:9