Page MenuHomePhabricator

D4385.id14066.diff
No OneTemporary

D4385.id14066.diff

diff --git a/native/ios/Comm/TemporalMessageStorage/EncryptedFileUtils.mm b/native/ios/Comm/TemporalMessageStorage/EncryptedFileUtils.mm
--- a/native/ios/Comm/TemporalMessageStorage/EncryptedFileUtils.mm
+++ b/native/ios/Comm/TemporalMessageStorage/EncryptedFileUtils.mm
@@ -12,6 +12,54 @@
@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:binary];
+ [fileHandle closeFile];
+ } @catch (NSException *ex) {
+ *err = [NSError errorWithDomain:@"app.comm"
+ code:NSFileWriteUnknownError
+ userInfo:@{
+ NSLocalizedDescriptionKey : ex.reason,
+ }];
+ }
+}
+
++ (NSString *)readFromFileAtPath:(NSString *)path error:(NSError **)err {
+ NSData *binaryFileContent =
+ [NSData dataWithContentsOfFile:path
+ options:NSDataReadingMappedIfSafe
+ error:err];
+ if (!binaryFileContent) {
+ return nil;
+ }
+ NSString *fileContent = [EncryptedFileUtils _decryptBinary:binaryFileContent
+ error:err];
+ return fileContent;
+}
+
++ (void)clearContentAtPath:(NSString *)path error:(NSError **)err {
+ [@"" writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:err];
+}
+
+ (NSData *)_encryptData:(NSString *)data error:(NSError **)error {
return [EncryptedFileUtils
_runCryptor:[data dataUsingEncoding:NSUTF8StringEncoding]
@@ -71,4 +119,4 @@
return resultBinary;
}
-@end
\ No newline at end of file
+@end

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 28, 7:11 AM (3 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2724542
Default Alt Text
D4385.id14066.diff (2 KB)

Event Timeline