forked from arqbackup/arq_restore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlobKeyIO.m
54 lines (50 loc) · 1.9 KB
/
BlobKeyIO.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// BlobKeyIO.m
//
// Created by Stefan Reitshamer on 9/14/12.
//
//
#import "BlobKeyIO.h"
#import "BooleanIO.h"
#import "StringIO.h"
#import "IntegerIO.h"
#import "StorageType.h"
#import "BlobKey.h"
#import "DateIO.h"
@implementation BlobKeyIO
+ (void)write:(BlobKey *)theBlobKey to:(NSMutableData *)data {
[StringIO write:[theBlobKey sha1] to:data];
[BooleanIO write:[theBlobKey stretchEncryptionKey] to:data];
[IntegerIO writeUInt32:(uint32_t)[theBlobKey storageType] to:data];
[StringIO write:[theBlobKey archiveId] to:data];
[IntegerIO writeUInt64:[theBlobKey archiveSize] to:data];
[DateIO write:[theBlobKey archiveUploadedDate] to:data];
}
+ (BOOL)read:(BlobKey **)theBlobKey from:(BufferedInputStream *)is treeVersion:(int)theTreeVersion compressed:(BOOL)isCompressed error:(NSError **)error {
NSString *dataSHA1;
BOOL stretchEncryptionKey = NO;
StorageType storageType = StorageTypeS3;
NSString *archiveId = nil;
uint64_t archiveSize = 0;
NSDate *archiveUploadedDate = nil;
if (![StringIO read:&dataSHA1 from:is error:error]) {
[self release];
return NO;
}
if (theTreeVersion >= 14 && ![BooleanIO read:&stretchEncryptionKey from:is error:error]) {
[self release];
return NO;
}
if (theTreeVersion >= 17) {
if (![IntegerIO readUInt32:&storageType from:is error:error]
|| ![StringIO read:&archiveId from:is error:error]
|| ![IntegerIO readUInt64:&archiveSize from:is error:error]
|| ![DateIO read:&archiveUploadedDate from:is error:error]) {
[self release];
return NO;
}
}
*theBlobKey = [[[BlobKey alloc] initWithStorageType:storageType archiveId:archiveId archiveSize:archiveSize archiveUploadedDate:archiveUploadedDate sha1:dataSHA1 stretchEncryptionKey:stretchEncryptionKey compressed:isCompressed] autorelease];
return YES;
}
@end