Jens Alfke  committed da03419

MyErrorUtils fixes: Renamed USE_SECURITY_API compiler flag to MYERRORUTILS_USE_SECURITY_API. Documented it in the header. Conditionalized the test cases that fail when it's not enabled.

  • Participants
  • Parent commits ce3254b
  • Branches master

Comments (0)

Files changed (2)

File MYErrorUtils.h

 BOOL MYMiscError( NSError **outError, NSString *messageFormat, ... )
                                 __attribute__ ((format (__NSString__, 2, 3)));
+/** Utilities for converting NSErrors to user-readable (but geeky) strings.
+    If your code uses Security or SSL APIs, you will probably want to #define
+    the symbol MYERRORUTILS_USE_SECURITY_API in your precompiled header, which
+    will enable the implementations of these functions to call Security API to
+    look up error messages. (This is turned off by default because it creates
+    a dependency on linking against Security.framework.)
+ */
 NSString* MYPrintableErrorCode( int code );
 NSString* MYErrorName( NSString *domain, int code );

File MYErrorUtils.m

 #import "CollectionUtils.h"
 #import <Foundation/Foundation.h>
 #import <Security/SecBase.h>
         if (name && *name)
             result = [NSString stringWithCString: name encoding: NSMacOSRomanStringEncoding];
         else {
             result = (id) SecCopyErrorMessageString(code,NULL);
             if (result) {
                 [NSMakeCollectable(result) autorelease];
     CAssertEqual(err.my_nameOfCode, @"fnfErr (OSStatus -43)");
     err = [NSError errorWithDomain: NSOSStatusErrorDomain code: -25291 userInfo: nil];
     CAssertEqual(err.my_nameOfCode, @"errKCNotAvailable / errSecNotAvailable (OSStatus -25291)");
     err = [NSError errorWithDomain: NSOSStatusErrorDomain code: -25260 userInfo: nil];
     CAssertEqual(err.my_nameOfCode, @"Passphrase is required for import/export. (OSStatus -25260)");
     err = [NSError errorWithDomain: NSOSStatusErrorDomain code: 12345 userInfo: nil];
     CAssertEqual(err.my_nameOfCode, @"OSStatus 12345");
     err = [NSError errorWithDomain: @"CSSMErrorDomain" code: 2147549184u userInfo: nil];
     CAssertEqual(err.my_nameOfCode, @"CSSM_CSSM_BASE_ERROR (CSSM 2147549184)");
+    // If that assertion fails, you probably need to add MYError_CSSMErrorDomain.strings to your target.
+    CAssertEqual(err.my_nameOfCode, @"CSSM 2147549184");
     err = [NSError errorWithDomain: (id)kCFErrorDomainCocoa code: 100 userInfo: nil];
     CAssertEqual(err.my_nameOfCode, @"Cocoa 100");