@@ -259,6 +259,29 @@ bool storage_file_exists(Storage* storage, const char* path) {
259
259
return exist ;
260
260
}
261
261
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
+
262
285
/****************** DIR ******************/
263
286
264
287
static bool storage_dir_open_internal (File * file , const char * path ) {
@@ -714,6 +737,26 @@ bool storage_file_is_dir(File* file) {
714
737
return (file -> type == FileTypeOpenDir );
715
738
}
716
739
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
+
717
760
void storage_file_free (File * file ) {
718
761
if (storage_file_is_open (file )) {
719
762
if (storage_file_is_dir (file )) {
@@ -724,6 +767,7 @@ void storage_file_free(File* file) {
724
767
}
725
768
726
769
FURI_LOG_T (TAG , "File/Dir %p free" , (void * )((uint32_t )file - SRAM_BASE ));
770
+ free (file -> encryption );
727
771
free (file );
728
772
}
729
773
0 commit comments