Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3383941
D4385.id14164.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D4385.id14164.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D4385: Implement elementary file operations with encryption-decryption layer
Attached
Detach File
Event Timeline
Log In to Comment