Using KPKDatabaseType instead of KPKVersion.

This commit is contained in:
michael starke
2016-09-04 16:50:30 +02:00
parent 024e9cf41a
commit f0d4b2f835
12 changed files with 46 additions and 34 deletions

View File

@@ -1,3 +1,3 @@
github "sparkle-project/Sparkle" ~> 1.13.1
github "mstarke/KeePassKit" "d66c888b299358481da2ba2672ec7c644cce56ec"
github "mstarke/KeePassKit" "5c98755e9954549a74f421d90af8cd6b5c0e01cc"
github "mstarke/HNHUi" ~> 1.1

View File

@@ -1,3 +1,3 @@
github "mstarke/HNHUi" "1.1"
github "mstarke/KeePassKit" "d66c888b299358481da2ba2672ec7c644cce56ec"
github "mstarke/KeePassKit" "5c98755e9954549a74f421d90af8cd6b5c0e01cc"
github "sparkle-project/Sparkle" "1.14.0"

View File

@@ -17,16 +17,16 @@
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
typeToUTI = @{
@(KPKLegacyVersion) : MPLegacyDocumentUTI,
@(KPKXmlVersion) : MPXMLDocumentUTI
@(KPKDatabaseTypeBinary) : MPLegacyDocumentUTI,
@(KPKDatabaseTypeXml) : MPXMLDocumentUTI
};
});
return typeToUTI;
}
- (NSString *)typeForData:(NSData *)data {
KPKVersion version = [self databaseVersionForData:data];
return [self _typeToUTIdictionary][@(version)];
KPKFileInfo fileInfo = [self fileInfoForData:data];
return [self _typeToUTIdictionary][@(fileInfo.type)];
}
- (NSString *)typeForContentOfURL:(NSURL *)url {

View File

@@ -37,6 +37,9 @@
return _tokens;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (NSString *)nibName {
return @"AutotypeBuilderView";
@@ -46,6 +49,15 @@
[super viewDidLoad];
self.tokenField.editable = NO;
self.tokenField.objectValue = self.tokens;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_textViewDidChangeSelection:) name:NSTextViewDidChangeSelectionNotification object:nil];
}
- (void)_textViewDidChangeSelection:(NSNotification *)notification {
NSTextView *tv = [self.tokenField.cell fieldEditorForView:self.tokenField];
if(tv) {
NSArray *selectionRanges = tv.selectedRanges;
}
}
@end

View File

@@ -78,7 +78,7 @@ FOUNDATION_EXPORT NSString *const MPDocumentGroupKey;
@property (nonatomic, strong, readonly) KPKCompositeKey *compositeKey;
@property (assign, readonly, getter = isReadOnly) BOOL readOnly;
@property (nonatomic, readonly, assign) KPKVersion versionForFileType;
@property (nonatomic, readonly, assign) KPKDatabaseType versionForFileType;
/*
State (active group/entry)
@@ -96,8 +96,8 @@ FOUNDATION_EXPORT NSString *const MPDocumentGroupKey;
@property (nonatomic, copy) MPEntrySearchContext *searchContext;
@property (nonatomic, strong, readonly) NSArray *searchResult;
+ (KPKVersion)versionForFileType:(NSString *)fileType;
+ (NSString *)fileTypeForVersion:(KPKVersion)version;
+ (KPKDatabaseType)versionForFileType:(NSString *)fileType;
+ (NSString *)fileTypeForVersion:(KPKDatabaseType)version;
#pragma mark Lock/Decrypt
- (IBAction)lockDatabase:(id)sender;

View File

@@ -89,22 +89,22 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
return [NSSet setWithObject:NSStringFromSelector(@selector(tree))];
}
+ (KPKVersion)versionForFileType:(NSString *)fileType {
+ (KPKDatabaseType)versionForFileType:(NSString *)fileType {
if( NSOrderedSame == [fileType compare:MPLegacyDocumentUTI options:NSCaseInsensitiveSearch]) {
return KPKLegacyVersion;
return KPKDatabaseTypeBinary;
}
if( NSOrderedSame == [fileType compare:MPXMLDocumentUTI options:NSCaseInsensitiveSearch]) {
return KPKXmlVersion;
return KPKDatabaseTypeXml;
}
return KPKUnknownVersion;
return KPKDatabaseTypeUnknown;
}
+ (NSString *)fileTypeForVersion:(KPKVersion)version {
+ (NSString *)fileTypeForVersion:(KPKDatabaseType)version {
switch(version) {
case KPKLegacyVersion:
case KPKDatabaseTypeBinary:
return MPLegacyDocumentUTI;
case KPKXmlVersion:
case KPKDatabaseTypeXml:
return MPXMLDocumentUTI;
default:
@@ -182,8 +182,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
return nil; // Saving without a password/key is not possible
}
NSString *fileType = self.fileTypeFromLastRunSavePanel;
KPKVersion version = [self.class versionForFileType:fileType];
if(version == KPKUnknownVersion) {
KPKDatabaseType version = [self.class versionForFileType:fileType];
if(version == KPKDatabaseTypeUnknown) {
if(outError != NULL) {
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: NSLocalizedString(@"UNKNOWN_FILE_VERSION", "") };
*outError = [NSError errorWithDomain:MPErrorDomain code:0 userInfo:userInfo];
@@ -325,7 +325,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
NSError *error;
/* FIXME: User feedback is ignored */
[self saveDocument:sender];
self.encryptedData = [self.tree encryptWithPassword:self.compositeKey forVersion:KPKXmlVersion error:&error];
self.encryptedData = [self.tree encryptWithPassword:self.compositeKey forVersion:KPKDatabaseTypeXml error:&error];
self.tree = nil;
[self.undoManager removeAllActions];
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidLockDatabaseNotification object:self];
@@ -389,8 +389,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
}
#pragma mark Properties
- (KPKVersion)versionForFileType {
return [[self class] versionForFileType:[self fileType]];
- (KPKDatabaseType)versionForFileType {
return [[self class] versionForFileType:self.fileType];
}
- (BOOL)encrypted {

View File

@@ -193,7 +193,7 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
NSString *fileType = document.fileType;
/* we did open as legacy */
if([fileType isEqualToString:MPLegacyDocumentUTI]) {
if(document.tree.minimumVersion != KPKLegacyVersion) {
if(document.tree.minimumType != KPKDatabaseTypeBinary) {
NSAlert *alert = [[NSAlert alloc] init];
alert.alertStyle = NSWarningAlertStyle;
alert.messageText = NSLocalizedString(@"WARNING_ON_LOSSY_SAVE", "");

View File

@@ -117,7 +117,7 @@
- (IBAction)generateKey:(id)sender {
MPDocument *document = self.document;
NSData *data = [NSData generateKeyfiledataForVersion:document.tree.minimumVersion];
NSData *data = [NSData generateKeyfiledataForVersion:document.tree.minimumType];
if(data) {
NSSavePanel *savePanel = [NSSavePanel savePanel];
savePanel.allowedFileTypes = @[@"key", @"xml"];

View File

@@ -15,7 +15,7 @@
@property (nonatomic, weak) NSSavePanel *savePanel;
@property (nonatomic, weak) MPDocument *document;
@property (nonatomic, assign, readonly) KPKVersion selectedVersion;
@property (nonatomic, assign, readonly) KPKDatabaseType selectedVersion;
@property (nonatomic, weak) IBOutlet NSPopUpButton *fileTypePopupButton;
@property (nonatomic, weak) IBOutlet NSTextField *infoTextField;

View File

@@ -13,7 +13,7 @@
#import "KeePassKit/KeePassKit.h"
@interface MPSavePanelAccessoryViewController ()
@property (readwrite, assign) KPKVersion selectedVersion;
@property (readwrite, assign) KPKDatabaseType selectedVersion;
@end
@implementation MPSavePanelAccessoryViewController
@@ -42,10 +42,10 @@
- (IBAction)setFileType:(id)sender {
NSString *uti = self.fileTypePopupButton.selectedItem.representedObject;
if([uti isEqualToString:MPLegacyDocumentUTI]) {
self.selectedVersion = KPKLegacyVersion;
self.selectedVersion = KPKDatabaseTypeBinary;
}
else if([uti isEqualToString:MPXMLDocumentUTI]) {
self.selectedVersion = KPKXmlVersion;
self.selectedVersion = KPKDatabaseTypeXml;
}
NSAssert(uti != nil, @"UTI cannot be nil");
[self _updateNote];
@@ -66,13 +66,13 @@
NSView *view = self.view;
NSAssert(view != nil, @"View has to be loaded at this point");
switch(self.document.versionForFileType) {
case KPKLegacyVersion:
case KPKDatabaseTypeBinary:
[self.fileTypePopupButton selectItemAtIndex:1];
break;
case KPKXmlVersion:
case KPKDatabaseTypeXml:
[self.fileTypePopupButton selectItemAtIndex:0];
break;
case KPKUnknownVersion:
default:
NSAssert(NO, @"Minimum Version should always be valid");
break;
}
@@ -82,8 +82,8 @@
- (void)_updateNote {
NSString *uti = [[self.fileTypePopupButton selectedItem] representedObject];
BOOL showInfoText = (self.document.tree.minimumVersion == KPKXmlVersion && [uti isEqualToString:MPLegacyDocumentUTI]);
[self.infoTextField setHidden:!showInfoText];
BOOL showInfoText = (self.document.tree.minimumType == KPKDatabaseTypeXml && [uti isEqualToString:MPLegacyDocumentUTI]);
self.infoTextField.hidden = !showInfoText;
}
@end

View File

@@ -28,7 +28,7 @@
XCTAssertTrue(document.encrypted, @"Loaded but unencrypted should be not decrypted");
XCTAssertTrue([document unlockWithPassword:@"1234" keyFileURL:nil error:&error], @"Should decrypt with password");
XCTAssertNil(error, @"No Error should occur on unlocking with correct password");
XCTAssertTrue((document.tree.minimumVersion = KPKLegacyVersion), @"Minimal Version should not increase with KDB File loaded");
XCTAssertTrue((document.tree.minimumType = KPKDatabaseTypeBinary), @"Minimal Version should not increase with KDB File loaded");
//STAssertTrue([document.fileType isEqualToString:[MPDocument fileTypeForVersion:KPKLegacyVersion]], @"File type needs to match opened file");
}

View File

@@ -28,7 +28,7 @@
- (void)testCreateUntitledDocument {
MPDocument *document = [[MPDocument alloc] initWithType:@"" error:nil];
XCTAssertNotNil(document, @"Document should be created");
XCTAssertTrue(document.tree.minimumVersion == KPKLegacyVersion, @"Tree should be Legacy Version in default case");
XCTAssertTrue(document.tree.minimumType == KPKDatabaseTypeBinary, @"Tree should be Legacy Version in default case");
XCTAssertFalse(document.encrypted, @"Document cannot be encrypted at creation");
XCTAssertFalse(document.compositeKey.hasPasswordOrKeyFile, @"Document has no Password/Keyfile and thus is not secured");