MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / open_and_parse

Method open_and_parse

crypto/file_access_encrypted_custom.cpp:49–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49Error FileAccessEncryptedCustom::open_and_parse(Ref<FileAccess> p_base, const Vector<uint8_t> &p_key, Mode p_mode, bool p_with_magic, const Vector<uint8_t> &p_iv) {
50 ERR_FAIL_COND_V_MSG(file.is_valid(), ERR_ALREADY_IN_USE, vformat("Can't open file while another file from path '%s' is open.", file->get_path_absolute()));
51 ERR_FAIL_COND_V(p_key.size() != 32, ERR_INVALID_PARAMETER);
52
53 pos = 0;
54 eofed = false;
55 use_magic = p_with_magic;
56
57 if (p_mode == MODE_WRITE_CUSTOM) {
58 ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Writing to a custom encrypted file is not supported.");
59 } else if (p_mode == MODE_READ) {
60 ERR_FAIL_NULL_V(decryptor, ERR_UNCONFIGURED);
61 writing = false;
62 key = p_key;
63 Dictionary result = decryptor->parse_and_decrypt(p_base, key, use_magic);
64 ERR_FAIL_COND_V_MSG(result.is_empty(), ERR_BUG, "Decryptor did not return a result.");
65 ERR_FAIL_COND_V_MSG(!result.has("error") || !result.has("length") || !result.has("data"), ERR_BUG, "Decryptor result is missing required keys;\nEnsure that the decryptor returns a Dictionary with the following keys: 'error', 'length', and 'data'.");
66 Error err = result["error"];
67 ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to decrypt data.");
68 length = result["length"];
69 data = result["data"];
70 ERR_FAIL_COND_V_MSG(length != data.size(), ERR_UNAUTHORIZED, "Decrypted data size mismatch; 'length' does not match data.size()");
71 file = p_base;
72 }
73
74 return OK;
75}
76
77Error FileAccessEncryptedCustom::open_and_parse_password(Ref<FileAccess> p_base, const String &p_key, Mode p_mode) {
78 String cs = p_key.md5_text();

Callers

nothing calls this directly

Calls 4

parse_and_decryptMethod · 0.80
is_validMethod · 0.45
get_path_absoluteMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected