Page MenuHomePhabricator

D4385.id14164.diff
No OneTemporary

D4385.id14164.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,52 @@
@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;
+ }
+ return [EncryptedFileUtils _decryptBinary:binaryFileContent error:err];
+}
+
++ (void)clearContentAtPath:(NSString *)path error:(NSError **)err {
+ [@"" writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:err];
+}
+
+ (NSData *)_encryptData:(NSString *)data error:(NSError **)error {
NSUInteger paddingLength =
data.length + kCCBlockSizeAES128 - data.length % kCCBlockSizeAES128;

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 29, 6:27 PM (21 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2597783
Default Alt Text
D4385.id14164.diff (1 KB)

Event Timeline