public @Override char[] read(String key) { Pointer[] found = new Pointer[1]; Pointer attributes = LIBRARY.g_array_new(0, 0, GnomeKeyringAttribute_SIZE); try { LIBRARY.gnome_keyring_attribute_list_append_string(attributes, KEY, key); error( GnomeKeyringLibrary.LIBRARY.gnome_keyring_find_items_sync( GNOME_KEYRING_ITEM_GENERIC_SECRET, attributes, found)); } finally { LIBRARY.gnome_keyring_attribute_list_free(attributes); } if (found[0] != null) { try { if (LIBRARY.g_list_length(found[0]) > 0) { GnomeKeyringFound result = LIBRARY.g_list_nth_data(found[0], 0); if (result != null) { if (result.secret != null) { return result.secret.toCharArray(); } else { LOG.warning("#183670: GnomeKeyringFound.secret == null"); delete(key); } } else { LOG.warning("#183670: GList<GnomeKeyringFound>[0].result == null"); } } } finally { LIBRARY.gnome_keyring_found_list_free(found[0]); } } return null; }
public @Override void delete(String key) { Pointer[] found = new Pointer[1]; Pointer attributes = LIBRARY.g_array_new(0, 0, GnomeKeyringAttribute_SIZE); try { LIBRARY.gnome_keyring_attribute_list_append_string(attributes, KEY, key); error( GnomeKeyringLibrary.LIBRARY.gnome_keyring_find_items_sync( GNOME_KEYRING_ITEM_GENERIC_SECRET, attributes, found)); } finally { LIBRARY.gnome_keyring_attribute_list_free(attributes); } if (found[0] == null) { return; } int id; try { if (LIBRARY.g_list_length(found[0]) > 0) { GnomeKeyringFound result = LIBRARY.g_list_nth_data(found[0], 0); id = result.item_id; } else { id = 0; } } finally { LIBRARY.gnome_keyring_found_list_free(found[0]); } if (id > 0) { if ("SunOS".equals(System.getProperty("os.name")) && "5.10".equals(System.getProperty("os.version"))) { // #185698 save( key, new char[0], null); // gnome_keyring_item_delete(null, id, null, null, null) does not seem to do // anything } else { error(GnomeKeyringLibrary.LIBRARY.gnome_keyring_item_delete_sync(null, id)); } } }
public @Override void save(String key, char[] password, String description) { Pointer attributes = LIBRARY.g_array_new(0, 0, GnomeKeyringAttribute_SIZE); try { LIBRARY.gnome_keyring_attribute_list_append_string(attributes, KEY, key); int[] item_id = new int[1]; error( GnomeKeyringLibrary.LIBRARY.gnome_keyring_item_create_sync( null, GNOME_KEYRING_ITEM_GENERIC_SECRET, description != null ? description : key, attributes, new String(password), true, item_id)); } finally { LIBRARY.gnome_keyring_attribute_list_free(attributes); } }