147 lines
5 KiB
ReStructuredText
147 lines
5 KiB
ReStructuredText
:github_url: hide
|
|
|
|
.. DO NOT EDIT THIS FILE!!!
|
|
.. Generated automatically from Godot engine sources.
|
|
.. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
|
|
.. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/HashingContext.xml.
|
|
|
|
.. _class_HashingContext:
|
|
|
|
HashingContext
|
|
==============
|
|
|
|
**Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
|
|
|
|
Context to compute cryptographic hashes over multiple iterations.
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
Description
|
|
-----------
|
|
|
|
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).
|
|
|
|
The :ref:`HashType<enum_HashingContext_HashType>` enum shows the supported hashing algorithms.
|
|
|
|
::
|
|
|
|
const CHUNK_SIZE = 1024
|
|
|
|
func hash_file(path):
|
|
var ctx = HashingContext.new()
|
|
var file = File.new()
|
|
# Start a SHA-256 context.
|
|
ctx.start(HashingContext.HASH_SHA256)
|
|
# Check that file exists.
|
|
if not file.file_exists(path):
|
|
return
|
|
# Open the file to hash.
|
|
file.open(path, File.READ)
|
|
# Update the context after reading each chunk.
|
|
while not file.eof_reached():
|
|
ctx.update(file.get_buffer(CHUNK_SIZE))
|
|
# Get the computed hash.
|
|
var res = ctx.finish()
|
|
# Print the result as hex string and array.
|
|
printt(res.hex_encode(), Array(res))
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
Methods
|
|
-------
|
|
|
|
.. table::
|
|
:widths: auto
|
|
|
|
+-------------------------------------------+----------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`finish<class_HashingContext_method_finish>` **(** **)** |
|
|
+-------------------------------------------+----------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`start<class_HashingContext_method_start>` **(** :ref:`HashType<enum_HashingContext_HashType>` type **)** |
|
|
+-------------------------------------------+----------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`update<class_HashingContext_method_update>` **(** :ref:`PoolByteArray<class_PoolByteArray>` chunk **)** |
|
|
+-------------------------------------------+----------------------------------------------------------------------------------------------------------------+
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
Enumerations
|
|
------------
|
|
|
|
.. _enum_HashingContext_HashType:
|
|
|
|
.. rst-class:: classref-enumeration
|
|
|
|
enum **HashType**:
|
|
|
|
.. _class_HashingContext_constant_HASH_MD5:
|
|
|
|
.. rst-class:: classref-enumeration-constant
|
|
|
|
:ref:`HashType<enum_HashingContext_HashType>` **HASH_MD5** = ``0``
|
|
|
|
Hashing algorithm: MD5.
|
|
|
|
.. _class_HashingContext_constant_HASH_SHA1:
|
|
|
|
.. rst-class:: classref-enumeration-constant
|
|
|
|
:ref:`HashType<enum_HashingContext_HashType>` **HASH_SHA1** = ``1``
|
|
|
|
Hashing algorithm: SHA-1.
|
|
|
|
.. _class_HashingContext_constant_HASH_SHA256:
|
|
|
|
.. rst-class:: classref-enumeration-constant
|
|
|
|
:ref:`HashType<enum_HashingContext_HashType>` **HASH_SHA256** = ``2``
|
|
|
|
Hashing algorithm: SHA-256.
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
Method Descriptions
|
|
-------------------
|
|
|
|
.. _class_HashingContext_method_finish:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`PoolByteArray<class_PoolByteArray>` **finish** **(** **)**
|
|
|
|
Closes the current context, and return the computed hash.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_HashingContext_method_start:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Error<enum_@GlobalScope_Error>` **start** **(** :ref:`HashType<enum_HashingContext_HashType>` type **)**
|
|
|
|
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).
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_HashingContext_method_update:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Error<enum_@GlobalScope_Error>` **update** **(** :ref:`PoolByteArray<class_PoolByteArray>` chunk **)**
|
|
|
|
Updates the computation with the given ``chunk`` of data.
|
|
|
|
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
|
|
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
|
|
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
|
|
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
|