reduced code complexity

added usage of storage typdef instead of AppKit values
This commit is contained in:
Michael Starke
2022-10-12 00:33:14 +02:00
parent 24164d501e
commit 289a27c7e7
4 changed files with 28 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
{ {
"info" : { "info" : {
"version" : 1, "author" : "xcode",
"author" : "xcode" "version" : 1
} }
} }

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21225" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies> <dependencies>
<deployment identifier="macosx"/> <deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21225"/>
<capability name="Image references" minToolsVersion="12.0"/> <capability name="Image references" minToolsVersion="12.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
@@ -29,7 +29,7 @@
<rect key="frame" x="0.0" y="0.0" width="508" height="526"/> <rect key="frame" x="0.0" y="0.0" width="508" height="526"/>
<subviews> <subviews>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2"> <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2">
<rect key="frame" x="323" y="169" width="78" height="32"/> <rect key="frame" x="325" y="169" width="77" height="32"/>
<buttonCell key="cell" type="push" title="Unlock" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="3"> <buttonCell key="cell" type="push" title="Unlock" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="3">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
@@ -89,14 +89,14 @@ DQ
</connections> </connections>
</secureTextField> </secureTextField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="408"> <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="408">
<rect key="frame" x="351" y="246" width="50" height="32"/> <rect key="frame" x="351" y="246" width="51" height="32"/>
<buttonCell key="cell" type="push" bezelStyle="rounded" image="NSQuickLookTemplate" imagePosition="only" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="409"> <buttonCell key="cell" type="push" bezelStyle="rounded" image="NSQuickLookTemplate" imagePosition="only" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="409">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/> <behavior key="behavior" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
</buttonCell> </buttonCell>
</button> </button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="486"> <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="486">
<rect key="frame" x="351" y="216" width="50" height="32"/> <rect key="frame" x="351" y="216" width="51" height="32"/>
<buttonCell key="cell" type="push" bezelStyle="rounded" image="NSStopProgressTemplate" imagePosition="only" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="487"> <buttonCell key="cell" type="push" bezelStyle="rounded" image="NSStopProgressTemplate" imagePosition="only" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="487">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
@@ -113,7 +113,7 @@ DQ
</buttonCell> </buttonCell>
</button> </button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2pb-ZG-spA"> <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2pb-ZG-spA">
<rect key="frame" x="249" y="169" width="76" height="32"/> <rect key="frame" x="251" y="169" width="76" height="32"/>
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="erj-mR-UyO"> <buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="erj-mR-UyO">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
@@ -134,7 +134,7 @@ Gw
</textFieldCell> </textFieldCell>
</textField> </textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ZpI-L9-oFW"> <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ZpI-L9-oFW">
<rect key="frame" x="153" y="130" width="247" height="40"/> <rect key="frame" x="153" y="130" width="248" height="40"/>
<buttonCell key="cell" type="push" bezelStyle="rounded" imagePosition="overlaps" alignment="center" controlSize="large" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="H68-pk-x95"> <buttonCell key="cell" type="push" bezelStyle="rounded" imagePosition="overlaps" alignment="center" controlSize="large" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="H68-pk-x95">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
@@ -198,7 +198,7 @@ Gw
<constraint firstItem="2" firstAttribute="leading" secondItem="2pb-ZG-spA" secondAttribute="trailing" constant="12" id="ytJ-5Z-5rT"/> <constraint firstItem="2" firstAttribute="leading" secondItem="2pb-ZG-spA" secondAttribute="trailing" constant="12" id="ytJ-5Z-5rT"/>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="ZpI-L9-oFW" secondAttribute="bottom" constant="1" id="zhU-C3-jab"/> <constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="ZpI-L9-oFW" secondAttribute="bottom" constant="1" id="zhU-C3-jab"/>
</constraints> </constraints>
<point key="canvasLocation" x="-25" y="11"/> <point key="canvasLocation" x="100" y="-94"/>
</customView> </customView>
</objects> </objects>
<resources> <resources>

View File

@@ -202,16 +202,12 @@
return (nil != currentDocument.encryptedKeyData); return (nil != currentDocument.encryptedKeyData);
} }
- (NSData * _Nullable)_touchIdEncryptedCompositeKeyForCurrentDocutmen { - (IBAction)unlockWithTouchID:(id)sender {
NSString* documentKey = [self biometricKeyForCurrentDocument]; NSString* documentKey = [self biometricKeyForCurrentDocument];
if(nil == documentKey) { if(nil == documentKey) {
return nil; return;
} }
return [MPTouchIdCompositeKeyStore.defaultStore loadEncryptedCompositeKeyForDocumentKey:documentKey]; NSData* encryptedKey = [MPTouchIdCompositeKeyStore.defaultStore loadEncryptedCompositeKeyForDocumentKey:documentKey];
}
- (IBAction)unlockWithTouchID:(id)sender {
NSData* encryptedKey = [self _touchIdEncryptedCompositeKeyForCurrentDocutmen];
if(!encryptedKey) { if(!encryptedKey) {
self.touchIdButton.enabled = NO; self.touchIdButton.enabled = NO;
return; return;

View File

@@ -8,12 +8,13 @@
#import "MPSettingsHelper.h" #import "MPSettingsHelper.h"
#import "MPTouchIdCompositeKeyStore.h" #import "MPTouchIdCompositeKeyStore.h"
#import "MPConstants.h" #import "MPConstants.h"
#import "MPSettingsHelper.h"
#import "NSError+Messages.h" #import "NSError+Messages.h"
@interface MPTouchIdCompositeKeyStore () @interface MPTouchIdCompositeKeyStore ()
@property (readonly, strong) NSMutableDictionary* keys; @property (readonly, strong) NSMutableDictionary* keys;
@property (nonatomic) NSInteger touchIdEnabledState; @property (nonatomic) MPTouchIDKeyStorage touchIdEnabledState;
@end @end
@implementation MPTouchIdCompositeKeyStore @implementation MPTouchIdCompositeKeyStore
@@ -39,13 +40,13 @@
return self; return self;
} }
- (void)setTouchIdEnabledState:(NSInteger)touchIdEnabledState { - (void)setTouchIdEnabledState:(MPTouchIDKeyStorage)touchIdEnabledState {
switch(touchIdEnabledState) { switch(touchIdEnabledState) {
case NSControlStateValueMixed: case MPTouchIDKeyStorageTransient:
// clear persistent store // clear persistent store
[NSUserDefaults.standardUserDefaults removeObjectForKey:kMPSettingsKeyTouchIdEncryptedKeyStore]; [NSUserDefaults.standardUserDefaults removeObjectForKey:kMPSettingsKeyTouchIdEncryptedKeyStore];
break; break;
case NSControlStateValueOn: case MPTouchIDKeyStoragePersistent:
// clear transient store // clear transient store
[self.keys removeAllObjects]; [self.keys removeAllObjects];
break; break;
@@ -66,29 +67,33 @@
/* FIXME this behavour is wrong. Old keys do not get cleared so this leaves a lot of data behind that should be cleaned up*/ /* FIXME this behavour is wrong. Old keys do not get cleared so this leaves a lot of data behind that should be cleaned up*/
NSInteger touchIdMode = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyTouchIdEnabled]; MPTouchIDKeyStorage touchIdMode = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyTouchIdEnabled];
switch(touchIdMode) { switch(touchIdMode) {
case NSControlStateValueMixed: case MPTouchIDKeyStorageTransient:
[NSUserDefaults.standardUserDefaults removeObjectForKey:documentKey]; [NSUserDefaults.standardUserDefaults removeObjectForKey:documentKey];
if(nil != encryptedCompositeKey) { if(nil != encryptedCompositeKey) {
self.keys[documentKey] = encryptedCompositeKey; self.keys[documentKey] = encryptedCompositeKey;
} }
break; break;
case NSControlStateValueOn: case MPTouchIDKeyStoragePersistent:
self.keys[documentKey] = nil; self.keys[documentKey] = nil;
if(nil != encryptedCompositeKey) { if(nil != encryptedCompositeKey) {
[NSUserDefaults.standardUserDefaults setObject:encryptedCompositeKey forKey:documentKey]; [NSUserDefaults.standardUserDefaults setObject:encryptedCompositeKey forKey:documentKey];
} }
break; break;
default: case MPTouchIDKeyStorageDisabled:
[NSUserDefaults.standardUserDefaults removeObjectForKey:documentKey]; [NSUserDefaults.standardUserDefaults removeObjectForKey:documentKey];
self.keys[documentKey] = nil; self.keys[documentKey] = nil;
break;
default:
NSAssert(NO,@"Unsupported internal touchID preferences value.");
break;
} }
} }
- (NSData *)loadEncryptedCompositeKeyForDocumentKey:(NSString *)documentKey { - (NSData *)loadEncryptedCompositeKeyForDocumentKey:(NSString *)documentKey {
NSInteger touchIdMode = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyTouchIdEnabled]; NSInteger touchIdMode = [NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyTouchIdEnabled];
NSData* transientKey = self.keys[documentKey]; NSData* transientKey = self.keys[documentKey];
NSData* persistentKey =[NSUserDefaults.standardUserDefaults dataForKey:documentKey]; NSData* persistentKey = [NSUserDefaults.standardUserDefaults dataForKey:documentKey];
if(nil == transientKey && nil == persistentKey) { if(nil == transientKey && nil == persistentKey) {
return nil; return nil;
} }