[gnome-keyring/dbus-api] [gck, secret-store, user-store] Rename GckLogin to GckSecret.
- From: Stefan Walter <stefw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-keyring/dbus-api] [gck, secret-store, user-store] Rename GckLogin to GckSecret.
- Date: Fri, 7 Aug 2009 19:47:55 +0000 (UTC)
commit 083f9078bf23a3507080cdde5a6395ec8291152e
Author: Stefan Walter <Stefan Walter>
Date: Fri Aug 7 19:47:04 2009 +0000
[gck, secret-store, user-store] Rename GckLogin to GckSecret.
We can use the GckLogin class for more stuff like holding keyring
secrets etc... Rename and fine tune methods.
pkcs11/gck/gck-secret.c | 167 ++++++++++++++++++++
pkcs11/gck/gck-secret.h | 64 ++++++++
.../{unit-test-login.c => unit-test-secret.c} | 0
3 files changed, 231 insertions(+), 0 deletions(-)
---
diff --git a/pkcs11/gck/gck-secret.c b/pkcs11/gck/gck-secret.c
new file mode 100644
index 0000000..31e5a41
--- /dev/null
+++ b/pkcs11/gck/gck-secret.c
@@ -0,0 +1,167 @@
+/*
+ * gnome-keyring
+ *
+ * Copyright (C) 2008 Stefan Walter
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "gck-secret.h"
+
+#include "egg/egg-secure-memory.h"
+
+#include <string.h>
+
+struct _GckSecret {
+ GObject parent;
+ gchar *data;
+ gsize n_data;
+};
+
+G_DEFINE_TYPE (GckSecret, gck_secret, G_TYPE_OBJECT);
+
+/* -----------------------------------------------------------------------------
+ * OBJECT
+ */
+
+static void
+gck_secret_init (GckSecret *self)
+{
+
+}
+
+static void
+gck_secret_dispose (GObject *obj)
+{
+ GckSecret *self = GCK_SECRET (obj);
+
+ egg_secure_strfree (self->data);
+ self->data = NULL;
+ self->n_data = 0;
+
+ G_OBJECT_CLASS (gck_secret_parent_class)->dispose (obj);
+}
+
+static void
+gck_secret_finalize (GObject *obj)
+{
+ GckSecret *self = GCK_SECRET (obj);
+
+ g_assert (!self->data);
+ g_assert (!self->n_data);
+
+ G_OBJECT_CLASS (gck_secret_parent_class)->finalize (obj);
+}
+
+static void
+gck_secret_set_property (GObject *obj, guint prop_id, const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gck_secret_get_property (GObject *obj, guint prop_id, GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gck_secret_class_init (GckSecretClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->dispose = gck_secret_dispose;
+ gobject_class->finalize = gck_secret_finalize;
+ gobject_class->set_property = gck_secret_set_property;
+ gobject_class->get_property = gck_secret_get_property;
+}
+
+/* -----------------------------------------------------------------------------
+ * PUBLIC
+ */
+
+GckSecret*
+gck_secret_new (const guchar *data, gssize n_data)
+{
+ GckSecret *secret = g_object_new (GCK_TYPE_SECRET, NULL);
+
+ if (data) {
+ if (n_data == -1) {
+ secret->data = egg_secure_strdup ((const gchar*)data);
+ secret->n_data = strlen (secret->data);
+ } else {
+ secret->data = egg_secure_alloc (n_data + 1);
+ memcpy (secret->data, data, n_data);
+ secret->n_data = n_data;
+ }
+ } else {
+ secret->data = NULL;
+ secret->n_data = 0;
+ }
+
+ return secret;
+}
+
+GckSecret*
+gck_secret_new_from_login (CK_UTF8CHAR_PTR pin, CK_ULONG n_pin)
+{
+ if (n_pin == (CK_ULONG)-1)
+ return gck_secret_new ((const guchar*)pin, -1);
+ else
+ return gck_secret_new ((const guchar*)pin, (gssize)n_pin);
+}
+
+const gchar*
+gck_secret_get_password (GckSecret *self, gsize *n_data)
+{
+ g_return_val_if_fail (GCK_IS_SECRET (self), NULL);
+ g_return_val_if_fail (n_data, NULL);
+ *n_data = self->n_data;
+ return self->data;
+}
+
+gboolean
+gck_secret_equals (GckSecret *self, const guchar* pin, gssize n_pin)
+{
+ g_return_val_if_fail (GCK_IS_SECRET (self), FALSE);
+
+ /* In case they're different somewhere */
+ if (n_pin == (CK_ULONG)-1)
+ n_pin = -1;
+
+ if (n_pin == -1 && pin != NULL)
+ n_pin = strlen ((const gchar*)pin);
+
+ if (n_pin != self->n_data)
+ return FALSE;
+ if (!pin && !self->data)
+ return TRUE;
+ if (!pin || !self->data)
+ return FALSE;
+ return memcmp (pin, self->data, n_pin) == 0;
+}
diff --git a/pkcs11/gck/gck-secret.h b/pkcs11/gck/gck-secret.h
new file mode 100644
index 0000000..6101a33
--- /dev/null
+++ b/pkcs11/gck/gck-secret.h
@@ -0,0 +1,64 @@
+/*
+ * gnome-keyring
+ *
+ * Copyright (C) 2008 Stefan Walter
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef __GCK_SECRET_H__
+#define __GCK_SECRET_H__
+
+#include <glib-object.h>
+
+#include "gck-types.h"
+
+#include "pkcs11/pkcs11.h"
+
+#define GCK_TYPE_SECRET (gck_secret_get_type ())
+#define GCK_SECRET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCK_TYPE_SECRET, GckSecret))
+#define GCK_SECRET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCK_TYPE_SECRET, GckSecretClass))
+#define GCK_IS_SECRET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCK_TYPE_SECRET))
+#define GCK_IS_SECRET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCK_TYPE_SECRET))
+#define GCK_SECRET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GCK_TYPE_SECRET, GckSecretClass))
+
+typedef struct _GckSecretClass GckSecretClass;
+
+struct _GckSecretClass {
+ GObjectClass parent_class;
+};
+
+GType gck_secret_get_type (void);
+
+GckSecret* gck_secret_new (const guchar *data,
+ gssize n_data);
+
+GckSecret* gck_secret_new_from_login (CK_UTF8CHAR_PTR pin,
+ CK_ULONG n_pin);
+
+GckSecret* gck_secret_new_from_password (const gchar *password);
+
+const guchar* gck_secret_get (GckSecret *self,
+ gsize *n_data);
+
+const gchar* gck_secret_get_password (GckSecret *self,
+ gsize *n_pin);
+
+gboolean gck_secret_equals (GckSecret *self,
+ const guchar *data,
+ gssize n_data);
+
+#endif /* __GCK_SECRET_H__ */
diff --git a/pkcs11/gck/tests/unit-test-login.c b/pkcs11/gck/tests/unit-test-secret.c
similarity index 100%
rename from pkcs11/gck/tests/unit-test-login.c
rename to pkcs11/gck/tests/unit-test-secret.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]