summaryrefslogtreecommitdiff
path: root/core/io/file_access_encrypted.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/io/file_access_encrypted.cpp')
-rw-r--r--core/io/file_access_encrypted.cpp33
1 files changed, 0 insertions, 33 deletions
diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp
index 271c34ec4a..aaf21ad143 100644
--- a/core/io/file_access_encrypted.cpp
+++ b/core/io/file_access_encrypted.cpp
@@ -40,7 +40,6 @@
#define COMP_MAGIC 0x43454447
Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8_t> &p_key, Mode p_mode) {
-
ERR_FAIL_COND_V_MSG(file != nullptr, ERR_ALREADY_IN_USE, "Can't open file while another file from path '" + file->get_path_absolute() + "' is open.");
ERR_FAIL_COND_V(p_key.size() != 32, ERR_INVALID_PARAMETER);
@@ -48,7 +47,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
eofed = false;
if (p_mode == MODE_WRITE_AES256) {
-
data.clear();
writing = true;
file = p_base;
@@ -56,7 +54,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
key = p_key;
} else if (p_mode == MODE_READ) {
-
writing = false;
key = p_key;
uint32_t magic = p_base->get_32();
@@ -85,7 +82,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
ctx.set_decode_key(key.ptrw(), 256);
for (size_t i = 0; i < ds; i += 16) {
-
ctx.decrypt_ecb(&data.write[i], &data.write[i]);
}
@@ -103,13 +99,11 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
}
Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base, const String &p_key, Mode p_mode) {
-
String cs = p_key.md5_text();
ERR_FAIL_COND_V(cs.length() != 32, ERR_INVALID_PARAMETER);
Vector<uint8_t> key;
key.resize(32);
for (int i = 0; i < 32; i++) {
-
key.write[i] = cs[i];
}
@@ -117,16 +111,13 @@ Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base, const Str
}
Error FileAccessEncrypted::_open(const String &p_path, int p_mode_flags) {
-
return OK;
}
void FileAccessEncrypted::close() {
-
if (!file)
return;
if (writing) {
-
Vector<uint8_t> compressed;
size_t len = data.size();
if (len % 16) {
@@ -146,7 +137,6 @@ void FileAccessEncrypted::close() {
ctx.set_encode_key(key.ptrw(), 256);
for (size_t i = 0; i < len; i += 16) {
-
ctx.encrypt_ecb(&compressed.write[i], &compressed.write[i]);
}
@@ -163,7 +153,6 @@ void FileAccessEncrypted::close() {
data.clear();
} else {
-
file->close();
memdelete(file);
data.clear();
@@ -172,12 +161,10 @@ void FileAccessEncrypted::close() {
}
bool FileAccessEncrypted::is_open() const {
-
return file != nullptr;
}
String FileAccessEncrypted::get_path() const {
-
if (file)
return file->get_path();
else
@@ -185,7 +172,6 @@ String FileAccessEncrypted::get_path() const {
}
String FileAccessEncrypted::get_path_absolute() const {
-
if (file)
return file->get_path_absolute();
else
@@ -193,7 +179,6 @@ String FileAccessEncrypted::get_path_absolute() const {
}
void FileAccessEncrypted::seek(size_t p_position) {
-
if (p_position > (size_t)data.size())
p_position = data.size();
@@ -202,25 +187,20 @@ void FileAccessEncrypted::seek(size_t p_position) {
}
void FileAccessEncrypted::seek_end(int64_t p_position) {
-
seek(data.size() + p_position);
}
size_t FileAccessEncrypted::get_position() const {
-
return pos;
}
size_t FileAccessEncrypted::get_len() const {
-
return data.size();
}
bool FileAccessEncrypted::eof_reached() const {
-
return eofed;
}
uint8_t FileAccessEncrypted::get_8() const {
-
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
if (pos >= data.size()) {
eofed = true;
@@ -232,12 +212,10 @@ uint8_t FileAccessEncrypted::get_8() const {
return b;
}
int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const {
-
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
int to_copy = MIN(p_length, data.size() - pos);
for (int i = 0; i < to_copy; i++) {
-
p_dst[i] = data[pos++];
}
@@ -249,25 +227,19 @@ int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const {
}
Error FileAccessEncrypted::get_error() const {
-
return eofed ? ERR_FILE_EOF : OK;
}
void FileAccessEncrypted::store_buffer(const uint8_t *p_src, int p_length) {
-
ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode.");
if (pos < data.size()) {
-
for (int i = 0; i < p_length; i++) {
-
store_8(p_src[i]);
}
} else if (pos == data.size()) {
-
data.resize(pos + p_length);
for (int i = 0; i < p_length; i++) {
-
data.write[pos + i] = p_src[i];
}
pos += p_length;
@@ -281,7 +253,6 @@ void FileAccessEncrypted::flush() {
}
void FileAccessEncrypted::store_8(uint8_t p_dest) {
-
ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode.");
if (pos < data.size()) {
@@ -294,7 +265,6 @@ void FileAccessEncrypted::store_8(uint8_t p_dest) {
}
bool FileAccessEncrypted::file_exists(const String &p_name) {
-
FileAccess *fa = FileAccess::open(p_name, FileAccess::READ);
if (!fa)
return false;
@@ -303,12 +273,10 @@ bool FileAccessEncrypted::file_exists(const String &p_name) {
}
uint64_t FileAccessEncrypted::_get_modified_time(const String &p_file) {
-
return 0;
}
uint32_t FileAccessEncrypted::_get_unix_permissions(const String &p_file) {
-
return 0;
}
@@ -318,7 +286,6 @@ Error FileAccessEncrypted::_set_unix_permissions(const String &p_file, uint32_t
}
FileAccessEncrypted::~FileAccessEncrypted() {
-
if (file)
close();
}