class_hmaccontext.rst 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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()
  21. var err = ctx.start(HashingContext.HASH_SHA256, key)
  22. assert(err == OK)
  23. var msg1 = "this is ".to_utf8()
  24. var msg2 = "super duper secret".to_utf8()
  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;
  34. using System.Diagnostics;
  35. public class CryptoNode : Node
  36. {
  37. private HMACContext ctx = new HMACContext();
  38. public override void _Ready()
  39. {
  40. byte[] key = "supersecret".ToUTF8();
  41. Error err = ctx.Start(HashingContext.HashType.Sha256, key);
  42. Debug.Assert(err == Error.Ok);
  43. byte[] msg1 = "this is ".ToUTF8();
  44. byte[] msg2 = "super duper secret".ToUTF8();
  45. err = ctx.Update(msg1);
  46. Debug.Assert(err == Error.Ok);
  47. err = ctx.Update(msg2);
  48. Debug.Assert(err == Error.Ok);
  49. byte[] hmac = ctx.Finish();
  50. GD.Print(hmac.HexEncode());
  51. }
  52. }
  53. .. rst-class:: classref-reftable-group
  54. Methods
  55. -------
  56. .. table::
  57. :widths: auto
  58. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`finish<class_HMACContext_method_finish>` **(** **)** |
  60. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`start<class_HMACContext_method_start>` **(** :ref:`HashType<enum_HashingContext_HashType>` hash_type, :ref:`PackedByteArray<class_PackedByteArray>` key **)** |
  62. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`update<class_HMACContext_method_update>` **(** :ref:`PackedByteArray<class_PackedByteArray>` data **)** |
  64. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. .. rst-class:: classref-section-separator
  66. ----
  67. .. rst-class:: classref-descriptions-group
  68. Method Descriptions
  69. -------------------
  70. .. _class_HMACContext_method_finish:
  71. .. rst-class:: classref-method
  72. :ref:`PackedByteArray<class_PackedByteArray>` **finish** **(** **)**
  73. Returns the resulting HMAC. If the HMAC failed, an empty :ref:`PackedByteArray<class_PackedByteArray>` is returned.
  74. .. rst-class:: classref-item-separator
  75. ----
  76. .. _class_HMACContext_method_start:
  77. .. rst-class:: classref-method
  78. :ref:`Error<enum_@GlobalScope_Error>` **start** **(** :ref:`HashType<enum_HashingContext_HashType>` hash_type, :ref:`PackedByteArray<class_PackedByteArray>` key **)**
  79. Initializes the HMACContext. This method cannot be called again on the same HMACContext until :ref:`finish<class_HMACContext_method_finish>` has been called.
  80. .. rst-class:: classref-item-separator
  81. ----
  82. .. _class_HMACContext_method_update:
  83. .. rst-class:: classref-method
  84. :ref:`Error<enum_@GlobalScope_Error>` **update** **(** :ref:`PackedByteArray<class_PackedByteArray>` data **)**
  85. 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.
  86. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  87. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  88. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  89. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  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.)`
  91. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`