diff options
author | Hein-Pieter van Braam <hp@tmm.cx> | 2019-04-23 06:38:03 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-23 06:38:03 +0300 |
commit | f2d3d3e6791591a572515ea0768bf9c8fb71acd8 (patch) | |
tree | 88aa94de453a00a658289c3ee08d5203210a11c3 | |
parent | 5c28296efe2cf950c91b566eadf280fc350b517c (diff) | |
parent | e2c3bbabb0a12f58585bb441d91ee8882225b0ee (diff) |
Merge pull request #24269 from xsellier/feature/master-add-sha256
Add SHA256 for PoolByteArray
-rw-r--r-- | core/variant_call.cpp | 15 | ||||
-rw-r--r-- | doc/classes/PoolByteArray.xml | 5 |
2 files changed, 20 insertions, 0 deletions
diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 143b07418e..f9f73b4e51 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -36,6 +36,7 @@ #include "core/object.h" #include "core/os/os.h" #include "core/script_language.h" +#include "thirdparty/misc/sha256.h" typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args); typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args); @@ -587,6 +588,19 @@ struct _VariantCall { r_ret = decompressed; } + static void _call_PoolByteArray_sha256_string(Variant &r_ret, Variant &p_self, const Variant **p_args) { + PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem); + PoolByteArray::Read r = ba->read(); + String s; + unsigned char hash[32]; + sha256_context sha256; + sha256_init(&sha256); + sha256_hash(&sha256, (unsigned char *)r.ptr(), ba->size()); + sha256_done(&sha256, hash); + s = String::hex_encode_buffer(hash, 32); + r_ret = s; + } + VCALL_LOCALMEM0R(PoolByteArray, size); VCALL_LOCALMEM2(PoolByteArray, set); VCALL_LOCALMEM1R(PoolByteArray, get); @@ -1733,6 +1747,7 @@ void register_variant_methods() { ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, get_string_from_ascii, varray()); ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, get_string_from_utf8, varray()); + ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, sha256_string, varray()); ADDFUNC1R(POOL_BYTE_ARRAY, POOL_BYTE_ARRAY, PoolByteArray, compress, INT, "compression_mode", varray(0)); ADDFUNC2R(POOL_BYTE_ARRAY, POOL_BYTE_ARRAY, PoolByteArray, decompress, INT, "buffer_size", INT, "compression_mode", varray(0)); diff --git a/doc/classes/PoolByteArray.xml b/doc/classes/PoolByteArray.xml index 67419377e8..012a38a3ea 100644 --- a/doc/classes/PoolByteArray.xml +++ b/doc/classes/PoolByteArray.xml @@ -112,6 +112,11 @@ Change the byte at the given index. </description> </method> + <method name="sha256_string"> + <description> + Return SHA256 string of the PoolByteArray. + </description> + </method> <method name="size"> <return type="int"> </return> |