Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3363295
D4385.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D4385.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, Nov 26, 1:31 AM (22 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2581893
Default Alt Text
D4385.diff (2 KB)
Attached To
Mode
D4385: Implement elementary file operations with encryption-decryption layer
Attached
Detach File
Event Timeline
Log In to Comment