diff options
Diffstat (limited to 'core/os')
| -rw-r--r-- | core/os/file_access.cpp | 33 | ||||
| -rw-r--r-- | core/os/file_access.h | 1 |
2 files changed, 34 insertions, 0 deletions
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 1f23e8f33..2f1693c04 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -31,6 +31,7 @@ #include "os/os.h" #include "core/io/marshalls.h" #include "io/md5.h" +#include "io/sha256.h" #include "core/io/file_access_pack.h" FileAccess::CreateFunc FileAccess::create_func[ACCESS_MAX]={0,0}; @@ -517,6 +518,38 @@ String FileAccess::get_md5(const String& p_file) { } +String FileAccess::get_sha256(const String& p_file) { + + FileAccess *f=FileAccess::open(p_file,READ); + if (!f) + return String(); + + sha256_context sha256; + sha256_init(&sha256); + + unsigned char step[32768]; + + while(true) { + + int br = f->get_buffer(step,32768); + if (br>0) { + + sha256_hash(&sha256,step,br); + } + if (br < 4096) + break; + + } + + unsigned char hash[32]; + + sha256_done(&sha256, hash); + + memdelete(f); + return String::hex_encode_buffer(hash, 32); + +} + FileAccess::FileAccess() { endian_swap=false; diff --git a/core/os/file_access.h b/core/os/file_access.h index 8d5823663..5178c469b 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -153,6 +153,7 @@ public: static bool is_backup_save_enabled() { return backup_save; }; static String get_md5(const String& p_file); + static String get_sha256(const String& p_file); static Vector<uint8_t> get_file_as_array(const String& p_path); |
