forked from arqbackup/arq_restore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlobKey.m
118 lines (109 loc) · 3.86 KB
/
BlobKey.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// BlobKey.m
//
// Created by Stefan Reitshamer on 6/27/11.
// Copyright 2011 Haystack Software. All rights reserved.
//
#import "BlobKey.h"
#import "BufferedInputStream.h"
#import "StringIO.h"
#import "BooleanIO.h"
#import "IntegerIO.h"
#import "NSObject_extra.h"
@implementation BlobKey
- (id)initWithSHA1:(NSString *)theSHA1 archiveId:(NSString *)theArchiveId archiveSize:(uint64_t)theArchiveSize archiveUploadedDate:(NSDate *)theArchiveUploadedDate compressed:(BOOL)isCompressed {
if (self = [super init]) {
storageType = StorageTypeGlacier;
sha1 = [theSHA1 retain];
archiveId = [theArchiveId retain];
archiveSize = theArchiveSize;
archiveUploadedDate = [theArchiveUploadedDate retain];
compressed = isCompressed;
}
return self;
}
- (id)initWithSHA1:(NSString *)theSHA1 storageType:(StorageType)theStorageType stretchEncryptionKey:(BOOL)isStretchedKey compressed:(BOOL)isCompressed {
if (self = [super init]) {
storageType = theStorageType;
sha1 = [theSHA1 retain];
stretchEncryptionKey = isStretchedKey;
compressed = isCompressed;
}
return self;
}
- (id)initWithStorageType:(StorageType)theStorageType archiveId:(NSString *)theArchiveId archiveSize:(uint64_t)theArchiveSize archiveUploadedDate:(NSDate *)theArchiveUploadedDate sha1:(NSString *)theSHA1 stretchEncryptionKey:(BOOL)isStretchedKey compressed:(BOOL)isCompressed {
if (self = [super init]) {
storageType = theStorageType;
archiveId = [theArchiveId retain];
archiveSize = theArchiveSize;
archiveUploadedDate = [theArchiveUploadedDate retain];
sha1 = [theSHA1 retain];
stretchEncryptionKey = isStretchedKey;
compressed = isCompressed;
}
return self;
}
- (void)dealloc {
[archiveId release];
[archiveUploadedDate release];
[sha1 release];
[super dealloc];
}
- (StorageType)storageType {
return storageType;
}
- (NSString *)archiveId {
return archiveId;
}
- (uint64_t)archiveSize {
return archiveSize;
}
- (NSDate *)archiveUploadedDate {
return archiveUploadedDate;
}
- (NSString *)sha1 {
return sha1;
}
- (BOOL)stretchEncryptionKey {
return stretchEncryptionKey;
}
- (BOOL)compressed {
return compressed;
}
- (BOOL)isEqualToBlobKey:(BlobKey *)other {
if (![[other sha1] isEqualToString:sha1]) {
return NO;
}
if (stretchEncryptionKey != [other stretchEncryptionKey]) {
return NO;
}
return YES;
}
#pragma mark NSCopying
- (id)copyWithZone:(NSZone *)zone {
return [[BlobKey alloc] initWithStorageType:storageType archiveId:archiveId archiveSize:archiveSize archiveUploadedDate:archiveUploadedDate sha1:sha1 stretchEncryptionKey:stretchEncryptionKey compressed:compressed];
}
#pragma mark NSObject
- (NSString *)description {
if (storageType == StorageTypeS3) {
return [NSString stringWithFormat:@"<BlobKey sha1=%@,stretchedkey=%@,compressed=%@>", sha1, (stretchEncryptionKey ? @"YES" : @"NO"), (compressed ? @"YES" : @"NO")];
}
return [NSString stringWithFormat:@"<BlobKey archiveId=%@,archiveUploadedDate=%@,stretchedkey=%@,compressed=%@>", archiveId, archiveUploadedDate, (stretchEncryptionKey ? @"YES" : @"NO"), (compressed ? @"YES" : @"NO")];
}
- (BOOL)isEqual:(id)anObject {
if (![anObject isKindOfClass:[BlobKey class]]) {
return NO;
}
BlobKey *other = (BlobKey *)anObject;
return [NSObject equalObjects:sha1 and:[other sha1]]
&& stretchEncryptionKey == [other stretchEncryptionKey]
&& storageType == [other storageType]
&& [NSObject equalObjects:archiveId and:[other archiveId]]
&& archiveSize == [other archiveSize]
&& [NSObject equalObjects:archiveUploadedDate and:[other archiveUploadedDate]]
&& compressed == [other compressed];
}
- (NSUInteger)hash {
return [sha1 hash] + (stretchEncryptionKey ? 1 : 0) + (compressed ? 1 : 0);
}
@end