summaryrefslogtreecommitdiff
path: root/core/ustring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r--core/ustring.cpp61
1 files changed, 31 insertions, 30 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp
index ff28fa420d..21ac304a1b 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -31,6 +31,7 @@
#include "ustring.h"
#include "core/color.h"
+#include "core/math/crypto_core.h"
#include "core/math/math_funcs.h"
#include "core/os/memory.h"
#include "core/print_string.h"
@@ -38,9 +39,6 @@
#include "core/ucaps.h"
#include "core/variant.h"
-#include "thirdparty/misc/md5.h"
-#include "thirdparty/misc/sha256.h"
-
#include <wchar.h>
#ifndef NO_USE_STDLIB
@@ -481,8 +479,6 @@ signed char String::nocasecmp_to(const String &p_str) const {
this_str++;
that_str++;
}
-
- return 0; //should never reach anyway
}
signed char String::casecmp_to(const String &p_str) const {
@@ -513,8 +509,6 @@ signed char String::casecmp_to(const String &p_str) const {
this_str++;
that_str++;
}
-
- return 0; //should never reach anyway
}
signed char String::naturalnocasecmp_to(const String &p_str) const {
@@ -731,8 +725,6 @@ String String::get_slicec(CharType p_splitter, int p_slice) const {
i++;
}
-
- return String(); //no find!
}
Vector<String> String::split_spaces() const {
@@ -2260,54 +2252,63 @@ uint64_t String::hash64() const {
String String::md5_text() const {
CharString cs = utf8();
- MD5_CTX ctx;
- MD5Init(&ctx);
- MD5Update(&ctx, (unsigned char *)cs.ptr(), cs.length());
- MD5Final(&ctx);
- return String::md5(ctx.digest);
+ unsigned char hash[16];
+ CryptoCore::md5((unsigned char *)cs.ptr(), cs.length(), hash);
+ return String::hex_encode_buffer(hash, 16);
+}
+
+String String::sha1_text() const {
+ CharString cs = utf8();
+ unsigned char hash[20];
+ CryptoCore::sha1((unsigned char *)cs.ptr(), cs.length(), hash);
+ return String::hex_encode_buffer(hash, 20);
}
String String::sha256_text() const {
CharString cs = utf8();
unsigned char hash[32];
- sha256_context ctx;
- sha256_init(&ctx);
- sha256_hash(&ctx, (unsigned char *)cs.ptr(), cs.length());
- sha256_done(&ctx, hash);
+ CryptoCore::sha256((unsigned char *)cs.ptr(), cs.length(), hash);
return String::hex_encode_buffer(hash, 32);
}
Vector<uint8_t> String::md5_buffer() const {
CharString cs = utf8();
- MD5_CTX ctx;
- MD5Init(&ctx);
- MD5Update(&ctx, (unsigned char *)cs.ptr(), cs.length());
- MD5Final(&ctx);
+ unsigned char hash[16];
+ CryptoCore::md5((unsigned char *)cs.ptr(), cs.length(), hash);
Vector<uint8_t> ret;
ret.resize(16);
for (int i = 0; i < 16; i++) {
- ret.write[i] = ctx.digest[i];
- };
-
+ ret.write[i] = hash[i];
+ }
return ret;
};
+Vector<uint8_t> String::sha1_buffer() const {
+ CharString cs = utf8();
+ unsigned char hash[20];
+ CryptoCore::sha1((unsigned char *)cs.ptr(), cs.length(), hash);
+
+ Vector<uint8_t> ret;
+ ret.resize(20);
+ for (int i = 0; i < 20; i++) {
+ ret.write[i] = hash[i];
+ }
+
+ return ret;
+}
+
Vector<uint8_t> String::sha256_buffer() const {
CharString cs = utf8();
unsigned char hash[32];
- sha256_context ctx;
- sha256_init(&ctx);
- sha256_hash(&ctx, (unsigned char *)cs.ptr(), cs.length());
- sha256_done(&ctx, hash);
+ CryptoCore::sha256((unsigned char *)cs.ptr(), cs.length(), hash);
Vector<uint8_t> ret;
ret.resize(32);
for (int i = 0; i < 32; i++) {
ret.write[i] = hash[i];
}
-
return ret;
}