summaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
Diffstat (limited to 'core/os')
-rw-r--r--core/os/file_access.cpp40
-rw-r--r--core/os/os.cpp29
-rw-r--r--core/os/os.h1
3 files changed, 48 insertions, 22 deletions
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index b5580b5c6e..7509050b2b 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -32,12 +32,10 @@
#include "core/io/file_access_pack.h"
#include "core/io/marshalls.h"
+#include "core/math/crypto_core.h"
#include "core/os/os.h"
#include "core/project_settings.h"
-#include "thirdparty/misc/md5.h"
-#include "thirdparty/misc/sha256.h"
-
FileAccess::CreateFunc FileAccess::create_func[ACCESS_MAX] = { 0, 0 };
FileAccess::FileCloseFailNotify FileAccess::close_fail_notify = NULL;
@@ -637,8 +635,8 @@ String FileAccess::get_md5(const String &p_file) {
if (!f)
return String();
- MD5_CTX md5;
- MD5Init(&md5);
+ CryptoCore::MD5Context ctx;
+ ctx.start();
unsigned char step[32768];
@@ -647,24 +645,24 @@ String FileAccess::get_md5(const String &p_file) {
int br = f->get_buffer(step, 32768);
if (br > 0) {
- MD5Update(&md5, step, br);
+ ctx.update(step, br);
}
if (br < 4096)
break;
}
- MD5Final(&md5);
-
- String ret = String::md5(md5.digest);
+ unsigned char hash[16];
+ ctx.finish(hash);
memdelete(f);
- return ret;
+
+ return String::md5(hash);
}
String FileAccess::get_multiple_md5(const Vector<String> &p_file) {
- MD5_CTX md5;
- MD5Init(&md5);
+ CryptoCore::MD5Context ctx;
+ ctx.start();
for (int i = 0; i < p_file.size(); i++) {
FileAccess *f = FileAccess::open(p_file[i], READ);
@@ -677,7 +675,7 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) {
int br = f->get_buffer(step, 32768);
if (br > 0) {
- MD5Update(&md5, step, br);
+ ctx.update(step, br);
}
if (br < 4096)
break;
@@ -685,11 +683,10 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) {
memdelete(f);
}
- MD5Final(&md5);
+ unsigned char hash[16];
+ ctx.finish(hash);
- String ret = String::md5(md5.digest);
-
- return ret;
+ return String::md5(hash);
}
String FileAccess::get_sha256(const String &p_file) {
@@ -698,8 +695,8 @@ String FileAccess::get_sha256(const String &p_file) {
if (!f)
return String();
- sha256_context sha256;
- sha256_init(&sha256);
+ CryptoCore::SHA256Context ctx;
+ ctx.start();
unsigned char step[32768];
@@ -708,15 +705,14 @@ String FileAccess::get_sha256(const String &p_file) {
int br = f->get_buffer(step, 32768);
if (br > 0) {
- sha256_hash(&sha256, step, br);
+ ctx.update(step, br);
}
if (br < 4096)
break;
}
unsigned char hash[32];
-
- sha256_done(&sha256, hash);
+ ctx.finish(hash);
memdelete(f);
return String::hex_encode_buffer(hash, 32);
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 08067385ab..925154af7d 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -51,6 +51,35 @@ uint32_t OS::get_ticks_msec() const {
return get_ticks_usec() / 1000;
}
+String OS::get_iso_date_time(bool local) const {
+ OS::Date date = get_date(local);
+ OS::Time time = get_time(local);
+
+ String timezone;
+ if (!local) {
+ TimeZoneInfo zone = get_time_zone_info();
+ if (zone.bias >= 0) {
+ timezone = "+";
+ }
+ timezone = timezone + itos(zone.bias / 60).pad_zeros(2) + itos(zone.bias % 60).pad_zeros(2);
+ } else {
+ timezone = "Z";
+ }
+
+ return itos(date.year).pad_zeros(2) +
+ "-" +
+ itos(date.month).pad_zeros(2) +
+ "-" +
+ itos(date.day).pad_zeros(2) +
+ "T" +
+ itos(time.hour).pad_zeros(2) +
+ ":" +
+ itos(time.min).pad_zeros(2) +
+ ":" +
+ itos(time.sec).pad_zeros(2) +
+ timezone;
+}
+
uint64_t OS::get_splash_tick_msec() const {
return _msec_splash;
}
diff --git a/core/os/os.h b/core/os/os.h
index 1b19ddff26..2224d3b006 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -336,6 +336,7 @@ public:
virtual Date get_date(bool local = false) const = 0;
virtual Time get_time(bool local = false) const = 0;
virtual TimeZoneInfo get_time_zone_info() const = 0;
+ virtual String get_iso_date_time(bool local = false) const;
virtual uint64_t get_unix_time() const;
virtual uint64_t get_system_time_secs() const;
virtual uint64_t get_system_time_msecs() const;