diff options
author | Bojidar Marinov <bojidar.marinov.bg@gmail.com> | 2016-06-17 10:55:16 +0300 |
---|---|---|
committer | Bojidar Marinov <bojidar.marinov.bg@gmail.com> | 2016-06-17 10:55:16 +0300 |
commit | 7073bb0bb2c814b71f6128d249d7135dfca94b4a (patch) | |
tree | 41015e5af4288ffc3e4cc83826f5c883d2498de6 /core/os/file_access.cpp | |
parent | 367aabf03080da8e4e72c9db56b0b2097c86d6b4 (diff) |
Add sha256 to String and File/FileAccess.
Probably does #4166
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; |