mirror of
https://github.com/godotengine/godot.git
synced 2024-11-14 08:03:05 +00:00
Feature: Add SHA256 for PoolByteArray
This commit is contained in:
parent
fa024537a3
commit
e2c3bbabb0
@ -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);
|
||||
@ -583,6 +584,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);
|
||||
@ -1723,6 +1737,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));
|
||||
|
||||
|
@ -114,6 +114,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>
|
||||
|
Loading…
Reference in New Issue
Block a user