diff options
Diffstat (limited to 'doc/classes/HashingContext.xml')
-rw-r--r-- | doc/classes/HashingContext.xml | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/doc/classes/HashingContext.xml b/doc/classes/HashingContext.xml index f8152c813e..f470f1611d 100644 --- a/doc/classes/HashingContext.xml +++ b/doc/classes/HashingContext.xml @@ -1,13 +1,14 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="HashingContext" inherits="Reference" version="4.0"> +<class name="HashingContext" inherits="RefCounted" version="4.0"> <brief_description> Context to compute cryptographic hashes over multiple iterations. </brief_description> <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 [enum HashType] enum shows the supported hashing algorithms. - [codeblock] - const CHUNK_SIZE = 1024 + [codeblocks] + [gdscript] + const CHUNK_SIZE = 102 func hash_file(path): var ctx = HashingContext.new() @@ -26,33 +27,57 @@ var res = ctx.finish() # Print the result as hex string and array. printt(res.hex_encode(), Array(res)) - [/codeblock] + [/gdscript] + [csharp] + public const int ChunkSize = 1024; + + public void HashFile(string path) + { + var ctx = new HashingContext(); + var file = new File(); + // Start a SHA-256 context. + ctx.Start(HashingContext.HashType.Sha256); + // Check that file exists. + if (!file.FileExists(path)) + { + return; + } + // Open the file to hash. + file.Open(path, File.ModeFlags.Read); + // Update the context after reading each chunk. + while (!file.EofReached()) + { + ctx.Update(file.GetBuffer(ChunkSize)); + } + // Get the computed hash. + byte[] res = ctx.Finish(); + // Print the result as hex string and array. + + GD.PrintT(res.HexEncode(), res); + } + [/csharp] + [/codeblocks] [b]Note:[/b] Not available in HTML5 exports. </description> <tutorials> </tutorials> <methods> <method name="finish"> - <return type="PackedByteArray"> - </return> + <return type="PackedByteArray" /> <description> Closes the current context, and return the computed hash. </description> </method> <method name="start"> - <return type="int" enum="Error"> - </return> - <argument index="0" name="type" type="int" enum="HashingContext.HashType"> - </argument> + <return type="int" enum="Error" /> + <argument index="0" name="type" type="int" enum="HashingContext.HashType" /> <description> Starts a new hash computation of the given [code]type[/code] (e.g. [constant HASH_SHA256] to start computation of a SHA-256). </description> </method> <method name="update"> - <return type="int" enum="Error"> - </return> - <argument index="0" name="chunk" type="PackedByteArray"> - </argument> + <return type="int" enum="Error" /> + <argument index="0" name="chunk" type="PackedByteArray" /> <description> Updates the computation with the given [code]chunk[/code] of data. </description> |