SecDbBackupBag.m   [plain text]

// This file was automatically generated by protocompiler
// DO NOT EDIT!
// Compiled from SecDbBackupRecoverySet.proto

#import "SecDbBackupBag.h"
#import <ProtocolBuffer/PBConstants.h>
#import <ProtocolBuffer/PBHashUtil.h>
#import <ProtocolBuffer/PBDataReader.h>

#import "SecDbBackupBagIdentity.h"

#if !__has_feature(objc_arc)
# error This generated file depends on ARC but it is not enabled; turn on ARC, or use 'objc_use_arc' option to generate non-ARC code.
#endif

@implementation SecDbBackupBag

- (BOOL)hasBagIdentity
{
return _bagIdentity != nil;
}
@synthesize bagIdentity = _bagIdentity;
- (BOOL)hasKeybag
{
return _keybag != nil;
}
@synthesize keybag = _keybag;

- (NSString *)description
{
return [NSString stringWithFormat:@"%@ %@", [super description], [self dictionaryRepresentation]];
}

- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
if (self->_bagIdentity)
{
[dict setObject:[_bagIdentity dictionaryRepresentation] forKey:@"bagIdentity"];
}
if (self->_keybag)
{
[dict setObject:self->_keybag forKey:@"keybag"];
}
return dict;
}

BOOL SecDbBackupBagReadFrom(__unsafe_unretained SecDbBackupBag *self, __unsafe_unretained PBDataReader *reader) {
while (PBReaderHasMoreData(reader)) {
uint32_t tag = 0;
uint8_t aType = 0;

PBReaderReadTag32AndType(reader, &tag, &aType);

if (PBReaderHasError(reader))
break;

if (aType == TYPE_END_GROUP) {
break;
}

switch (tag) {

case 1 /* bagIdentity */:
{
SecDbBackupBagIdentity *new_bagIdentity = [[SecDbBackupBagIdentity alloc] init];
self->_bagIdentity = new_bagIdentity;
PBDataReaderMark mark_bagIdentity;
BOOL markError = !PBReaderPlaceMark(reader, &mark_bagIdentity);
if (markError)
{
return NO;
}
BOOL inError = !SecDbBackupBagIdentityReadFrom(new_bagIdentity, reader);
if (inError)
{
return NO;
}
PBReaderRecallMark(reader, &mark_bagIdentity);
}
break;
case 2 /* keybag */:
{
NSData *new_keybag = PBReaderReadData(reader);
self->_keybag = new_keybag;
}
break;
default:
if (!PBReaderSkipValueWithTag(reader, tag, aType))
return NO;
break;
}
}
return !PBReaderHasError(reader);
}

- (BOOL)readFrom:(PBDataReader *)reader
{
return SecDbBackupBagReadFrom(self, reader);
}
- (void)writeTo:(PBDataWriter *)writer
{
/* bagIdentity */
{
if (self->_bagIdentity != nil)
{
PBDataWriterWriteSubmessage(writer, self->_bagIdentity, 1);
}
}
/* keybag */
{
if (self->_keybag)
{
PBDataWriterWriteDataField(writer, self->_keybag, 2);
}
}
}

- (void)copyTo:(SecDbBackupBag *)other
{
if (_bagIdentity)
{
other.bagIdentity = _bagIdentity;
}
if (_keybag)
{
other.keybag = _keybag;
}
}

- (id)copyWithZone:(NSZone *)zone
{
SecDbBackupBag *copy = [[[self class] allocWithZone:zone] init];
copy->_bagIdentity = [_bagIdentity copyWithZone:zone];
copy->_keybag = [_keybag copyWithZone:zone];
return copy;
}

- (BOOL)isEqual:(id)object
{
SecDbBackupBag *other = (SecDbBackupBag *)object;
return [other isMemberOfClass:[self class]]
&&
((!self->_bagIdentity && !other->_bagIdentity) || [self->_bagIdentity isEqual:other->_bagIdentity])
&&
((!self->_keybag && !other->_keybag) || [self->_keybag isEqual:other->_keybag])
;
}

- (NSUInteger)hash
{
return 0
^
[self->_bagIdentity hash]
^
[self->_keybag hash]
;
}

- (void)mergeFrom:(SecDbBackupBag *)other
{
if (self->_bagIdentity && other->_bagIdentity)
{
[self->_bagIdentity mergeFrom:other->_bagIdentity];
}
else if (!self->_bagIdentity && other->_bagIdentity)
{
[self setBagIdentity:other->_bagIdentity];
}
if (other->_keybag)
{
[self setKeybag:other->_keybag];
}
}

@end