file_access_encrypted.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*************************************************************************/
  2. /* file_access_encrypted.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef FILE_ACCESS_ENCRYPTED_H
  30. #define FILE_ACCESS_ENCRYPTED_H
  31. #include "os/file_access.h"
  32. class FileAccessEncrypted : public FileAccess {
  33. public:
  34. enum Mode {
  35. MODE_READ,
  36. MODE_WRITE_AES256,
  37. MODE_MAX
  38. };
  39. private:
  40. Mode mode;
  41. Vector<uint8_t> key;
  42. bool writing;
  43. FileAccess *file;
  44. size_t base;
  45. size_t length;
  46. Vector<uint8_t> data;
  47. mutable size_t pos;
  48. mutable bool eofed;
  49. public:
  50. Error open_and_parse(FileAccess *p_base,const Vector<uint8_t>& p_key,Mode p_mode);
  51. Error open_and_parse_password(FileAccess *p_base,const String& p_key,Mode p_mode);
  52. virtual Error _open(const String& p_path, int p_mode_flags); ///< open a file
  53. virtual void close(); ///< close a file
  54. virtual bool is_open() const; ///< true when file is open
  55. virtual void seek(size_t p_position); ///< seek to a given position
  56. virtual void seek_end(int64_t p_position=0); ///< seek from the end of file
  57. virtual size_t get_pos() const; ///< get position in the file
  58. virtual size_t get_len() const; ///< get size of the file
  59. virtual bool eof_reached() const; ///< reading passed EOF
  60. virtual uint8_t get_8() const; ///< get a byte
  61. virtual int get_buffer(uint8_t *p_dst, int p_length) const;
  62. virtual Error get_error() const; ///< get last error
  63. virtual void store_8(uint8_t p_dest); ///< store a byte
  64. virtual void store_buffer(const uint8_t *p_src,int p_length); ///< store an array of bytes
  65. virtual bool file_exists(const String& p_name); ///< return true if a file exists
  66. virtual uint64_t _get_modified_time(const String& p_file);
  67. FileAccessEncrypted();
  68. ~FileAccessEncrypted();
  69. };
  70. #endif // FILE_ACCESS_ENCRYPTED_H