Re: KCAddGenericPassword()
Re: KCAddGenericPassword()
- Subject: Re: KCAddGenericPassword()
- From: Bill Bumgarner <email@hidden>
- Date: Mon, 28 Jan 2002 11:50:26 -0500
Found it! From the documentation of KCAddGenericPassword(). "Deprecated"
was clearly too strong of a word to use in my original post, but
"...provided for convenience only and may be removed..." is still fairly
strong encouragement not to use the API unless it is hard to avoid (which
it isn't-- see below). In any case, this will likely be rendered moot as
the KC* APIs are fully converted to Core in that all of the string
parameters will be of type CFStringRef (which is no-cost bridged to
NSString).
--- cut from KCAddGenericPassword documentation
Available beginning with Keychain Manager 1.0. In Keychain Manager 1.0,
the kcaddgenericpassword function provides the same functionality as
KCAddGenericPassword, except that it accepts C strings rather than Pascal
strings as arguments. In Keychain 2.0, you should use KCAddGenericPassword,
since kcaddgenericpassword is provided for convenience only and may be
removed from the header file at some point in the future.
--- end cut
I used this:
....
serviceNamePtr = [self pascalStringFromString: serviceName];
accountNamePtr = [self pascalStringFromString: accountName];
coreStatus = KCAddGenericPassword(*serviceNamePtr, *accountNamePtr,
strlen(password), password, NULL);
free(serviceNamePtr);
free(accountNamePtr);
if (coreStatus != 0)
[NSException raise: NSInternalInconsistencyException
format: @"Failed to add password to keychain:
%@ / %@ for %@", serviceName, accountName, requestedPassword];
....
Where -pascalStringFromString: is implemented as follows.
- (Str255 *) pascalStringFromString: (NSString *) aString
{
if (aString) {
Str255 *returnString = malloc(sizeof(Str255));
if ( !CFStringGetPascalString( (CFStringRef) aString,
*returnString, sizeof(*returnString), CFStringGetSystemEncoding())) {
free(returnString);
[NSException raise: NSInternalInconsistencyException
format: @"Failed to convert NSString '%@' to
pascal string.", aString];
}
return returnString;
}
return NULL;
}
I believe that is correct and it certainly works (this is all from
SSHPassKey), but I do not remotely claim to be a Carbon expert.
b.bum
On Sunday, January 27, 2002, at 04:59 PM, Andreas Monitzer wrote:
On Sunday, January 27, 2002, at 10:41 , Bill Bumgarner wrote:
Someone responded with a code snippet that uses kcaddgenericpassword.
That
works, but according to the Carbon documentation, kcaddgenericpassword
and the
other APIs that take C strings have been deprecated.
What documentation? There's no note of any deprecation in the headers nor
at
http://developer.apple.com/techpubs/macosx/Carbon/securityservices/keychainmanager/
Keychain_Manager/Functions/Miscellaneou7456789101112.html#//apple_ref/C/func/
kcaddgenericpassword (I like those 3 lines-URLs :-).
andy
b.bum
I ride tandem with the random....
.... things don't happen the way I planned them.