| 47 | } |
| 48 | |
| 49 | Error 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 | |
| 77 | Error FileAccessEncryptedCustom::open_and_parse_password(Ref<FileAccess> p_base, const String &p_key, Mode p_mode) { |
| 78 | String cs = p_key.md5_text(); |
nothing calls this directly
no test coverage detected