1.1 --- a/MYKeychainItem.m Tue Jun 09 23:58:03 2009 -0700
1.2 +++ b/MYKeychainItem.m Tue Jul 21 10:13:08 2009 -0700
1.3 @@ -8,6 +8,7 @@
1.4
1.5 #import "MYKeychainItem.h"
1.6 #import "MYCrypto_Private.h"
1.7 +#import "MYBERParser.h"
1.8 #import "MYErrorUtils.h"
1.9
1.10
1.11 @@ -25,6 +26,9 @@
1.12 _itemRef = itemRef;
1.13 CFRetain(_itemRef);
1.14 LogTo(INIT,@"%@, _itemRef=%@", [self class], itemRef);
1.15 +#if MYCRYPTO_USE_IPHONE_API
1.16 + _isPersistent = YES;
1.17 +#endif
1.18 }
1.19 return self;
1.20 }
1.21 @@ -32,6 +36,10 @@
1.22
1.23 @synthesize keychainItemRef=_itemRef;
1.24
1.25 +#if MYCRYPTO_USE_IPHONE_API
1.26 +@synthesize isPersistent = _isPersistent;
1.27 +#endif
1.28 +
1.29 - (void) dealloc
1.30 {
1.31 if (_itemRef) CFRelease(_itemRef);
1.32 @@ -71,7 +79,7 @@
1.33
1.34 - (MYKeychain*) keychain {
1.35 #if MYCRYPTO_USE_IPHONE_API
1.36 - return [MYKeychain defaultKeychain];
1.37 + return _isPersistent ? [MYKeychain defaultKeychain] : nil;
1.38 #else
1.39 MYKeychain *keychain = nil;
1.40 SecKeychainRef keychainRef = NULL;
1.41 @@ -89,6 +97,8 @@
1.42 OSStatus err;
1.43 #if MYCRYPTO_USE_IPHONE_API
1.44 err = SecItemDelete((CFDictionaryRef) $dict( {(id)kSecValueRef, (id)_itemRef} ));
1.45 + if (!err)
1.46 + _isPersistent = NO;
1.47 #else
1.48 err = SecKeychainItemDelete((SecKeychainItemRef)_itemRef);
1.49 if (err==errSecInvalidItemRef)
1.50 @@ -98,6 +108,43 @@
1.51 }
1.52
1.53
1.54 +/* (Not useful yet, as only password items have dates.)
1.55 +- (NSDate*) dateValueOfAttribute: (SecKeychainAttrType)attr {
1.56 + NSString *dateStr = [self stringValueOfAttribute: attr];
1.57 + if (dateStr.length == 0)
1.58 + return nil;
1.59 + NSDate *date = [MYBERGeneralizedTimeFormatter() dateFromString: dateStr];
1.60 + if (!date)
1.61 + Warn(@"MYKeychainItem: unable to parse date '%@'", dateStr);
1.62 + return date;
1.63 +}
1.64 +
1.65 +- (void) setDateValue: (NSDate*)date ofAttribute: (SecKeychainAttrType)attr {
1.66 + NSString *timeStr = nil;
1.67 + if (date)
1.68 + timeStr = [MYBERGeneralizedTimeFormatter() stringFromDate: date];
1.69 + [self setValue: timeStr ofAttribute: attr];
1.70 +}
1.71 +
1.72 +
1.73 +- (NSDate*) creationDate {
1.74 + return [self dateValueOfAttribute: kSecCreationDateItemAttr];
1.75 +}
1.76 +
1.77 +- (void) setCreationDate: (NSDate*)date {
1.78 + [self setDateValue: date ofAttribute: kSecCreationDateItemAttr];
1.79 +}
1.80 +
1.81 +- (NSDate*) modificationDate {
1.82 + return [self dateValueOfAttribute: kSecModDateItemAttr];
1.83 +}
1.84 +
1.85 +- (void) setModificationDate: (NSDate*)date {
1.86 + [self setDateValue: date ofAttribute: kSecModDateItemAttr];
1.87 +}
1.88 +*/
1.89 +
1.90 +
1.91 #pragma mark -
1.92 #pragma mark DATA / METADATA ACCESSORS:
1.93
1.94 @@ -165,6 +212,10 @@
1.95 }
1.96
1.97 - (NSString*) stringValueOfAttribute: (SecKeychainAttrType)attr {
1.98 +#if MYCRYPTO_USE_IPHONE_API
1.99 + if (!self.isPersistent)
1.100 + return nil;
1.101 +#endif
1.102 return [[self class] _getStringAttribute: attr ofItem: _itemRef];
1.103 }
1.104