class_hashingcontext.rst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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/HashingContext.xml.
  6. .. _class_HashingContext:
  7. HashingContext
  8. ==============
  9. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. Context to compute cryptographic hashes over multiple iterations.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. The HashingContext class provides an interface for computing cryptographic hashes over multiple iterations. This is useful for example when computing hashes of big files (so you don't have to load them all in memory), network streams, and data streams in general (so you don't have to hold buffers).
  15. The :ref:`HashType<enum_HashingContext_HashType>` enum shows the supported hashing algorithms.
  16. ::
  17. const CHUNK_SIZE = 1024
  18. func hash_file(path):
  19. var ctx = HashingContext.new()
  20. var file = File.new()
  21. # Start a SHA-256 context.
  22. ctx.start(HashingContext.HASH_SHA256)
  23. # Check that file exists.
  24. if not file.file_exists(path):
  25. return
  26. # Open the file to hash.
  27. file.open(path, File.READ)
  28. # Update the context after reading each chunk.
  29. while not file.eof_reached():
  30. ctx.update(file.get_buffer(CHUNK_SIZE))
  31. # Get the computed hash.
  32. var res = ctx.finish()
  33. # Print the result as hex string and array.
  34. printt(res.hex_encode(), Array(res))
  35. .. rst-class:: classref-reftable-group
  36. Methods
  37. -------
  38. .. table::
  39. :widths: auto
  40. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------+
  41. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`finish<class_HashingContext_method_finish>` **(** **)** |
  42. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`start<class_HashingContext_method_start>` **(** :ref:`HashType<enum_HashingContext_HashType>` type **)** |
  44. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`update<class_HashingContext_method_update>` **(** :ref:`PoolByteArray<class_PoolByteArray>` chunk **)** |
  46. +-------------------------------------------+----------------------------------------------------------------------------------------------------------------+
  47. .. rst-class:: classref-section-separator
  48. ----
  49. .. rst-class:: classref-descriptions-group
  50. Enumerations
  51. ------------
  52. .. _enum_HashingContext_HashType:
  53. .. rst-class:: classref-enumeration
  54. enum **HashType**:
  55. .. _class_HashingContext_constant_HASH_MD5:
  56. .. rst-class:: classref-enumeration-constant
  57. :ref:`HashType<enum_HashingContext_HashType>` **HASH_MD5** = ``0``
  58. Hashing algorithm: MD5.
  59. .. _class_HashingContext_constant_HASH_SHA1:
  60. .. rst-class:: classref-enumeration-constant
  61. :ref:`HashType<enum_HashingContext_HashType>` **HASH_SHA1** = ``1``
  62. Hashing algorithm: SHA-1.
  63. .. _class_HashingContext_constant_HASH_SHA256:
  64. .. rst-class:: classref-enumeration-constant
  65. :ref:`HashType<enum_HashingContext_HashType>` **HASH_SHA256** = ``2``
  66. Hashing algorithm: SHA-256.
  67. .. rst-class:: classref-section-separator
  68. ----
  69. .. rst-class:: classref-descriptions-group
  70. Method Descriptions
  71. -------------------
  72. .. _class_HashingContext_method_finish:
  73. .. rst-class:: classref-method
  74. :ref:`PoolByteArray<class_PoolByteArray>` **finish** **(** **)**
  75. Closes the current context, and return the computed hash.
  76. .. rst-class:: classref-item-separator
  77. ----
  78. .. _class_HashingContext_method_start:
  79. .. rst-class:: classref-method
  80. :ref:`Error<enum_@GlobalScope_Error>` **start** **(** :ref:`HashType<enum_HashingContext_HashType>` type **)**
  81. Starts a new hash computation of the given ``type`` (e.g. :ref:`HASH_SHA256<class_HashingContext_constant_HASH_SHA256>` to start computation of a SHA-256).
  82. .. rst-class:: classref-item-separator
  83. ----
  84. .. _class_HashingContext_method_update:
  85. .. rst-class:: classref-method
  86. :ref:`Error<enum_@GlobalScope_Error>` **update** **(** :ref:`PoolByteArray<class_PoolByteArray>` chunk **)**
  87. Updates the computation with the given ``chunk`` of data.
  88. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  89. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  90. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  91. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`