@@ -259,6 +259,29 @@ bool storage_file_exists(Storage* storage, const char* path) {
259259 return exist ;
260260}
261261
262+ FS_Error storage_file_decrypt (File * file ) {
263+ if (storage_file_is_decrypted (file )) {
264+ return FSE_OK ;
265+ }
266+
267+ S_FILE_API_PROLOGUE ;
268+ S_API_PROLOGUE ;
269+ S_API_DATA_FILE ;
270+ S_API_MESSAGE (StorageCommandFileDecrypt );
271+ S_API_EPILOGUE ;
272+ return S_RETURN_ERROR ;
273+ }
274+
275+ FS_Error storage_file_encrypt (Storage * storage , const char * path , uint8_t key_slot ) {
276+ S_API_PROLOGUE ;
277+
278+ SAData data = {.encryption = {.path = path , .key_slot = key_slot }};
279+
280+ S_API_MESSAGE (StorageCommandFileEncrypt );
281+ S_API_EPILOGUE ;
282+ return S_RETURN_ERROR ;
283+ }
284+
262285/****************** DIR ******************/
263286
264287static bool storage_dir_open_internal (File * file , const char * path ) {
@@ -714,6 +737,26 @@ bool storage_file_is_dir(File* file) {
714737 return (file -> type == FileTypeOpenDir );
715738}
716739
740+ bool storage_file_is_encrypted (Storage * storage , const char * path ) {
741+ Stream * fstream = file_stream_alloc (storage );
742+ if (!file_stream_open (fstream , path , FSAM_READ , FSOM_OPEN_EXISTING )) {
743+ stream_free (fstream );
744+ return false;
745+ };
746+ uint8_t magic_buf [encryption_magic_size ];
747+ stream_read (fstream , magic_buf , encryption_magic_size );
748+ stream_free (fstream );
749+ return memcmp (& encryption_magic_bytes , & magic_buf , encryption_magic_size ) == 0 ;
750+ }
751+
752+ bool storage_file_is_decrypted (File * file ) {
753+ return file -> encryption && file -> encryption -> decrypted ;
754+ }
755+
756+ bool storage_file_secured (File * file ) {
757+ return file -> encryption ;
758+ }
759+
717760void storage_file_free (File * file ) {
718761 if (storage_file_is_open (file )) {
719762 if (storage_file_is_dir (file )) {
@@ -724,6 +767,7 @@ void storage_file_free(File* file) {
724767 }
725768
726769 FURI_LOG_T (TAG , "File/Dir %p free" , (void * )((uint32_t )file - SRAM_BASE ));
770+ free (file -> encryption );
727771 free (file );
728772}
729773
0 commit comments