class_hmaccontext.rst 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/HMACContext.xml.
  6. .. _class_HMACContext:
  7. HMACContext
  8. ===========
  9. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. Used to create an HMAC for a message using a key.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. 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.
  15. ::
  16. extends Node
  17. var ctx = HMACContext.new()
  18. func _ready():
  19. var key = "supersecret".to_utf8()
  20. var err = ctx.start(HashingContext.HASH_SHA256, key)
  21. assert(err == OK)
  22. var msg1 = "this is ".to_utf8()
  23. var msg2 = "super duper secret".to_utf8()
  24. err = ctx.update(msg1)
  25. assert(err == OK)
  26. err = ctx.update(msg2)
  27. assert(err == OK)
  28. var hmac = ctx.finish()
  29. print(hmac.hex_encode())
  30. And in C# we can use the following.
  31. ::
  32. using Godot;
  33. using System;
  34. using System.Diagnostics;
  35. public class CryptoNode : Node
  36. {
  37. private HMACContext ctx = new HMACContext();
  38. public override void _Ready()
  39. {
  40. PoolByteArray key = String("supersecret").to_utf8();
  41. Error err = ctx.Start(HashingContext.HASH_SHA256, key);
  42. GD.Assert(err == OK);
  43. PoolByteArray msg1 = String("this is ").to_utf8();
  44. PoolByteArray msg2 = String("super duper secret").to_utf8();
  45. err = ctx.Update(msg1);
  46. GD.Assert(err == OK);
  47. err = ctx.Update(msg2);
  48. GD.Assert(err == OK);
  49. PoolByteArray hmac = ctx.Finish();
  50. GD.Print(hmac.HexEncode());
  51. }
  52. }
  53. \ **Note:** Not available in HTML5 exports.
  54. .. rst-class:: classref-reftable-group
  55. Methods
  56. -------
  57. .. table::
  58. :widths: auto
  59. +-------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`finish<class_HMACContext_method_finish>` **(** **)** |
  61. +-------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`start<class_HMACContext_method_start>` **(** :ref:`HashType<enum_HashingContext_HashType>` hash_type, :ref:`PoolByteArray<class_PoolByteArray>` key **)** |
  63. +-------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`update<class_HMACContext_method_update>` **(** :ref:`PoolByteArray<class_PoolByteArray>` data **)** |
  65. +-------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. .. rst-class:: classref-section-separator
  67. ----
  68. .. rst-class:: classref-descriptions-group
  69. Method Descriptions
  70. -------------------
  71. .. _class_HMACContext_method_finish:
  72. .. rst-class:: classref-method
  73. :ref:`PoolByteArray<class_PoolByteArray>` **finish** **(** **)**
  74. Returns the resulting HMAC. If the HMAC failed, an empty :ref:`PoolByteArray<class_PoolByteArray>` is returned.
  75. .. rst-class:: classref-item-separator
  76. ----
  77. .. _class_HMACContext_method_start:
  78. .. rst-class:: classref-method
  79. :ref:`Error<enum_@GlobalScope_Error>` **start** **(** :ref:`HashType<enum_HashingContext_HashType>` hash_type, :ref:`PoolByteArray<class_PoolByteArray>` key **)**
  80. Initializes the HMACContext. This method cannot be called again on the same HMACContext until :ref:`finish<class_HMACContext_method_finish>` has been called.
  81. .. rst-class:: classref-item-separator
  82. ----
  83. .. _class_HMACContext_method_update:
  84. .. rst-class:: classref-method
  85. :ref:`Error<enum_@GlobalScope_Error>` **update** **(** :ref:`PoolByteArray<class_PoolByteArray>` data **)**
  86. Updates the message to be HMACed. This can be called multiple times before :ref:`finish<class_HMACContext_method_finish>` is called to append ``data`` to the message, but cannot be called until :ref:`start<class_HMACContext_method_start>` has been called.
  87. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  88. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  89. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  90. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`