Entropy is now calculated for Custom Alphabets in Password Generator View

Custom String in Password Generator View are now filtered to only include unique characters
This commit is contained in:
michael starke
2013-08-04 03:41:09 +02:00
parent 9d22494bf4
commit 450bc3d4dd
20 changed files with 902 additions and 279 deletions

View File

@@ -7,8 +7,9 @@
//
#import "KPKLegacyLoadingTest.h"
#import "KPKTreeCryptor.h"
#import "KPKTree+Serializing.h"
#import "KPKPassword.h"
#import "KPKErrors.h"
@implementation KPKLegacyLoadingTest
@@ -24,10 +25,19 @@
_password = nil;
}
- (void)testLoading {
KPKTreeCryptor *cryptor = [KPKTreeCryptor treeCryptorWithData:_data password:_password];
KPKTree *tree = [cryptor decryptTree:NULL];
- (void)testValidFile {
KPKTree *tree = [[KPKTree alloc] initWithData:_data password:_password error:NULL];
STAssertNotNil(tree, @"Loading should result in a tree object");
}
- (void)testInvalidFile {
NSError *error;
uint8 bytes[] = {0x00,0x11,0x22,0x33,0x44};
NSData *data = [NSData dataWithBytes:bytes length:5];
KPKTree *tree = [[KPKTree alloc] initWithData:data password:nil error:&error];
STAssertNil(tree, @"Tree should be nil with invalid data");
STAssertNotNil(error, @"Error object should have been created");
STAssertTrue(KPKErrorUnknownFileFormat == [error code], @"Error should be Unknown file format");
}
@end

View File

@@ -0,0 +1,17 @@
//
// KPKLegacyWritingTest.h
// MacPass
//
// Created by Michael Starke on 02.08.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import <SenTestingKit/SenTestingKit.h>
@class KPKPassword;
@interface KPKLegacyWritingTest : SenTestCase {
NSData *_data;
KPKPassword *_password;
}
@end

View File

@@ -0,0 +1,36 @@
//
// KPKLegacyWritingTest.m
// MacPass
//
// Created by Michael Starke on 02.08.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "KPKLegacyWritingTest.h"
#import "KPKPassword.h"
#import "KPKTree+Serializing.h"
@implementation KPKLegacyWritingTest
- (void)setUp {
NSBundle *myBundle = [NSBundle bundleForClass:[self class]];
NSURL *url = [myBundle URLForResource:@"Test_Password_1234" withExtension:@"kdb"];
_data = [NSData dataWithContentsOfURL:url];
_password = [[KPKPassword alloc] initWithPassword:@"1234" key:nil];
}
- (void)tearDown {
_data = nil;
_password = nil;
}
- (void)testWriting {
NSError *error = nil;
KPKTree *tree = [[KPKTree alloc] initWithData:_data password:_password error:&error];
NSData *data = [tree encryptWithPassword:_password forVersion:KPKVersion1 error:&error];
}
@end

View File

@@ -0,0 +1,13 @@
//
// KPKTestXmlParsing.h
// MacPass
//
// Created by Michael Starke on 03.08.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import <SenTestingKit/SenTestingKit.h>
@interface KPKTestXmlParsing : SenTestCase
@end

View File

@@ -0,0 +1,47 @@
//
// KPKTestXmlParsing.m
// MacPass
//
// Created by Michael Starke on 03.08.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "KPKTestXmlParsing.h"
#import "KPKXmlTreeReader.h"
#import "KPKErrors.h"
#import "DDXMLDocument.h"
@implementation KPKTestXmlParsing
- (void)testEmptyXmlFile {
DDXMLDocument *document = [[DDXMLDocument alloc] initWithXMLString:@"" options:0 error:NULL];
KPKXmlTreeReader *reader = [[KPKXmlTreeReader alloc] initWithData:[document XMLData] headerReader:nil];
NSError *error;
KPKTree *tree = [reader tree:&error];
STAssertNil(tree, @"No Tree form emptry data");
STAssertNotNil(error, @"Error Object should be provided");
STAssertTrue([error code] == KPKErrorNoData, @"Error Code should be No Data");
}
- (void)testNoNodeXmlFile {
DDXMLDocument *document = [[DDXMLDocument alloc] initWithXMLString:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>" options:0 error:NULL];
KPKXmlTreeReader *reader = [[KPKXmlTreeReader alloc] initWithData:[document XMLData] headerReader:nil];
NSError *error;
KPKTree *tree = [reader tree:&error];
STAssertNil(tree, @"No Tree form emptry data");
STAssertNotNil(error, @"Error Object should be provided");
STAssertTrue([error code] == KPKErrorXMLKeePassFileElementMissing, @"Error Code should be KeePassFile root missing");
}
- (void)testNoRoodXmlFil {
DDXMLDocument *document = [[DDXMLDocument alloc] initWithXMLString:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><KeePassFile><Root></Root></KeePassFile>" options:0 error:NULL];
KPKXmlTreeReader *reader = [[KPKXmlTreeReader alloc] initWithData:[document XMLData] headerReader:nil];
NSError *error;
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");
}
@end

View File

@@ -7,10 +7,9 @@
//
#import "KPKXmlLoadingTest.h"
#import "KPKTreeCryptor.h"
#import "KPKPassword.h"
#import "KPKTree.h"
#import "KPKTree+Serializing.h"
#import "KPKEntry.h"
#import "KPKGroup.h"
@@ -29,12 +28,12 @@
}
- (void)testLoading {
KPKTreeCryptor *cryptor = [KPKTreeCryptor treeCryptorWithData:_data password:_password];
KPKTree *tree = [cryptor decryptTree:NULL];
//STAssertNotNil(tree, @"Loading should result in a tree object");
NSError *error;
KPKTree *tree = [[KPKTree alloc] initWithData:_data password:_password error:&error];
STAssertNotNil(tree, @"Loading should result in a tree object");
//STAssertTrue([tree.root.groups count] == 0, @"Tree contains just root group");
//STAssertTrue([tree.root.entries count] == 1, @"Tree has only one entry");
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];