class_hmaccontext.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/HMACContext.xml.
  6. .. _class_HMACContext:
  7. HMACContext
  8. ===========
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :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. .. tabs::
  16. .. code-tab:: gdscript
  17. extends Node
  18. var ctx = HMACContext.new()
  19. func _ready():
  20. var key = "supersecret".to_utf8_buffer()
  21. var err = ctx.start(HashingContext.HASH_SHA256, key)
  22. assert(err == OK)
  23. var msg1 = "this is ".to_utf8_buffer()
  24. var msg2 = "super duper secret".to_utf8_buffer()
  25. err = ctx.update(msg1)
  26. assert(err == OK)
  27. err = ctx.update(msg2)
  28. assert(err == OK)
  29. var hmac = ctx.finish()
  30. print(hmac.hex_encode())
  31. .. code-tab:: csharp
  32. using Godot;
  33. using System.Diagnostics;
  34. public partial class MyNode : Node
  35. {
  36. private HmacContext _ctx = new HmacContext();
  37. public override void _Ready()
  38. {
  39. byte[] key = "supersecret".ToUtf8Buffer();
  40. Error err = _ctx.Start(HashingContext.HashType.Sha256, key);
  41. Debug.Assert(err == Error.Ok);
  42. byte[] msg1 = "this is ".ToUtf8Buffer();
  43. byte[] msg2 = "super duper secret".ToUtf8Buffer();
  44. err = _ctx.Update(msg1);
  45. Debug.Assert(err == Error.Ok);
  46. err = _ctx.Update(msg2);
  47. Debug.Assert(err == Error.Ok);
  48. byte[] hmac = _ctx.Finish();
  49. GD.Print(hmac.HexEncode());
  50. }
  51. }
  52. .. rst-class:: classref-reftable-group
  53. Methods
  54. -------
  55. .. table::
  56. :widths: auto
  57. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`finish<class_HMACContext_method_finish>`\ (\ ) |
  59. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`start<class_HMACContext_method_start>`\ (\ hash_type\: :ref:`HashType<enum_HashingContext_HashType>`, key\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
  61. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`update<class_HMACContext_method_update>`\ (\ data\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
  63. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. .. rst-class:: classref-section-separator
  65. ----
  66. .. rst-class:: classref-descriptions-group
  67. Method Descriptions
  68. -------------------
  69. .. _class_HMACContext_method_finish:
  70. .. rst-class:: classref-method
  71. :ref:`PackedByteArray<class_PackedByteArray>` **finish**\ (\ ) :ref:`🔗<class_HMACContext_method_finish>`
  72. Returns the resulting HMAC. If the HMAC failed, an empty :ref:`PackedByteArray<class_PackedByteArray>` is returned.
  73. .. rst-class:: classref-item-separator
  74. ----
  75. .. _class_HMACContext_method_start:
  76. .. rst-class:: classref-method
  77. :ref:`Error<enum_@GlobalScope_Error>` **start**\ (\ hash_type\: :ref:`HashType<enum_HashingContext_HashType>`, key\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_HMACContext_method_start>`
  78. Initializes the HMACContext. This method cannot be called again on the same HMACContext until :ref:`finish<class_HMACContext_method_finish>` has been called.
  79. .. rst-class:: classref-item-separator
  80. ----
  81. .. _class_HMACContext_method_update:
  82. .. rst-class:: classref-method
  83. :ref:`Error<enum_@GlobalScope_Error>` **update**\ (\ data\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_HMACContext_method_update>`
  84. 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.
  85. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  86. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  87. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  88. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  89. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  90. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  91. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  92. .. |void| replace:: :abbr:`void (No return value.)`