mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2024-12-22 04:38:55 +00:00
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.
This commit is contained in:
parent
5fedca8ffc
commit
bac85c00fc
@ -128,6 +128,9 @@ secret_password_lookup_sync
|
||||
secret_password_lookup_nonpageable_sync
|
||||
secret_password_lookupv_sync
|
||||
secret_password_lookupv_nonpageable_sync
|
||||
secret_password_lookup_binary_finish
|
||||
secret_password_lookup_binary_sync
|
||||
secret_password_lookupv_binary_sync
|
||||
secret_password_clear
|
||||
secret_password_clearv
|
||||
secret_password_clear_finish
|
||||
|
@ -407,6 +407,27 @@ 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
|
||||
*
|
||||
* Since: 0.19.0
|
||||
*/
|
||||
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 +610,110 @@ 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
|
||||
*
|
||||
* Since: 0.19.0
|
||||
*/
|
||||
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
|
||||
*
|
||||
* Since: 0.19.0
|
||||
*/
|
||||
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
|
||||
|
@ -25,6 +25,7 @@ G_BEGIN_DECLS
|
||||
|
||||
#include "secret-schema.h"
|
||||
#include "secret-types.h"
|
||||
#include "secret-value.h"
|
||||
|
||||
void secret_password_store (const SecretSchema *schema,
|
||||
const gchar *collection,
|
||||
@ -80,6 +81,8 @@ gchar * secret_password_lookup_finish (GAsyncResult *result,
|
||||
|
||||
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,
|
||||
GCancellable *cancellable,
|
||||
@ -90,6 +93,10 @@ gchar * secret_password_lookup_nonpageable_sync (const SecretSchema *sche
|
||||
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,
|
||||
GHashTable *attributes,
|
||||
@ -100,6 +107,10 @@ gchar * secret_password_lookupv_nonpageable_sync (const SecretSchema *sche
|
||||
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,
|
||||
GCancellable *cancellable,
|
||||
|
Loading…
Reference in New Issue
Block a user