Page MenuHomePhabricator

D4385.diff
No OneTemporary

D4385.diff

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

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)

Event Timeline