2018-03-16 15:55:16 +01:00
|
|
|
//
|
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
@interface OWSBackupEncryptedItem : NSObject
|
|
|
|
|
|
|
|
@property (nonatomic) NSString *filePath;
|
|
|
|
|
|
|
|
@property (nonatomic) NSData *encryptionKey;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2018-03-16 18:04:01 +01:00
|
|
|
@interface OWSBackupIO : NSObject
|
2018-03-16 15:55:16 +01:00
|
|
|
|
|
|
|
- (instancetype)init NS_UNAVAILABLE;
|
|
|
|
|
|
|
|
- (instancetype)initWithJobTempDirPath:(NSString *)jobTempDirPath;
|
|
|
|
|
2018-03-22 19:05:12 +01:00
|
|
|
- (NSString *)generateTempFilePath;
|
|
|
|
|
2018-03-20 22:22:19 +01:00
|
|
|
- (nullable NSString *)createTempFile;
|
|
|
|
|
2018-03-16 15:55:16 +01:00
|
|
|
#pragma mark - Encrypt
|
|
|
|
|
|
|
|
- (nullable OWSBackupEncryptedItem *)encryptFileAsTempFile:(NSString *)srcFilePath;
|
|
|
|
|
|
|
|
- (nullable OWSBackupEncryptedItem *)encryptFileAsTempFile:(NSString *)srcFilePath
|
|
|
|
encryptionKey:(NSData *)encryptionKey;
|
|
|
|
|
|
|
|
- (nullable OWSBackupEncryptedItem *)encryptDataAsTempFile:(NSData *)srcData;
|
|
|
|
|
|
|
|
- (nullable OWSBackupEncryptedItem *)encryptDataAsTempFile:(NSData *)srcData encryptionKey:(NSData *)encryptionKey;
|
|
|
|
|
|
|
|
#pragma mark - Decrypt
|
|
|
|
|
2018-03-16 17:55:20 +01:00
|
|
|
- (BOOL)decryptFileAsFile:(NSString *)srcFilePath
|
|
|
|
dstFilePath:(NSString *)dstFilePath
|
|
|
|
encryptionKey:(NSData *)encryptionKey;
|
|
|
|
|
|
|
|
- (nullable NSData *)decryptFileAsData:(NSString *)srcFilePath encryptionKey:(NSData *)encryptionKey;
|
2018-03-16 15:55:16 +01:00
|
|
|
|
|
|
|
- (nullable NSData *)decryptDataAsData:(NSData *)srcData encryptionKey:(NSData *)encryptionKey;
|
|
|
|
|
2018-03-16 17:55:20 +01:00
|
|
|
#pragma mark - Compression
|
|
|
|
|
|
|
|
- (nullable NSData *)compressData:(NSData *)srcData;
|
|
|
|
|
2018-03-17 14:03:52 +01:00
|
|
|
// I'm using the (new in iOS 9) compressionlib. One of its weaknesses is that it
|
|
|
|
// requires you to pre-allocate output buffers during compression and decompression.
|
|
|
|
// During decompression this is particularly tricky since there's no way to safely
|
|
|
|
// predict how large the output will be based on the input. So, we store the
|
|
|
|
// uncompressed size for compressed backup items.
|
2018-03-16 17:55:20 +01:00
|
|
|
- (nullable NSData *)decompressData:(NSData *)srcData uncompressedDataLength:(NSUInteger)uncompressedDataLength;
|
|
|
|
|
2018-03-16 15:55:16 +01:00
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|