Updated documentation

small refactorings on the key file settings
This commit is contained in:
michael starke
2013-11-18 00:12:35 +01:00
parent 9192504939
commit 12a29121e5
3 changed files with 36 additions and 7 deletions

View File

@@ -36,7 +36,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
@property (weak, readonly) KPKGroup *trash;
@property (weak, readonly) KPKGroup *templates;
@property (nonatomic, strong) KPKCompositeKey *compositeKey;
@property (nonatomic, strong, readonly) KPKCompositeKey *compositeKey;
//@property (nonatomic, copy) NSString *password;
//@property (nonatomic, strong) NSURL *key;
@@ -56,7 +56,25 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
#pragma mark Lock/Decrypt
- (void)lockDatabase:(id)sender;
/**
* Decrypts the databse with the given password and keyfile
*
* @param password The password to unlock the db with, can be nil. This is not the same as an empty stirng @""
* @param keyFileURL URL for the keyfile to use, can be nil
* @param error Pointer to an NSError pointer of error reporting.
*
* @return YES if the document was unlocked sucessfully, NO otherwise. Consult the error object for details
*/
- (BOOL)unlockWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL error:(NSError *__autoreleasing*)error;
/**
* Changes the password of the database. Some sanity checks are applied and the change is aborted if the new values arent valid
*
* @param password new password, can be nil
* @param keyFileURL new key URL can be nil
*
* @return YES if the password was change, NO otherwise
*/
- (BOOL)changePassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL;
/**
* Returns the suggest key URL for this document. This might be nil.
* If the user did disable remeberKeyFiles in the settings, this always returns nil

View File

@@ -52,6 +52,7 @@ typedef NS_ENUM(NSUInteger, MPAlertType) {
@property (strong, nonatomic) KPKTree *tree;
@property (weak, nonatomic) KPKGroup *root;
@property (nonatomic, strong) KPKCompositeKey *compositeKey;
@property (assign) BOOL readOnly;
@property (strong) NSURL *lockFileURL;
@@ -244,12 +245,22 @@ typedef NS_ENUM(NSUInteger, MPAlertType) {
return isUnlocked;
}
- (BOOL)changePassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL {
/* sanity check? */
if([password length] == 0 && keyFileURL == nil) {
return NO;
}
[self.compositeKey setPassword:password andKeyfile:keyFileURL];
/* We need to store the key file once the user actually writes the database */
return YES;
}
- (NSURL *)suggestedKeyURL {
if(!self.isAllowedToStoreKeyFile) {
return nil;
}
NSDictionary *keysForFiles = [[NSUserDefaults standardUserDefaults] dictionaryForKey:kMPSettingsKeyRememeberdKeysForDatabases];
NSString *keyPath = keysForFiles[[[self fileURL] path]];
if(!self.isAllowedToStoreKeyFile) {
return nil;
}
NSDictionary *keysForFiles = [[NSUserDefaults standardUserDefaults] dictionaryForKey:kMPSettingsKeyRememeberdKeysForDatabases];
NSString *keyPath = keysForFiles[[[self fileURL] path]];
if(!keyPath) {
return nil;
}

View File

@@ -85,7 +85,7 @@
#pragma mark Actions
- (IBAction)save:(id)sender {
_currentDocument.compositeKey = [[KPKCompositeKey alloc] initWithPassword:[self.passwordTextField stringValue] key:[self.keyfilePathControl URL]];
[_currentDocument changePassword:[self.passwordTextField stringValue] keyFileURL:[self.keyfilePathControl URL]];
[self dismissSheet:NSRunStoppedResponse];
if(self.delegate && [self.delegate respondsToSelector:@selector(didFinishPasswordEditing:)]) {
[self.delegate didFinishPasswordEditing:YES];