[libsecret/wip/dueno/simple-item: 6/7] secret-value: Add secret_value_unref_to_password
- From: Daiki Ueno <dueno src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsecret/wip/dueno/simple-item: 6/7] secret-value: Add secret_value_unref_to_password
- Date: Sat, 29 Jun 2019 05:40:57 +0000 (UTC)
commit 530c38e30a1ae3e381e122582dc7275ce1d23bb6
Author: Daiki Ueno <dueno src gnome org>
Date: Thu Jun 20 06:55:56 2019 +0200
secret-value: Add secret_value_unref_to_password
This adds the secret_value_unref_to_password function that
unreferences and returns the stored secret in non-pageable memory.
This is supposed to be used with secret_password_lookup_binary*
functions.
libsecret/secret-value.c | 38 ++++++++++++++++++++++++++++++++------
libsecret/secret-value.h | 3 +++
2 files changed, 35 insertions(+), 6 deletions(-)
---
diff --git a/libsecret/secret-value.c b/libsecret/secret-value.c
index ca891cb..ce4ebee 100644
--- a/libsecret/secret-value.c
+++ b/libsecret/secret-value.c
@@ -256,38 +256,64 @@ is_password_value (SecretValue *value)
return FALSE;
}
+/**
+ * secret_value_unref_to_password:
+ * @value: the value
+ * @length: the length of the secret
+ *
+ * Unreference a #SecretValue and steal the secret data in
+ * #SecretValue as nonpageable memory.
+ *
+ * Returns: (transfer full): a new password string stored in nonpageable memory
+ * which must be freed with secret_password_free() when done
+ */
gchar *
-_secret_value_unref_to_password (SecretValue *value)
+secret_value_unref_to_password (SecretValue *value,
+ gsize *length)
{
SecretValue *val = value;
gchar *result;
g_return_val_if_fail (value != NULL, NULL);
- if (!is_password_value (value)) {
- secret_value_unref (value);
- return NULL;
- }
-
if (g_atomic_int_dec_and_test (&val->refs)) {
if (val->destroy == egg_secure_free) {
result = val->secret;
+ if (length)
+ *length = val->length;
} else {
result = egg_secure_strndup (val->secret, val->length);
if (val->destroy)
(val->destroy) (val->secret);
+ if (length)
+ *length = val->length;
}
g_free (val->content_type);
g_slice_free (SecretValue, val);
} else {
result = egg_secure_strndup (val->secret, val->length);
+ if (length)
+ *length = val->length;
}
return result;
}
+gchar *
+_secret_value_unref_to_password (SecretValue *value)
+{
+ g_return_val_if_fail (value != NULL, NULL);
+
+ if (!is_password_value (value)) {
+ secret_value_unref (value);
+ return NULL;
+ }
+
+ return secret_value_unref_to_password (value, NULL);
+}
+
gchar *
_secret_value_unref_to_string (SecretValue *value)
{
diff --git a/libsecret/secret-value.h b/libsecret/secret-value.h
index 43b0e09..7699c08 100644
--- a/libsecret/secret-value.h
+++ b/libsecret/secret-value.h
@@ -51,6 +51,9 @@ SecretValue * secret_value_ref (SecretValue *value);
void secret_value_unref (gpointer value);
+gchar * secret_value_unref_to_password (SecretValue *value,
+ gsize *length);
+
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SecretValue, secret_value_unref)
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]