diff --git a/Cartfile b/Cartfile index 94656ccd..1388922b 100644 --- a/Cartfile +++ b/Cartfile @@ -1,3 +1,3 @@ github "sparkle-project/Sparkle" ~> 1.13.1 -github "mstarke/KeePassKit" "d66c888b299358481da2ba2672ec7c644cce56ec" +github "mstarke/KeePassKit" "5c98755e9954549a74f421d90af8cd6b5c0e01cc" github "mstarke/HNHUi" ~> 1.1 diff --git a/Cartfile.resolved b/Cartfile.resolved index 5db8a76d..01370473 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,3 @@ github "mstarke/HNHUi" "1.1" -github "mstarke/KeePassKit" "d66c888b299358481da2ba2672ec7c644cce56ec" +github "mstarke/KeePassKit" "5c98755e9954549a74f421d90af8cd6b5c0e01cc" github "sparkle-project/Sparkle" "1.14.0" diff --git a/MacPass/KPKFormat+MPUTIDetection.m b/MacPass/KPKFormat+MPUTIDetection.m index c88c9405..3f4b605f 100644 --- a/MacPass/KPKFormat+MPUTIDetection.m +++ b/MacPass/KPKFormat+MPUTIDetection.m @@ -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 { diff --git a/MacPass/MPAutotypeBuilderViewController.m b/MacPass/MPAutotypeBuilderViewController.m index b00a6785..3116d821 100644 --- a/MacPass/MPAutotypeBuilderViewController.m +++ b/MacPass/MPAutotypeBuilderViewController.m @@ -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 diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index 72f8e59f..f7609b1a 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -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; diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 676c6380..623a8849 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -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 { diff --git a/MacPass/MPDocumentWindowController.m b/MacPass/MPDocumentWindowController.m index 4b58b6d2..e01892c9 100644 --- a/MacPass/MPDocumentWindowController.m +++ b/MacPass/MPDocumentWindowController.m @@ -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", ""); diff --git a/MacPass/MPPasswordEditWindowController.m b/MacPass/MPPasswordEditWindowController.m index f5344961..8d51f27c 100644 --- a/MacPass/MPPasswordEditWindowController.m +++ b/MacPass/MPPasswordEditWindowController.m @@ -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"]; diff --git a/MacPass/MPSavePanelAccessoryViewController.h b/MacPass/MPSavePanelAccessoryViewController.h index 0294d37f..5663e725 100644 --- a/MacPass/MPSavePanelAccessoryViewController.h +++ b/MacPass/MPSavePanelAccessoryViewController.h @@ -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; diff --git a/MacPass/MPSavePanelAccessoryViewController.m b/MacPass/MPSavePanelAccessoryViewController.m index bef78477..66d74965 100644 --- a/MacPass/MPSavePanelAccessoryViewController.m +++ b/MacPass/MPSavePanelAccessoryViewController.m @@ -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 diff --git a/MacPassTests/MPDatabaseLoading.m b/MacPassTests/MPDatabaseLoading.m index 3eba9cf1..dea66244 100644 --- a/MacPassTests/MPDatabaseLoading.m +++ b/MacPassTests/MPDatabaseLoading.m @@ -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"); } diff --git a/MacPassTests/MPTestDocument.m b/MacPassTests/MPTestDocument.m index eaf9378b..db290108 100644 --- a/MacPassTests/MPTestDocument.m +++ b/MacPassTests/MPTestDocument.m @@ -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");