Add sha256 to String and File/FileAccess.

Probably does #4166
This commit is contained in:
Bojidar Marinov
2016-06-17 10:55:16 +03:00
parent 367aabf030
commit 7073bb0bb2
10 changed files with 366 additions and 7 deletions

View File

@@ -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;