mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 02:22:28 +00:00
Updated submodule
Added Test for Hashed data
This commit is contained in:
14
MacPassTests/KPKHashedDataTest.h
Normal file
14
MacPassTests/KPKHashedDataTest.h
Normal file
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// KPKHashedDataTest.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 08.08.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <SenTestingKit/SenTestingKit.h>
|
||||
|
||||
|
||||
@interface KPKHashedDataTest : SenTestCase
|
||||
|
||||
@end
|
||||
23
MacPassTests/KPKHashedDataTest.m
Normal file
23
MacPassTests/KPKHashedDataTest.m
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// KPKHashedDataTest.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 08.08.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKHashedDataTest.h"
|
||||
#import "NSData+HashedData.h"
|
||||
#import "NSData+Random.h"
|
||||
|
||||
@implementation KPKHashedDataTest
|
||||
|
||||
- (void)testHashedData {
|
||||
|
||||
NSData *data = [NSData dataWithRandomBytes:10000];
|
||||
NSData *hashedData = [data hashedDataWithBlockSize:512];
|
||||
NSData *unhashedData = [hashedData unhashedData];
|
||||
STAssertTrue([unhashedData isEqualToData:data], @"Data needs to be the same after hashing and unhashing");
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -29,7 +29,7 @@
|
||||
- (void)testWriting {
|
||||
NSError *error = nil;
|
||||
KPKTree *tree = [[KPKTree alloc] initWithData:_data password:_password error:&error];
|
||||
NSData *data = [tree encryptWithPassword:_password forVersion:KPKVersion1 error:&error];
|
||||
NSData *data = [tree encryptWithPassword:_password forVersion:KPKLegacyVersion error:&error];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,13 +35,14 @@
|
||||
}
|
||||
|
||||
- (void)testColorRefReading {
|
||||
uint32_t colorBytes = 0x000000ff;
|
||||
uint32_t swappedData = colorBytes;//CFSwapInt32(colorBytes);
|
||||
uint32_t colorBytes = 0x000000FF;
|
||||
uint32_t swappedData = colorBytes;
|
||||
NSData *colorData = [NSData dataWithBytesNoCopy:&swappedData length:sizeof(uint32_t) freeWhenDone:NO];
|
||||
NSColor *color = [NSColor colorWithData:colorData];
|
||||
STAssertEquals([color redComponent], 1.0, @"Red 100%");
|
||||
STAssertEquals([color blueComponent], 0.0, @"Blue 0%");
|
||||
STAssertEquals([color redComponent], 0.0, @"Red 100%");
|
||||
STAssertEquals([color greenComponent], 0.0, @"Green 0%");
|
||||
STAssertEquals([color blueComponent], 1.0, @"Blue 100%");
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
KPKTree *tree = [reader tree:&error];
|
||||
STAssertNil(tree, @"No Tree form emptry data");
|
||||
STAssertNotNil(error, @"Error Object should be provided");
|
||||
STAssertTrue([error code] == KPKErrorXMLRootElementMissing, @"Error Code should be KeePassFile root missing");
|
||||
STAssertTrue([error code] == KPKErrorXMLMetaElementMissing, @"Error Code should be KeePassFile root missing");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -34,18 +34,6 @@
|
||||
|
||||
STAssertTrue([tree.root.groups count] == 0, @"Tree contains just root group");
|
||||
STAssertTrue([tree.root.entries count] == 1, @"Tree has only one entry");
|
||||
|
||||
KPKEntry *entry = [tree.root.entries lastObject];
|
||||
NSMutableData *data = [[NSMutableData alloc] init];
|
||||
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
|
||||
[entry encodeWithCoder:archiver];
|
||||
[archiver finishEncoding];
|
||||
|
||||
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
|
||||
KPKEntry *newEntry = [[KPKEntry alloc] initWithCoder:unarchiver];
|
||||
[unarchiver finishDecoding];
|
||||
|
||||
STAssertTrue([entry.title isEqualToString:newEntry.title], @"Entries must have same attributes");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user