Descriptive Error Messages for the Security Framework
Friday, May 19, 2006
Have you ever wondered how to translate OSStatus codes like -9612 from e.g. SSLHandshake() to something user presentable using Cocoa?
Here is how!
NSString* OPStringForSecErrorCode(OSStatus status)
/*" Returns the error string from the SecErrorMessages.strings
file found in the Security.framework bundle for the error (status)
code given. "*/
{
NSBundle* secBundle = [NSBundle bundleWithIdentifier: @"com.apple.security"];
// Convert status to Int32 string representation, e.g. "-25924":
NSString* keyString = [NSString stringWithFormat: @"%d", status];
NSString* errorString = [secBundle localizedStringForKey: keyString
value: keyString
table: @"SecErrorMessages"];
return errorString;
}
This code is also part of the BSD-licensed OPNetwork.framework (OPSSLSocket class).
Have fun!
Dirk