Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33330851
D4385.1768883261.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D4385.1768883261.diff
View Options
diff --git a/native/ios/Comm/TemporaryMessageStorage/EncryptedFileUtils.mm b/native/ios/Comm/TemporaryMessageStorage/EncryptedFileUtils.mm
--- a/native/ios/Comm/TemporaryMessageStorage/EncryptedFileUtils.mm
+++ b/native/ios/Comm/TemporaryMessageStorage/EncryptedFileUtils.mm
@@ -12,6 +12,63 @@
@end
@implementation EncryptedFileUtils
++ (void)writeData:(NSString *)data
+ toFileAtPath:(NSString *)path
+ error:(NSError **)err {
+ NSData *binary = [EncryptedFileUtils _encryptData:data error:err];
+ if (!binary) {
+ return;
+ }
+ [binary writeToFile:path atomically:YES];
+}
+
++ (void)appendData:(NSString *)data
+ toFileAtPath:(NSString *)path
+ error:(NSError **)err {
+ NSData *binary = [EncryptedFileUtils _encryptData:data error:err];
+ if (!binary) {
+ return;
+ }
+ NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
+ @try {
+ [fileHandle seekToEndOfFile];
+ [fileHandle writeData:[encryptedDataSeparator
+ dataUsingEncoding:NSUTF8StringEncoding]];
+ [fileHandle writeData:binary];
+ [fileHandle closeFile];
+ } @catch (NSException *ex) {
+ *err = [NSError errorWithDomain:@"app.comm"
+ code:NSFileWriteUnknownError
+ userInfo:@{
+ NSLocalizedDescriptionKey : ex.reason,
+ }];
+ }
+}
+
++ (NSArray<NSString *> *)readFromFileAtPath:(NSString *)path
+ error:(NSError **)err {
+ NSString *fileContent =
+ [NSString stringWithContentsOfFile:path
+ encoding:NSUTF8StringEncoding
+ error:err];
+ if (!fileContent) {
+ return nil;
+ }
+ NSMutableArray<NSString *> *decryptedDataItems =
+ [[NSMutableArray alloc] init];
+ NSMutableArray<NSString *> *encryptedDataItems = [[fileContent
+ componentsSeparatedByString:encryptedDataSeparator] mutableCopy];
+ [encryptedDataItems removeObject:@""];
+ for (NSString *encryptedDataItem in encryptedDataItems) {
+ NSString *decryptedDataItem =
+ [EncryptedFileUtils _decryptData:encryptedDataItem error:nil];
+ if (decryptedDataItem) {
+ [decryptedDataItems addObject:decryptedDataItem];
+ }
+ }
+ return decryptedDataItems;
+}
+
+ (NSData *)_encryptData:(NSString *)data error:(NSError **)error {
NSData *encryptedData = [EncryptedFileUtils
_runCryptor:[data dataUsingEncoding:NSUTF8StringEncoding]
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jan 20, 4:27 AM (16 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5959409
Default Alt Text
D4385.1768883261.diff (2 KB)
Attached To
Mode
D4385: Implement elementary file operations with encryption-decryption layer
Attached
Detach File
Event Timeline
Log In to Comment