adium 4575:5eddeda585e7: Fixed a mega bunch of "Method accepting...

commits at adium.im commits at adium.im
Fri Jan 27 16:20:04 UTC 2012


details:	http://hg.adium.im/adium/rev/5eddeda585e7
revision:	4575:5eddeda585e7
branch:		(none)
author:		Adrian Godoroja <robotive at me.com>
date:		Fri Jan 27 18:19:55 2012 +0200

Fixed a mega bunch of "Method accepting NSError** should have a non-void return value to indicate whether or not an error occurred". Analyzer Warnings--.

diffs (truncated from 1525 to 1000 lines):

diff -r 7ee7f2517cc5 -r 5eddeda585e7 Frameworks/AIUtilities Framework/Source/AIKeychain.h
--- a/Frameworks/AIUtilities Framework/Source/AIKeychain.h	Fri Jan 27 12:54:07 2012 +0200
+++ b/Frameworks/AIUtilities Framework/Source/AIKeychain.h	Fri Jan 27 18:19:55 2012 +0200
@@ -30,6 +30,7 @@
  *	You may pass \c NULL for the \a error argument, in which case the error will be
  *	silently dropped.
  */
+
 /*@{*/
 
 /*!	@def AIKEYCHAIN_ERROR_DOMAIN
@@ -43,42 +44,53 @@
  *	This value is stored as an \c NSValue. Call \c -pointerValue to retrieve the function pointer.
  */
 #define AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION @"SecurityFrameworkFunction"
+
 //!	@brief The name of the Keychain Services function that returned the error.
 #define AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTIONNAME @"SecurityFrameworkFunctionName"
+
 //!	@brief Description of the error (from SecErrorMessages.strings).
 #define AIKEYCHAIN_ERROR_USERINFO_ERRORDESCRIPTION @"SecurityFrameworkErrorDescription"
+
 //!	@brief The \c AIKeychain instance that was involved.
 #define AIKEYCHAIN_ERROR_USERINFO_KEYCHAIN @"Keychain"
+
 /*!	@def AIKEYCHAIN_ERROR_USERINFO_USERINTERACTIONALLOWEDSTATE
  *	@brief The value that would have been returned by \c +allowsUserInteraction or was passed to <code>+setAllowsUserInteraction:</code>.
  *	This is an \c NSNumber containing a \c BOOL.
  */
 #define AIKEYCHAIN_ERROR_USERINFO_USERINTERACTIONALLOWEDSTATE @"UserInteractionAllowed"
+
 /*!	@def AIKEYCHAIN_ERROR_USERINFO_SETTINGSPOINTER
  *	@brief The pointer passed to <code>-getSettings:</code> or <code>-setSettings:</code>.
  *	This value is stored as an \c NSValue. Call \c -pointerValue to retrieve the function pointer.
  */
 #define AIKEYCHAIN_ERROR_USERINFO_SETTINGSPOINTER @"PointerToSettingsStructure"
+
 /*!	@def AIKEYCHAIN_ERROR_USERINFO_SERVICE
  *	@brief The service name passed to <code>-addGenericPasswordForService:account:keychainItem:error:</code> or <code>-findGenericPasswordForService:account:keychainItem:error:</code>.
  */
 #define AIKEYCHAIN_ERROR_USERINFO_SERVICE            @"GenericPasswordService"
+
 /*!	@def AIKEYCHAIN_ERROR_USERINFO_SERVER
  *	@brief The service name passed to <code>-addInternetPassword:forService:securityDomain:account:path:port:protocol:authenticationType:keychainItem:error:</code> or <code>-findInternetPasswordForServer:securityDomain:account:path:port:protocol:authenticationType:keychainItem:error:</code>.
  */
 #define AIKEYCHAIN_ERROR_USERINFO_SERVER             @"InternetPasswordServer"
+
 /*!	@def AIKEYCHAIN_ERROR_USERINFO_DOMAIN
  *	@brief The service name passed to <code>-addInternetPassword:forService:securityDomain:account:path:port:protocol:authenticationType:keychainItem:error:</code> or <code>-findInternetPasswordForServer:securityDomain:account:path:port:protocol:authenticationType:keychainItem:error:</code>.
  */
 #define AIKEYCHAIN_ERROR_USERINFO_DOMAIN             @"InternetPasswordSecurityDomain"
+
 /*!	@def AIKEYCHAIN_ERROR_USERINFO_ACCOUNT
  *	@brief The service name passed to <code>-addInternetPassword:forService:securityDomain:account:path:port:protocol:authenticationType:keychainItem:error:</code>, <code>-findInternetPasswordForServer:securityDomain:account:path:port:protocol:authenticationType:keychainItem:error:</code>, <code>-addGenericPasswordForService:account:keychainItem:error:</code>, or <code>-findGenericPasswordForService:account:keychainItem:error:</code>.
  */
 #define AIKEYCHAIN_ERROR_USERINFO_ACCOUNT            @"PasswordAccount"
+
 /*!	@def AIKEYCHAIN_ERROR_USERINFO_PROTOCOL
  *	@brief The service name passed to <code>-addInternetPassword:forService:securityDomain:account:path:port:protocol:authenticationType:keychainItem:error:</code> or <code>-findInternetPasswordForServer:securityDomain:account:path:port:protocol:authenticationType:keychainItem:error:</code>.
  */
 #define AIKEYCHAIN_ERROR_USERINFO_PROTOCOL           @"PasswordProtocol"
+
 /*!	@def AIKEYCHAIN_ERROR_USERINFO_AUTHENTICATIONTYPE
  *	@brief The service name passed to <code>-addInternetPassword:forService:securityDomain:account:path:port:protocol:authenticationType:keychainItem:error:</code> or <code>-findInternetPasswordForServer:securityDomain:account:path:port:protocol:authenticationType:keychainItem:error:</code>.
  */
@@ -101,15 +113,19 @@
  *	Wraps \c SecKeychainLockAll.
  *
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
+ *	@return \c BOOL (Success/Failure)
  */
-+ (void)lockAllKeychains_error:(out NSError **)outError;
++ (BOOL)lockAllKeychains_error:(out NSError **)outError;
+
 /*!	@brief Locks the user's default keychain.
  *
  *	Wraps \c SecKeychainLock, passing \c NULL as the keychain to lock.
  *
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
+ *	@return \c BOOL (Success/Failure)
  */
-+ (void)lockDefaultKeychain_error:(out NSError **)outError;
++ (BOOL)lockDefaultKeychain_error:(out NSError **)outError;
+
 /*!	@brief Unlocks the user's default keychain.
  *
  *	@par
@@ -121,6 +137,7 @@
  *	@return \c YES if the keychain was successfully unlocked; \c NO if the password was incorrect or an error occurred.
  */
 + (BOOL)unlockDefaultKeychain_error:(out NSError **)outError;
+
 /*!	@brief Unlocks the user's default keychain with a specific password.
  *
  *	Wraps \c SecKeychainUnlock, passing \c NULL as the keychain to unlock.
@@ -139,6 +156,7 @@
  *	@return \c YES if user interaction is allowed; \c NO if not, or if an error occurred.
  */
 + (BOOL)allowsUserInteraction_error:(out NSError **)outError;
+
 /*!	@brief Sets whether Keychain Services should use its user interface.
  *
  *	Wraps \c SecKeychainSetUserInteractionAllowed.
@@ -146,7 +164,7 @@
  *	@param flag \c YES if user interaction should be allowed; \c NO if not.
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
  */
-+ (void)setAllowsUserInteraction:(BOOL)flag error:(out NSError **)outError;
++ (BOOL)setAllowsUserInteraction:(BOOL)flag error:(out NSError **)outError;
 
 /*!	@brief Returns the version of the Keychain Services API.
  *	Wraps \c SecKeychainGetVersion.
@@ -169,6 +187,7 @@
  *	@return An \c AIKeychain instance that wraps the current default keychain.
  */
 + (AIKeychain *)defaultKeychain_error:(out NSError **)outError;
+
 /*!	@brief	Sets the default keychain.
  *
  *	@par
@@ -179,8 +198,9 @@
  *
  *	@param newDefaultKeychain An \c AIKeychain instance that wraps the intended default keychain.
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
+ *	@return \c BOOL (Success/Failure)
  */
-+ (void)setDefaultKeychain:(AIKeychain *)newDefaultKeychain error:(out NSError **)outError;
++ (BOOL)setDefaultKeychain:(AIKeychain *)newDefaultKeychain error:(out NSError **)outError;
 
 /*!	@brief Loads a keychain from a file.
  *
@@ -191,6 +211,7 @@
  *	@return A shiny new autoreleased \c AIKeychain.
  */
 + (AIKeychain *)keychainWithContentsOfFile:(NSString *)path error:(out NSError **)outError;
+
 /*!	@brief Loads a keychain from a file.
  *
  *	Wraps \c SecKeychainOpen.
@@ -213,6 +234,7 @@
  *	@result A shiny new autoreleased \c AIKeychain.
  */
 + (AIKeychain *)keychainWithPath:(NSString *)path password:(NSString *)password promptUser:(BOOL)prompt initialAccess:(SecAccessRef)initialAccess error:(out NSError **)outError;
+
 /*!	@brief Creates a new keychain from scratch.
  *
  *	Wraps \c SecKeychainCreate.
@@ -238,6 +260,7 @@
  *	@return A shiny new autoreleased \c AIKeychain.
  */
 + (AIKeychain *)keychainWithKeychainRef:(SecKeychainRef)newKeychainRef;
+
 /*!	@brief Creates a new \c AIKeychain wrapper for an existing keychain object.
  *
  *	When you already have a Keychain Services \c SecKeychainRef for a keychain, use this to wrap it in yummy \c AIKeychain goodness.
@@ -255,16 +278,19 @@
  *
  *	@param outSettings The destination to which the settings should be copied.
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
+ *	@return \c BOOL (Success/Failure)
  */
-- (void)getSettings:(out struct SecKeychainSettings *)outSettings error:(out NSError **)outError;
+- (BOOL)getSettings:(out struct SecKeychainSettings *)outSettings error:(out NSError **)outError;
+
 /*!	@brief Sets the current settings of the keychain.
  *
  *	Wraps \c SecKeychainSetSettings.
  *
  *	@param newSettings The new settings. These will be copied, so the memory does not need to persist after this call.
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
+ *	@return \c BOOL (Success/Failure)
  */
-- (void)setSettings:( in struct SecKeychainSettings *)newSettings error:(out NSError **)outError;
+- (BOOL)setSettings:( in struct SecKeychainSettings *)newSettings error:(out NSError **)outError;
 
 /*!	@brief Gets the current status (locked state and writability) of the keychain.
  *
@@ -274,6 +300,7 @@
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
  */
 - (SecKeychainStatus)status_error:(out NSError **)outError;
+
 /*!	@brief Gets the path to the keychain file.
  *
  *	@par
@@ -288,6 +315,7 @@
  *	@return \a outBuf.
  */
 - (char *)getPathFileSystemRepresentation:(out char *)outBuf length:(inout u_int32_t *)outLength error:(out NSError **)outError;
+
 /*!	@brief Gets the path to the keychain file as an \c NSString.
  *
  *	@par
@@ -304,8 +332,10 @@
  *	Wraps \c SecKeychainLock.
  *
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
+ *	@return \c BOOL (Success/Failure)
  */
-- (void)lockKeychain_error:(out NSError **)outError;
+- (BOOL)lockKeychain_error:(out NSError **)outError;
+
 /*!	@brief Unlocks the keychain.
  *
  *	@par
@@ -318,6 +348,7 @@
  *	@return \c YES if the keychain was successfully unlocked; \c NO if the password was incorrect or an error occurred.
  */
 - (BOOL)unlockKeychain_error:(out NSError **)outError;
+
 /*!	@brief Unlocks the keychain with a specific password.
  *
  *	@par
@@ -342,10 +373,11 @@
  *	@par
  *	\c SecKeychainDelete will not delete a keychain unless it is a local file.
  *	Even if the keychain is successfully deleted, the \c AIKeychain instance will still be around until it has been released by all owners. You just won't be able to use it.
+ *	@return \c BOOL (Success/Failure)
  *
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
  */
-- (void)deleteKeychain_error:(out NSError **)outError;
+- (BOOL)deleteKeychain_error:(out NSError **)outError;
 
 #pragma mark -
 
@@ -356,7 +388,6 @@
  *	keychain item.
  */
 
-//------------------------------------------------------------------------------
 /*!	@brief Adds an Internet password.
  *
  *	@par
@@ -375,8 +406,9 @@
  *	@param authType The type of authentication to use.
  *	@param outKeychainItem On return, a pointer to the keychain item that was created and added. Can be \c NULL. If it is non-\c NULL, you are responsible for releasing the keychain item.
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
+ *	@return \c BOOL (Success/Failure)
  */
-- (void)addInternetPassword:(NSString *)password
+- (BOOL)addInternetPassword:(NSString *)password
 				  forServer:(NSString *)server
 			 securityDomain:(NSString *)domain //can pass nil
 					account:(NSString *)account
@@ -400,14 +432,16 @@
  *	@param account The username of the account.
  *	@param protocol The protocol of the service via which authentication should occur.
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
+ *	@return \c BOOL (Success/Failure)
  */
-- (void)addInternetPassword:(NSString *)password
+- (BOOL)addInternetPassword:(NSString *)password
 				  forServer:(NSString *)server
 					account:(NSString *)account
 				   protocol:(SecProtocolType)protocol
 					  error:(out NSError **)outError;
 
-//------------------------------------------------------------------------------
+#pragma mark -
+
 /*!	@brief Retrieves an Internet password.
  *
  *	@par
@@ -469,7 +503,8 @@
  */
 - (NSDictionary *)dictionaryFromKeychainForServer:(NSString *)server protocol:(SecProtocolType)protocol error:(out NSError **)outError;
 
-//------------------------------------------------------------------------------
+#pragma mark -
+
 /*!	@brief Adds, changes, or deletes an Internet password.
  *
  *	@par
@@ -490,8 +525,9 @@
  *	@param authType The type of authentication to use.
  *	@param outKeychainItem On return, a pointer to the keychain item that was created and added. Can be \c NULL.
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
+ *	@return \c BOOL (Success/Failure)
  */
-- (void)setInternetPassword:(NSString *)password
+- (BOOL)setInternetPassword:(NSString *)password
 				  forServer:(NSString *)server
 			 securityDomain:(NSString *)domain //can pass nil
 					account:(NSString *)account
@@ -517,14 +553,15 @@
  *	@param account The username of the account.
  *	@param protocol The protocol of the service via which authentication should occur.
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
+ *	@return \c BOOL (Success/Failure)
  */
-- (void)setInternetPassword:(NSString *)password
+- (BOOL)setInternetPassword:(NSString *)password
 				  forServer:(NSString *)server
 					account:(NSString *)account
 				   protocol:(SecProtocolType)protocol
 					  error:(out NSError **)outError;
 
-//------------------------------------------------------------------------------
+#pragma mark -
 
 /*!	@brief Deletes an Internet password.
  *
@@ -540,8 +577,9 @@
  *	@param authType The type of authentication to use.
  *	@param outKeychainItem On return, a pointer to the keychain item that was created and added. Can be \c NULL.
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
+ *	@return \c BOOL (Success/Failure)
  */
-- (void)deleteInternetPasswordForServer:(NSString *)server
+- (BOOL)deleteInternetPasswordForServer:(NSString *)server
 						 securityDomain:(NSString *)domain //can pass nil
 								account:(NSString *)account
 								   path:(NSString *)path
@@ -560,8 +598,9 @@
  *	@param account The username of the account.
  *	@param protocol The protocol of the service via which authentication should occur.
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
+ *	@return \c BOOL (Success/Failure)
  */
-- (void)deleteInternetPasswordForServer:(NSString *)server
+- (BOOL)deleteInternetPasswordForServer:(NSString *)server
 								account:(NSString *)account
 							   protocol:(SecProtocolType)protocol
 								  error:(out NSError **)outError;
@@ -581,8 +620,9 @@
  *	@param account The username of the account.
  *	@param outKeychainItem On return, a pointer to the keychain item that was created and added. Can be \c NULL. If you pass non-\c NULL, you are responsible for releasing the keychain item.
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
+ *	@return \c BOOL (Success/Failure)
  */
-- (void)addGenericPassword:(NSString *)password
+- (BOOL)addGenericPassword:(NSString *)password
 				forService:(NSString *)service
 				   account:(NSString *)account
 			  keychainItem:(out SecKeychainItemRef *)outKeychainItem
@@ -614,9 +654,10 @@
 
  *	@param outError On return, a pointer to either \c nil (hopefully) or an \c NSError describing what went wrong.
  */
-- (void)deleteGenericPasswordForService:(NSString *)service
+- (BOOL)deleteGenericPasswordForService:(NSString *)service
 								account:(NSString *)account
 								  error:(out NSError **)outError;
+
 #pragma mark -
 
 /*!	@brief Returns the Keychain Services object that backs the \c AIKeychain.
diff -r 7ee7f2517cc5 -r 5eddeda585e7 Frameworks/AIUtilities Framework/Source/AIKeychain.m
--- a/Frameworks/AIUtilities Framework/Source/AIKeychain.m	Fri Jan 27 12:54:07 2012 +0200
+++ b/Frameworks/AIUtilities Framework/Source/AIKeychain.m	Fri Jan 27 18:19:55 2012 +0200
@@ -14,8 +14,8 @@
  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
-/*
- *Cocoa wrapper for accessing the system keychain
+/*!
+ * @brief Cocoa wrapper for accessing the system keychain
  */
 
 #import "AIKeychain.h"
@@ -27,15 +27,17 @@
 static AIKeychain *lastKnownDefaultKeychain = nil;
 
 #define AI_LOCALIZED_SECURITY_ERROR_DESCRIPTION(err) \
-	NSLocalizedStringFromTableInBundle([[NSNumber numberWithLong:(err)] stringValue], @"SecErrorMessages", [NSBundle bundleWithIdentifier:@"com.apple.security"], /*comment*/ nil)
+	NSLocalizedStringFromTableInBundle([[NSNumber numberWithLong:(err)] stringValue], @"SecErrorMessages", [NSBundle bundleWithIdentifier:@"com.apple.security"], /* comment */ nil)
 
 @implementation AIKeychain
 
-+ (void)lockAllKeychains_error:(out NSError **)outError
++ (BOOL)lockAllKeychains_error:(out NSError **)outError
 {
 	OSStatus err = SecKeychainLockAll();
+	
 	if (outError) {
 		NSError *error = nil;
+		
 		if (err != noErr) {
 			NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 				[NSValue valueWithPointer:SecKeychainLockAll], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -44,15 +46,20 @@
 				nil];
 			error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 		}
+		
 		*outError = error;
 	}
+	
+	return (err == noErr);
 }
 
-+ (void)lockDefaultKeychain_error:(out NSError **)outError
++ (BOOL)lockDefaultKeychain_error:(out NSError **)outError
 {
-	OSStatus err = SecKeychainLock(/*keychain*/ NULL);
+	OSStatus err = SecKeychainLock(/* keychain */ NULL);
+	
 	if (outError) {
 		NSError *error = nil;
+		
 		if (err != noErr) {
 			NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 				[NSValue valueWithPointer:SecKeychainLock], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -61,14 +68,20 @@
 				nil];
 			error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 		}
+		
 		*outError = error;
 	}
+	
+	return (err == noErr);
 }
+
 + (BOOL)unlockDefaultKeychain_error:(out NSError **)outError
 {
-	OSStatus err = SecKeychainUnlock(/*keychain*/ NULL, /*passwordLength*/ 0, /*password*/ NULL, /*usePassword*/ false);
+	OSStatus err = SecKeychainUnlock(/* keychain */ NULL, /* passwordLength */ 0, /* password */ NULL, /* usePassword */ false);
+	
 	if (outError) {
 		NSError *error = nil;
+		
 		if (err != noErr) {
 			NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 				[NSValue valueWithPointer:SecKeychainUnlock], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -77,22 +90,26 @@
 				nil];
 			error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 		}
+		
 		*outError = error;
 	}
-	return err == noErr;
+	
+	return (err == noErr);
 }
+
 + (BOOL)unlockDefaultKeychainWithPassword:(NSString *)password error:(out NSError **)outError
 {
 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
 	NSData *data = [password dataUsingEncoding:NSUTF8StringEncoding];
 	NSAssert( UINT_MAX >= [data length], @"Attempting to send more data than Keychain can handle.  Abort." );
-	OSStatus err = SecKeychainUnlock(/*keychain*/ NULL, (UInt32)[data length], [data bytes], /*usePassword*/ true);
+	OSStatus err = SecKeychainUnlock(/* keychain */ NULL, (UInt32)[data length], [data bytes], /* usePassword */ true);
 
 	[pool release];
 
 	if (outError) {
 		NSError *error = nil;
+		
 		if (err != noErr) {
 			NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 				[NSValue valueWithPointer:SecKeychainUnlock], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -101,9 +118,11 @@
 				nil];
 			error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 		}
+		
 		*outError = error;
 	}
-	return err == noErr;
+
+	return (err == noErr);
 }
 
 + (BOOL)allowsUserInteraction_error:(out NSError **)outError
@@ -111,8 +130,10 @@
 	Boolean state = false;
 
 	OSStatus err = SecKeychainGetUserInteractionAllowed(&state);
+
 	if (outError) {
 		NSError *error = nil;
+
 		if (err != noErr) {
 			NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 				[NSValue valueWithPointer:SecKeychainGetUserInteractionAllowed], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -121,16 +142,20 @@
 				nil];
 			error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 		}
+		
 		*outError = error;
 	}
 
 	return state;
 }
-+ (void)setAllowsUserInteraction:(BOOL)flag error:(out NSError **)outError
+
++ (BOOL)setAllowsUserInteraction:(BOOL)flag error:(out NSError **)outError
 {
 	OSStatus err = SecKeychainSetUserInteractionAllowed(flag);
+	
 	if (outError) {
 		NSError *error = nil;
+		
 		if (err != noErr) {
 			NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 				[NSValue valueWithPointer:SecKeychainSetUserInteractionAllowed], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -140,17 +165,22 @@
 				nil];
 			error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 		}
+		
 		*outError = error;
 	}
+	
+	return (err == noErr);
 }
 
 + (u_int32_t)keychainServicesVersion_error:(out NSError **)outError
 {
 	UInt32 version;
-	//will this function EVER return an error? well, it can, so we should be prepared for it. --boredzo
+	// Will this function EVER return an error? well, it can, so we should be prepared for it. --boredzo
 	OSStatus err = SecKeychainGetVersion(&version);
+	
 	if (outError) {
 		NSError *error = nil;
+		
 		if (err != noErr) {
 			NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 				[NSValue valueWithPointer:SecKeychainGetVersion], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -159,8 +189,10 @@
 				nil];
 			error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 		}
+
 		*outError = error;
 	}
+
 	return version;
 }
 
@@ -171,6 +203,7 @@
 	SecKeychainRef aKeychainRef = NULL;
 
 	OSStatus err = SecKeychainCopyDefault(&aKeychainRef);
+
 	if (err != noErr) {
 		if (err == errSecNoDefaultKeychain) {
 			/* XXX - SecKeychainCreate() to an appropriate path here, followed by SecKeychainSetDefault(), would
@@ -183,6 +216,7 @@
 		if (err != errSecNoDefaultKeychain) {
 			if (outError) {
 				NSError *error = nil;
+
 				if (err != noErr) {
 					NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 						[NSValue valueWithPointer:SecKeychainCopyDefault], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -191,12 +225,15 @@
 						nil];
 					error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 				}
+				
 				*outError = error;
 			}
 		}
 		
-		if (aKeychainRef) CFRelease(aKeychainRef);
-		
+		if (aKeychainRef) {
+			CFRelease(aKeychainRef);
+		}
+
 		return nil;
 	}
 	
@@ -205,7 +242,7 @@
 
 + (AIKeychain *)defaultKeychain_error:(out NSError **)outError
 {
-	/* ensure there is a default keychain which can be accessed */
+	// Ensure there is a default keychain which can be accessed
 	SecKeychainRef aKeychainRef = [self copyDefaultSecKeychainRef_error:outError];
 
 	if (aKeychainRef) {
@@ -225,13 +262,15 @@
 	}
 }
 
-+ (void)setDefaultKeychain:(AIKeychain *)newDefaultKeychain error:(out NSError **)outError
++ (BOOL)setDefaultKeychain:(AIKeychain *)newDefaultKeychain error:(out NSError **)outError
 {
 	NSParameterAssert(newDefaultKeychain != nil);
 
 	OSStatus err = ([newDefaultKeychain keychainRef] ? SecKeychainSetDefault([newDefaultKeychain keychainRef]) : noErr);
+	
 	if (outError) {
 		NSError *error = nil;
+		
 		if (err != noErr) {
 			NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 				[NSValue valueWithPointer:SecKeychainSetDefault], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -240,24 +279,31 @@
 				nil];
 			error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 		}
+		
 		*outError = error;
 	}
+	
 	if (err == noErr) {
 		[lastKnownDefaultKeychain release];
 		lastKnownDefaultKeychain = [newDefaultKeychain retain];
 	}
+	
+	return (err == noErr);
 }
 
 + (AIKeychain *)keychainWithContentsOfFile:(NSString *)path error:(out NSError **)outError
 {
 	return [[[self alloc] initWithContentsOfFile:path error:outError] autorelease];
 }
+
 - (id)initWithContentsOfFile:(NSString *)path error:(out NSError **)outError
 {
 	if ((self = [super init])) {
 		OSStatus err = SecKeychainOpen([path fileSystemRepresentation], &keychainRef);
+		
 		if (outError) {
 			NSError *error = nil;
+
 			if (err != noErr) {
 				NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 					[NSValue valueWithPointer:SecKeychainOpen], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -266,28 +312,30 @@
 					nil];
 				error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 			}
+
 			*outError = error;
 		}
+		
 		if (err != noErr) {
-			[self release];
-			self = nil;
+			[self release], self = nil;
 		}
 	}
 
 	return self;
 }
 
-//SecKeychainCreate
+// SecKeychainCreate
+
 + (AIKeychain *)keychainWithPath:(NSString *)path password:(NSString *)password promptUser:(BOOL)prompt initialAccess:(SecAccessRef)initialAccess error:(out NSError **)outError
 {
 	return [[[self alloc] initWithPath:path password:password promptUser:prompt initialAccess:initialAccess error:outError] autorelease];
 }
+
 - (id)initWithPath:(NSString *)path password:(NSString *)password promptUser:(BOOL)prompt initialAccess:(SecAccessRef)initialAccess error:(out NSError **)outError
 {
 	if ((self = [super init])) {
-		/*we create our own copy of the string (if any) using NSString to
-		 *	ensure that the NSData that we create is an NSData.
-		 *we create our own pool to ensure that both objects are released ASAP.
+		/* We create our own copy of the string (if any) using NSString to ensure that the NSData that we create is an NSData.
+		 * We create our own pool to ensure that both objects are released ASAP.
 		 */
 		NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
@@ -315,8 +363,10 @@
 					nil];
 				error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 			}
+
 			*outError = error;
 		}
+
 		if (err != noErr) {
 			[self release];
 			self = nil;
@@ -343,17 +393,21 @@
 
 #pragma mark -
 
-- (void)getSettings:(out struct SecKeychainSettings *)outSettings error:(out NSError **)outError
+- (BOOL)getSettings:(out struct SecKeychainSettings *)outSettings error:(out NSError **)outError
 {
 	NSParameterAssert(outSettings != NULL);
 	SecKeychainRef targetKeychainRef = (keychainRef ? (SecKeychainRef)CFRetain(keychainRef) : NULL);
 
-	if (!targetKeychainRef) targetKeychainRef = [[self class] copyDefaultSecKeychainRef_error:outError];
+	if (!targetKeychainRef) {
+		targetKeychainRef = [[self class] copyDefaultSecKeychainRef_error:outError];
+	}
 
 	if (targetKeychainRef) {
 		OSStatus err = SecKeychainCopySettings(targetKeychainRef, outSettings);
+		
 		if (outError) {
 			NSError *error = nil;
+			
 			if (err != noErr) {
 				NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 					[NSValue valueWithPointer:outSettings], AIKEYCHAIN_ERROR_USERINFO_SETTINGSPOINTER,
@@ -363,20 +417,27 @@
 					nil];
 				error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 			}
+
 			*outError = error;
 		}
 		
 		CFRelease(targetKeychainRef);
+		
+		return (err == noErr);
 	}
+	
+	return NO;
 }
-- (void)setSettings:(in struct SecKeychainSettings *)newSettings error:(out NSError **)outError
+
+- (BOOL)setSettings:(in struct SecKeychainSettings *)newSettings error:(out NSError **)outError
 {
 	NSParameterAssert(newSettings != NULL);
-
-	/* If keychainRef is NULL, we'll get the default keychain's settings */
+	// If keychainRef is NULL, we'll get the default keychain's settings
 	OSStatus err = SecKeychainSetSettings(keychainRef, newSettings);
+	
 	if (outError) {
 		NSError *error = nil;
+		
 		if (err != noErr) {
 			NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 				[NSValue valueWithPointer:newSettings], AIKEYCHAIN_ERROR_USERINFO_SETTINGSPOINTER,
@@ -386,17 +447,22 @@
 				nil];
 			error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 		}
+
 		*outError = error;
 	}
+	
+	return (err == noErr);
 }
 
 - (SecKeychainStatus)status_error:(out NSError **)outError
 {
 	SecKeychainStatus status;
-	/* If keychainRef is NULL, we'll get the default keychain's status */
+	// If keychainRef is NULL, we'll get the default keychain's status
 	OSStatus err = SecKeychainGetStatus(keychainRef, &status);
+	
 	if (outError) {
 		NSError *error = nil;
+		
 		if (err != noErr) {
 			NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 				[NSValue valueWithPointer:SecKeychainGetStatus], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -405,8 +471,10 @@
 				nil];
 			error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 		}
+
 		*outError = error;
 	}
+
 	return status;
 }
 
@@ -417,11 +485,12 @@
 
 	SecKeychainRef targetKeychainRef = (keychainRef ? (SecKeychainRef)CFRetain(keychainRef) : NULL);
 	
-	if (!targetKeychainRef) targetKeychainRef = [[self class] copyDefaultSecKeychainRef_error:outError];
-	
+	if (!targetKeychainRef) {
+		targetKeychainRef = [[self class] copyDefaultSecKeychainRef_error:outError];
+	}
+
 	if (targetKeychainRef) {		
 		OSStatus err = SecKeychainGetPath(targetKeychainRef, (UInt32 *)outLength, outBuf);
-		
 		NSError *error = nil;
 		
 		if (err != noErr) {
@@ -431,12 +500,17 @@
 				AI_LOCALIZED_SECURITY_ERROR_DESCRIPTION(err), AIKEYCHAIN_ERROR_USERINFO_ERRORDESCRIPTION,
 				targetKeychainRef, AIKEYCHAIN_ERROR_USERINFO_KEYCHAIN,
 				nil];
-			if (outError)
+			
+			if (outError) {
 				error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
+			}
+
 			outBuf = NULL;
 		}
 		
-		if (outError) *outError = error;
+		if (outError) {
+			*outError = error;
+		}
 
 		CFRelease(targetKeychainRef);
 
@@ -446,6 +520,7 @@
 
 	return outBuf;
 }
+
 - (NSString *)path
 {
 	NSMutableData *data = [NSMutableData dataWithLength:PATH_MAX];
@@ -454,17 +529,20 @@
 								   length:&size
 									error:NULL];
 	[data setLength:size];
+
 	return [NSString stringWithData:data encoding:NSUTF8StringEncoding];
 }
 
 #pragma mark -
 
-- (void)lockKeychain_error:(out NSError **)outError
+- (BOOL)lockKeychain_error:(out NSError **)outError
 {
-	/* If keychainRef is NULL, the default keychain will locked */
+	// If keychainRef is NULL, the default keychain will locked
 	OSStatus err = SecKeychainLock(keychainRef);
+	
 	if (outError) {
 		NSError *error = nil;
+		
 		if (err != noErr) {
 			NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 				[NSValue valueWithPointer:SecKeychainLock], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -474,16 +552,21 @@
 				nil];
 			error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 		}
+
 		*outError = error;
 	}
+	
+	return (err == noErr);
 }
 
 - (BOOL)unlockKeychain_error:(out NSError **)outError
 {
-	/* If keychainRef is NULL, the default keychain will unlocked */
-	OSStatus err = SecKeychainUnlock(keychainRef, /*passwordLength*/ 0, /*password*/ NULL, /*usePassword*/ false);
+	// If keychainRef is NULL, the default keychain will unlocked
+	OSStatus err = SecKeychainUnlock(keychainRef, /* passwordLength */ 0, /* password */ NULL, /* usePassword */ false);
+	
 	if (outError) {
 		NSError *error = nil;
+		
 		if (err != noErr) {
 			NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 				[NSValue valueWithPointer:SecKeychainUnlock], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -493,24 +576,28 @@
 				nil];
 			error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 		}
+
 		*outError = error;
 	}
-	return err == noErr;
+
+	return (err == noErr);
 }
+
 - (BOOL)unlockKeychainWithPassword:(NSString *)password error:(out NSError **)outError
 {
 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
 	NSData *data = [password dataUsingEncoding:NSUTF8StringEncoding];
 	
-	/* If keychainRef is NULL, the default keychain will unlocked */
+	// If keychainRef is NULL, the default keychain will unlocked
 	NSAssert( UINT_MAX >= [data length], @"Attempting to send more data than Keychain can handle.  Abort." );
-	OSStatus err = SecKeychainUnlock(keychainRef, (UInt32)[data length], [data bytes], /*usePassword*/ true);
+	OSStatus err = SecKeychainUnlock(keychainRef, (UInt32)[data length], [data bytes], /* usePassword */ true);
 
 	[pool release];
 
 	if (outError) {
 		NSError *error = nil;
+		
 		if (err != noErr) {
 			NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 				[NSValue valueWithPointer:SecKeychainUnlock], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -520,24 +607,29 @@
 				nil];
 			error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 		}
+
 		*outError = error;
 	}
-	return err == noErr;
+
+	return (err == noErr);
 }
 
 #pragma mark -
 
-- (void)deleteKeychain_error:(out NSError **)outError
+- (BOOL)deleteKeychain_error:(out NSError **)outError
 {
 	SecKeychainRef targetKeychainRef = (keychainRef ? (SecKeychainRef)CFRetain(keychainRef) : NULL);
 	
-	if (!targetKeychainRef) targetKeychainRef = [[self class] copyDefaultSecKeychainRef_error:outError];
+	if (!targetKeychainRef) {
+		targetKeychainRef = [[self class] copyDefaultSecKeychainRef_error:outError];
+	}
 	
 	if (targetKeychainRef) {				
-		/* In 10.2, passing NULL to SecKeychainDelete deletes the default keychain.
-		* In 10.3+, passing NULL returns errSecInvalidKeychain.
-		*/
+		/* In 10.2, passing NULL to SecKeychainDelete deletes the default keychain
+		 * In 10.3+, passing NULL returns errSecInvalidKeychain
+		 */
 		OSStatus err = SecKeychainDelete(targetKeychainRef);
+
 		if (outError) {
 			NSError *error = nil;
 			if (err != noErr) {
@@ -549,21 +641,26 @@
 					nil];
 				error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 			}
+
 			*outError = error;
 		}
 
 		CFRelease(targetKeychainRef);
+		
+		return (err == noErr);
 	}
+	
+	return NO;
 }
 
 #pragma mark -
 
-- (void)addInternetPassword:(NSString *)password
+- (BOOL)addInternetPassword:(NSString *)password
 				  forServer:(NSString *)server
-			 securityDomain:(NSString *)domain //can pass nil
+			 securityDomain:(NSString *)domain	// Can pass nil
 					account:(NSString *)account
 					   path:(NSString *)path
-					   port:(u_int16_t)port //can pass 0
+					   port:(u_int16_t)port		// Can pass 0
 				   protocol:(SecProtocolType)protocol
 		 authenticationType:(SecAuthenticationType)authType
 			   keychainItem:(out SecKeychainItemRef *)outKeychainItem
@@ -571,7 +668,7 @@
 {
 	NSParameterAssert(password != nil);
 	NSParameterAssert(server != nil);
-	//domain is optional
+	// Domain is optional
 
 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
@@ -588,16 +685,16 @@
 					  (UINT_MAX >= [accountData length]) &&
 					  (UINT_MAX >= [pathData length]),
 					  @"Attempting to send more data than Keychain can handle.  Abort." );
-	/* If keychainRef is NNULL, the password will be added to the default keychain */
+	// If keychainRef is NNULL, the password will be added to the default keychain
 	OSStatus err = SecKeychainAddInternetPassword(keychainRef,
 												  (UInt32)[serverData length],  [serverData bytes],
-												  //domain is optional, so be sure to handle domain == nil
+												  // Domain is optional, so be sure to handle domain == nil
 												  domainData ? (UInt32)[domainData length] : 0,
 												  domainData ? [domainData bytes]  : NULL,
-												  //account appears optional, even though it isn't so documented
+												  // Account appears optional, even though it isn't so documented
 												  accountData ? (UInt32)[accountData length] : 0,
 												  accountData ? [accountData bytes]  : NULL,
-												  //path appears optional, even though it isn't so documented
+												  // Path appears optional, even though it isn't so documented
 												  pathData ? (UInt32)[pathData length] : 0,
 												  pathData ? [pathData bytes]  : NULL,
 												  port,
@@ -610,6 +707,7 @@
 
 	if (outError) {
 		NSError *error = nil;
+		
 		if (err != noErr) {
 			NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
 				[NSValue valueWithPointer:SecKeychainAddInternetPassword], AIKEYCHAIN_ERROR_USERINFO_SECURITYFUNCTION,
@@ -624,31 +722,34 @@
 				nil];
 			error = [NSError errorWithDomain:AIKEYCHAIN_ERROR_DOMAIN code:err userInfo:userInfo];
 		}
+
 		*outError = error;




More information about the commits mailing list