mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2024-12-22 04:38:55 +00:00
libsecret: Add secret_service_encode_dbus_secret() and opposite
Add secret_service_encode_dbus_secret() and secret_service_decode_dbus_secret() functions for encoding and decoding the Secret Service API DBus structs that carry secrets on the wire. These are not added to the stable or scripting APIs.
This commit is contained in:
parent
ded87c7b32
commit
6b7d643929
@ -289,6 +289,8 @@ secret_service_read_alias_dbus_path_sync
|
||||
secret_service_set_alias_to_dbus_path
|
||||
secret_service_set_alias_to_dbus_path_finish
|
||||
secret_service_set_alias_to_dbus_path_sync
|
||||
secret_service_encode_dbus_secret
|
||||
secret_service_decode_dbus_secret
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
|
@ -2581,3 +2581,62 @@ secret_service_prompt_at_dbus_path_finish (SecretService *self,
|
||||
|
||||
return secret_service_prompt_finish (self, result, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* secret_service_encode_dbus_secret:
|
||||
* @service: the service
|
||||
* @value: the secret value
|
||||
*
|
||||
* Encodes a #SecretValue into GVariant for use with the Secret Service
|
||||
* DBus API.
|
||||
*
|
||||
* The resulting GVariant will have a <literal>(oayays)</literal> signature.
|
||||
*
|
||||
* A session must have already been established by the #SecretService.
|
||||
*
|
||||
* Returns: (transfer floating): the encoded secret
|
||||
*/
|
||||
GVariant *
|
||||
secret_service_encode_dbus_secret (SecretService *service,
|
||||
SecretValue *value)
|
||||
{
|
||||
SecretSession *session;
|
||||
|
||||
g_return_val_if_fail (service != NULL, NULL);
|
||||
g_return_val_if_fail (value != NULL, NULL);
|
||||
|
||||
session = _secret_service_get_session (service);
|
||||
g_return_val_if_fail (session != NULL, NULL);
|
||||
|
||||
return _secret_session_encode_secret (session, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* secret_service_decode_dbus_secret:
|
||||
* @service: the service
|
||||
* @value: the encoded secret
|
||||
*
|
||||
* Decode a #SecretValue into GVariant received with the Secret Service
|
||||
* DBus API.
|
||||
*
|
||||
* The GVariant should have a <literal>(oayays)</literal> signature.
|
||||
*
|
||||
* A session must have already been established by the #SecretService, and
|
||||
* the encoded secret must be valid for that session.
|
||||
*
|
||||
* Returns: (transfer full): the decoded secret value
|
||||
*/
|
||||
SecretValue *
|
||||
secret_service_decode_dbus_secret (SecretService *service,
|
||||
GVariant *value)
|
||||
{
|
||||
SecretSession *session;
|
||||
|
||||
g_return_val_if_fail (service != NULL, NULL);
|
||||
g_return_val_if_fail (value != NULL, NULL);
|
||||
|
||||
session = _secret_service_get_session (service);
|
||||
g_return_val_if_fail (session != NULL, NULL);
|
||||
|
||||
return _secret_session_decode_secret (session, value);
|
||||
}
|
||||
|
@ -272,6 +272,12 @@ gboolean secret_service_set_alias_to_dbus_path_sync (SecretSe
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
GVariant * secret_service_encode_dbus_secret (SecretService *service,
|
||||
SecretValue *value);
|
||||
|
||||
SecretValue * secret_service_decode_dbus_secret (SecretService *service,
|
||||
GVariant *value);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __SECRET_SERVICE_H___ */
|
||||
|
@ -710,6 +710,33 @@ test_set_alias_path (Test *test,
|
||||
g_assert (path == NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
test_encode_decode_secret (Test *test,
|
||||
gconstpointer unused)
|
||||
{
|
||||
GVariant *variant;
|
||||
SecretValue *value;
|
||||
SecretValue *decoded;
|
||||
GError *error = NULL;
|
||||
|
||||
value = secret_value_new ("zerogjuggs", -1, "text/plain");
|
||||
|
||||
secret_service_ensure_session_sync (test->service, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
variant = secret_service_encode_dbus_secret (test->service, value);
|
||||
g_assert (variant != NULL);
|
||||
g_assert_cmpstr (g_variant_get_type_string (variant), ==, "(oayays)");
|
||||
secret_value_unref (value);
|
||||
|
||||
decoded = secret_service_decode_dbus_secret (test->service, variant);
|
||||
g_assert (variant != NULL);
|
||||
g_variant_unref (variant);
|
||||
|
||||
g_assert_cmpstr (secret_value_get_text (decoded), ==, "zerogjuggs");
|
||||
secret_value_unref (decoded);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
@ -746,5 +773,7 @@ main (int argc, char **argv)
|
||||
|
||||
g_test_add ("/service/set-alias-path", Test, "mock-service-normal.py", setup, test_set_alias_path, teardown);
|
||||
|
||||
g_test_add ("/service/encode-decode-secret", Test, "mock-service-normal.py", setup, test_encode_decode_secret, teardown);
|
||||
|
||||
return egg_tests_run_with_loop ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user