diff options
Diffstat (limited to 'core/os/file_access.cpp')
-rw-r--r-- | core/os/file_access.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 1f23e8f33d..2f1693c044 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; |