Class HmacContext
- Namespace
- Godot
- Assembly
- GodotSharp.dll
The HMACContext class is useful for advanced HMAC use cases, such as streaming the message as it supports creating the message over time rather than providing it all at once.
using Godot;
using System.Diagnostics;
public partial class MyNode : Node
{
private HmacContext _ctx = new HmacContext();
public override void _Ready()
{
byte[] key = "supersecret".ToUtf8Buffer();
Error err = _ctx.Start(HashingContext.HashType.Sha256, key);
Debug.Assert(err == Error.Ok);
byte[] msg1 = "this is ".ToUtf8Buffer();
byte[] msg2 = "super duper secret".ToUtf8Buffer();
err = _ctx.Update(msg1);
Debug.Assert(err == Error.Ok);
err = _ctx.Update(msg2);
Debug.Assert(err == Error.Ok);
byte[] hmac = _ctx.Finish();
GD.Print(hmac.HexEncode());
}
}
[GodotClassName("HMACContext")]
public class HmacContext : RefCounted, IDisposable
- Inheritance
-
HmacContext
- Implements
- Inherited Members
Constructors
HmacContext()
public HmacContext()
Methods
Finish()
Returns the resulting HMAC. If the HMAC failed, an empty byte[] is returned.
public byte[] Finish()
Returns
- byte[]
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
Start(HashType, byte[])
Initializes the HMACContext. This method cannot be called again on the same HMACContext until Finish() has been called.
public Error Start(HashingContext.HashType hashType, byte[] key)
Parameters
hashType
HashingContext.HashTypekey
byte[]
Returns
Update(byte[])
Updates the message to be HMACed. This can be called multiple times before Finish() is called to append data
to the message, but cannot be called until Start(HashType, byte[]) has been called.
public Error Update(byte[] data)
Parameters
data
byte[]