[libsecret/wip/dueno/simple-item: 4/7] secret-password: Add lookup_binary functions
- From: Daiki Ueno <dueno src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsecret/wip/dueno/simple-item: 4/7] secret-password: Add lookup_binary functions
- Date: Sat, 29 Jun 2019 05:40:47 +0000 (UTC)
commit ab83c023dd6d762a07032027dc0ec726e1cc728f
Author: Daiki Ueno <dueno src gnome org>
Date: Thu Jun 20 06:55:37 2019 +0200
secret-password: Add lookup_binary functions
This adds a set of functions that return a SecretValue instead of a
text password when looking up a secret. This is useful if the stored
password is not null-terminated.
libsecret/secret-password.c | 119 ++++++++++++++++++++++++++++++++++++++++++++
libsecret/secret-password.h | 63 +++++++++++++----------
2 files changed, 156 insertions(+), 26 deletions(-)
---
diff --git a/libsecret/secret-password.c b/libsecret/secret-password.c
index 640519e..855ddcd 100644
--- a/libsecret/secret-password.c
+++ b/libsecret/secret-password.c
@@ -407,6 +407,25 @@ secret_password_lookup_nonpageable_finish (GAsyncResult *result,
return _secret_value_unref_to_password (value);
}
+/**
+ * secret_password_lookup_binary_finish: (skip)
+ * @result: the asynchronous result passed to the callback
+ * @error: location to place an error on failure
+ *
+ * Finish an asynchronous operation to lookup a password in the secret service.
+ *
+ * Returns: (transfer full): a newly allocated #SecretValue, which should be
+ * released with secret_value_unref(), or %NULL if no secret found
+ */
+SecretValue *
+secret_password_lookup_binary_finish (GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ return secret_service_lookup_finish (NULL, result, error);
+}
+
/**
* secret_password_lookup_finish:
* @result: the asynchronous result passed to the callback
@@ -589,6 +608,106 @@ secret_password_lookupv_nonpageable_sync (const SecretSchema *schema,
return password;
}
+/**
+ * secret_password_lookup_binary_sync: (skip)
+ * @schema: the schema for the attributes
+ * @cancellable: optional cancellation object
+ * @error: location to place an error on failure
+ * @...: the attribute keys and values, terminated with %NULL
+ *
+ * Lookup a password in the secret service.
+ *
+ * This is similar to secret_password_lookup_sync(), but returns a
+ * #SecretValue instead of a null-terminated password.
+ *
+ * This method may block indefinitely and should not be used in user interface
+ * threads.
+ *
+ * Returns: (transfer full): a newly allocated #SecretValue, which should be
+ * released with secret_value_unref(), or %NULL if no secret found
+ */
+SecretValue *
+secret_password_lookup_binary_sync (const SecretSchema *schema,
+ GCancellable *cancellable,
+ GError **error,
+ ...)
+{
+ GHashTable *attributes;
+ SecretValue *value;
+ va_list va;
+
+ g_return_val_if_fail (schema != NULL, NULL);
+ g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ va_start (va, error);
+ attributes = secret_attributes_buildv (schema, va);
+ va_end (va);
+
+ /* Precondition failed, already warned */
+ if (!attributes)
+ return NULL;
+
+ value = secret_password_lookupv_binary_sync (schema, attributes,
+ cancellable, error);
+
+ g_hash_table_unref (attributes);
+
+ return value;
+}
+
+/**
+ * secret_password_lookupv_binary_sync: (skip)
+ * @schema: the schema for attributes
+ * @attributes: (element-type utf8 utf8): the attribute keys and values
+ * @cancellable: optional cancellation object
+ * @error: location to place an error on failure
+ *
+ * Lookup a password in the secret service.
+ *
+ * This is similar to secret_password_lookupv_sync(), but returns a
+ * #SecretValue instead of a null-terminated password.
+ *
+ * This method may block indefinitely and should not be used in user interface
+ * threads.
+ *
+ * Returns: (transfer full): a newly allocated #SecretValue, which should be
+ * released with secret_value_unref(), or %NULL if no secret found
+ */
+SecretValue *
+secret_password_lookupv_binary_sync (const SecretSchema *schema,
+ GHashTable *attributes,
+ GCancellable *cancellable,
+ GError **error)
+{
+ SecretSync *sync;
+ SecretValue *value;
+
+ g_return_val_if_fail (schema != NULL, NULL);
+ g_return_val_if_fail (attributes != NULL, NULL);
+ g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ /* Warnings raised already */
+ if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
+ return FALSE;
+
+ sync = _secret_sync_new ();
+ g_main_context_push_thread_default (sync->context);
+
+ secret_password_lookupv (schema, attributes, cancellable,
+ _secret_sync_on_result, sync);
+
+ g_main_loop_run (sync->loop);
+
+ value = secret_password_lookup_binary_finish (sync->result, error);
+
+ g_main_context_pop_thread_default (sync->context);
+ _secret_sync_free (sync);
+
+ return value;
+}
+
/**
* secret_password_lookupv_sync: (rename-to secret_password_lookup_sync)
* @schema: the schema for attributes
diff --git a/libsecret/secret-password.h b/libsecret/secret-password.h
index 725d11b..36cc18d 100644
--- a/libsecret/secret-password.h
+++ b/libsecret/secret-password.h
@@ -25,8 +25,9 @@ G_BEGIN_DECLS
#include "secret-schema.h"
#include "secret-types.h"
+#include "secret-value.h"
-void secret_password_store (const SecretSchema *schema,
+void secret_password_store (const SecretSchema *schema,
const gchar *collection,
const gchar *label,
const gchar *password,
@@ -35,7 +36,7 @@ void secret_password_store (const SecretSchema *sche
gpointer user_data,
...) G_GNUC_NULL_TERMINATED;
-void secret_password_storev (const SecretSchema *schema,
+void secret_password_storev (const SecretSchema *schema,
GHashTable *attributes,
const gchar *collection,
const gchar *label,
@@ -44,10 +45,10 @@ void secret_password_storev (const SecretSchema *sche
GAsyncReadyCallback callback,
gpointer user_data);
-gboolean secret_password_store_finish (GAsyncResult *result,
+gboolean secret_password_store_finish (GAsyncResult *result,
GError **error);
-gboolean secret_password_store_sync (const SecretSchema *schema,
+gboolean secret_password_store_sync (const SecretSchema *schema,
const gchar *collection,
const gchar *label,
const gchar *password,
@@ -55,7 +56,7 @@ gboolean secret_password_store_sync (const SecretSchema *sche
GError **error,
...) G_GNUC_NULL_TERMINATED;
-gboolean secret_password_storev_sync (const SecretSchema *schema,
+gboolean secret_password_storev_sync (const SecretSchema *schema,
GHashTable *attributes,
const gchar *collection,
const gchar *label,
@@ -63,101 +64,111 @@ gboolean secret_password_storev_sync (const SecretSchema *sche
GCancellable *cancellable,
GError **error);
-void secret_password_lookup (const SecretSchema *schema,
+void secret_password_lookup (const SecretSchema *schema,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data,
...) G_GNUC_NULL_TERMINATED;
-void secret_password_lookupv (const SecretSchema *schema,
+void secret_password_lookupv (const SecretSchema *schema,
GHashTable *attributes,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
-gchar * secret_password_lookup_finish (GAsyncResult *result,
+gchar * secret_password_lookup_finish (GAsyncResult *result,
GError **error);
-gchar * secret_password_lookup_nonpageable_finish (GAsyncResult *result,
- GError **error);
+gchar * secret_password_lookup_nonpageable_finish (GAsyncResult *result,
+ GError **error);
+SecretValue *secret_password_lookup_binary_finish (GAsyncResult *result,
+ GError **error);
-gchar * secret_password_lookup_sync (const SecretSchema *schema,
+gchar * secret_password_lookup_sync (const SecretSchema *schema,
GCancellable *cancellable,
GError **error,
...) G_GNUC_NULL_TERMINATED;
-gchar * secret_password_lookup_nonpageable_sync (const SecretSchema *schema,
+gchar * secret_password_lookup_nonpageable_sync (const SecretSchema *schema,
GCancellable *cancellable,
GError **error,
...);
+SecretValue *secret_password_lookup_binary_sync (const SecretSchema *schema,
+ GCancellable *cancellable,
+ GError **error,
+ ...);
-gchar * secret_password_lookupv_sync (const SecretSchema *schema,
+gchar * secret_password_lookupv_sync (const SecretSchema *schema,
GHashTable *attributes,
GCancellable *cancellable,
GError **error);
-gchar * secret_password_lookupv_nonpageable_sync (const SecretSchema *schema,
+gchar * secret_password_lookupv_nonpageable_sync (const SecretSchema *schema,
GHashTable *attributes,
GCancellable *cancellable,
GError **error);
+SecretValue *secret_password_lookupv_binary_sync (const SecretSchema *schema,
+ GHashTable *attributes,
+ GCancellable *cancellable,
+ GError **error);
-void secret_password_clear (const SecretSchema *schema,
+void secret_password_clear (const SecretSchema *schema,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data,
...) G_GNUC_NULL_TERMINATED;
-void secret_password_clearv (const SecretSchema *schema,
+void secret_password_clearv (const SecretSchema *schema,
GHashTable *attributes,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
-gboolean secret_password_clear_finish (GAsyncResult *result,
+gboolean secret_password_clear_finish (GAsyncResult *result,
GError **error);
-gboolean secret_password_clear_sync (const SecretSchema* schema,
+gboolean secret_password_clear_sync (const SecretSchema* schema,
GCancellable *cancellable,
GError **error,
...) G_GNUC_NULL_TERMINATED;
-gboolean secret_password_clearv_sync (const SecretSchema *schema,
+gboolean secret_password_clearv_sync (const SecretSchema *schema,
GHashTable *attributes,
GCancellable *cancellable,
GError **error);
-void secret_password_search (const SecretSchema *schema,
+void secret_password_search (const SecretSchema *schema,
SecretSearchFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data,
...) G_GNUC_NULL_TERMINATED;
-void secret_password_searchv (const SecretSchema *schema,
+void secret_password_searchv (const SecretSchema *schema,
GHashTable *attributes,
SecretSearchFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
-GList * secret_password_search_sync (const SecretSchema *schema,
+GList * secret_password_search_sync (const SecretSchema *schema,
SecretSearchFlags flags,
GCancellable *cancellable,
GError **error,
...) G_GNUC_NULL_TERMINATED;
-GList * secret_password_searchv_sync (const SecretSchema *schema,
+GList * secret_password_searchv_sync (const SecretSchema *schema,
GHashTable *attributes,
SecretSearchFlags flags,
GCancellable *cancellable,
GError **error);
-GList * secret_password_search_finish (GAsyncResult *result,
+GList * secret_password_search_finish (GAsyncResult *result,
GError **error);
-void secret_password_free (gchar *password);
+void secret_password_free (gchar *password);
-void secret_password_wipe (gchar *password);
+void secret_password_wipe (gchar *password);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]