Files
MacPass/MacPassTests/KPKTestLegacyWriting.m
michael starke 214a192a4d Fixed typo
2013-08-21 00:45:44 +02:00

43 lines
1.5 KiB
Objective-C

//
// KPKLegacyWritingTest.m
// MacPass
//
// Created by Michael Starke on 02.08.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "KPKTestLegacyWriting.h"
#import "KPKPassword.h"
#import "KPKTree+Serializing.h"
@implementation KPKTestLegacyWriting
- (void)testWriting {
NSError __autoreleasing *error = nil;
NSURL *dbUrl = [self _urlForFile:@"CustomIcon_Password_1234" extension:@"kdbx"];
KPKPassword *password = [[KPKPassword alloc] initWithPassword:@"1234" key:nil];
KPKTree *tree = [[KPKTree alloc] initWithContentsOfUrl:dbUrl password:password error:&error];
STAssertNotNil(tree, @"Tree should be created");
error = nil;
NSData *data = [tree encryptWithPassword:password forVersion:KPKLegacyVersion error:&error];
STAssertNotNil(data, @"Serialized Data shoudl be created");
NSString *tempFile = [NSTemporaryDirectory() stringByAppendingString:@"CustomIcon_Password_1234.kdb"];
NSLog(@"Saved to %@", tempFile);
[data writeToFile:tempFile atomically:YES];
KPKTree *loadTree = [[KPKTree alloc] initWithData:data password:password error:&error];
STAssertNotNil(loadTree, @"Tree should be loadable from kdb file data");
}
- (NSData *)_dataForFile:(NSString *)name extension:(NSString *)extension {
NSURL *url = [self _urlForFile:name extension:extension];
return [NSData dataWithContentsOfURL:url];
}
- (NSURL *)_urlForFile:(NSString *)file extension:(NSString *)extension {
return [[NSBundle bundleForClass:[self class]] URLForResource:file withExtension:extension];
}
@end