Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
HS256.cs
1using System;
2using Waher.Script;
7
9{
14 {
23 {
24 }
25
34 : base(new ScriptNode[] { Secret }, argumentTypes1Scalar, Start, Length, Expression)
35 {
36 }
37
41 public override string FunctionName => nameof(HS256);
42
46 public override string[] DefaultArgumentNames => new string[] { "Secret" };
47
55 {
56 if (Arguments.Length == 0)
57 return new ObjectValue(new HmacSha256());
58
59 object Obj = Arguments[0].AssociatedObjectValue;
60
61 if (Obj is byte[] Bin)
62 return new ObjectValue(new HmacSha256(Bin));
63 else if (Obj is string s)
64 return new ObjectValue(new HmacSha256(Convert.FromBase64String(s)));
65 else
66 throw new ScriptRuntimeException("Expected secret to be a binary array, or a base64-encoded string.", this);
67 }
68 }
69}
Class managing a script expression.
Definition: Expression.cs:39
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
static readonly ArgumentType[] argumentTypes0
Zero parameters.
static readonly ArgumentType[] argumentTypes1Scalar
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
Collection of variables.
Definition: Variables.cs:25
Creates an HMAC SHA-256 JSON Web Signature key.
Definition: HS256.cs:14
HS256(int Start, int Length, Expression Expression)
Creates an HMAC SHA-256 JSON Web Signature key.
Definition: HS256.cs:21
HS256(ScriptNode Secret, int Start, int Length, Expression Expression)
Creates an HMAC SHA-256 JSON Web Signature key.
Definition: HS256.cs:33
override string FunctionName
Name of the function
Definition: HS256.cs:41
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: HS256.cs:54
override string[] DefaultArgumentNames
Default Argument names
Definition: HS256.cs:46
HMAC SHA-256 algorithm.
Definition: HmacSha256.cs:11
Basic interface for all types of elements.
Definition: IElement.cs:20