carlbrown/PDKeychainBindingsController

removeObjectForKey: gives "Could not store(Delete) string. Error was:-25300"

evgeniyd opened this issue · 4 comments

Calling

[[PDKeychainBindings sharedKeychainBindings] removeObjectForKey:@"myKey"];

returns

Could not store(Delete) string. Error was:-25300

While investigating it, I've found that this is a custom NSLog string, logged when the following operation fails:

OSStatus result=SecItemDelete((__bridge CFDictionaryRef)spec);
if (result!=0) {
    NSLog(@"Could not store(Delete) string. Error was:%i",(int)result);
}

The error code from OSStatus enum declared in <Security/SecBase.h>has this description:

errSecItemNotFound = -25300,  /* The specified item could not be found in the keychain. */

...which points out, that it's just the value being not found for respective key upon deleting.

Question

I wonder, what option here would be more preferable?

  1. I have to check for key existence, before attempting to delete it?
  2. The PDKeychainBindingsController has to have a fix to check the key, before deleting
  3. The PDKeychainBindingsController has to have a fix to make error codes processing and logging more accurate
  4. Ignore everything here (which was the way, it worked before this bug report was submitted)

FYI. So far, my workaround:

if ([[PDKeychainBindings sharedKeychainBindings] objectForKey:@"myKey"]) {
    [[PDKeychainBindings sharedKeychainBindings] removeObjectForKey:@"myKey"];
}

@evgeniyd have you tried adding Keychain Sharing in your capabilities (entitlements) file? See here

Interesting, I've tried the testing for the existence of the key as you've suggested but I still get the same crash and error.

@danielkramer hm, I do not have my app crashed upon the error. It is just the message, I don't prefer to be printed to the console.
Do you see the same log message?