Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3359790
D4385.id13909.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.id13909.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,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
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 10:53 AM (8 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2579402
Default Alt Text
D4385.id13909.diff (2 KB)
Attached To
Mode
D4385: Implement elementary file operations with encryption-decryption layer
Attached
Detach File
Event Timeline
Log In to Comment