// FindAndRemoveGenericPassword finds a generic password with the // given attributes in the default keychain and removes it if // found. If not found, an error is returned. func FindAndRemoveGenericPassword(attributes *GenericPasswordAttributes) error { itemRef, err := findGenericPasswordItem(attributes) if err != nil { return err } defer C.CFRelease(C.CFTypeRef(itemRef)) errCode := C.SecKeychainItemDelete(itemRef) return newKeychainError(errCode) }
func (*keychainOSX) DeletePassword(service, account string) error { // Validate input serviceValid := isValidNonNullUTF8(service) accountValid := isValidNonNullUTF8(account) if !(serviceValid && accountValid) { return ErrInvalidValue } // Convert values to C strings serviceCStr := C.CString(service) defer C.free(unsafe.Pointer(serviceCStr)) accountCStr := C.CString(account) defer C.free(unsafe.Pointer(accountCStr)) // Grab the item var item C.SecKeychainItemRef status := C.SecKeychainFindGenericPassword( nil, C.UInt32(len(service)), serviceCStr, C.UInt32(len(account)), accountCStr, nil, nil, &item, ) // Check for errors if status != C.errSecSuccess { return ErrNotFound } // Delete the item status = C.SecKeychainItemDelete(item) // Free the item C.CFRelease(C.CFTypeRef(item)) // Check for errors if status != C.errSecSuccess { return ErrUnknown } // All done return nil }
// DeleteItemRef deletes a keychain item reference. func DeleteItemRef(ref C.CFTypeRef) error { errCode := C.SecKeychainItemDelete(C.SecKeychainItemRef(ref)) return checkError(errCode) }