[gcr/wip/gcr4] gck: Make GckPassword final



commit ecbc75edfeb66d5aaf2a3d8d25726c0a0ddf1ea0
Author: Corentin Noël <corentin noel collabora com>
Date:   Thu Oct 7 15:39:16 2021 +0200

    gck: Make GckPassword final
    
    There is currently no need to derive it.

 gck/gck-password.c | 53 +++++++++++++++++++++++++++--------------------------
 gck/gck-password.h | 36 +++++++-----------------------------
 2 files changed, 34 insertions(+), 55 deletions(-)
---
diff --git a/gck/gck-password.c b/gck/gck-password.c
index 717c5ca..9e5aeea 100644
--- a/gck/gck-password.c
+++ b/gck/gck-password.c
@@ -1,4 +1,3 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 /* gck-password.c - the GObject PKCS#11 wrapper library
 
    Copyright (C) 2011 Collabora Ltd.
@@ -59,17 +58,19 @@ enum {
        PROP_KEY
 };
 
-struct _GckPasswordPrivate {
+struct _GckPassword
+{
+       GObject parent_instance;
+
        gboolean for_token;
        gpointer token_or_key;
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (GckPassword, gck_password, G_TYPE_TLS_PASSWORD);
+G_DEFINE_TYPE (GckPassword, gck_password, G_TYPE_TLS_PASSWORD);
 
 static void
 gck_password_init (GckPassword *self)
 {
-       self->pv = gck_password_get_instance_private (self);
 }
 
 static void
@@ -79,8 +80,8 @@ gck_password_constructed (GObject *obj)
 
        G_OBJECT_CLASS (gck_password_parent_class)->constructed (obj);
 
-       g_return_if_fail (GCK_IS_SLOT (self->pv->token_or_key) ||
-                         GCK_IS_OBJECT (self->pv->token_or_key));
+       g_return_if_fail (GCK_IS_SLOT (self->token_or_key) ||
+                         GCK_IS_OBJECT (self->token_or_key));
 }
 
 static void
@@ -122,17 +123,17 @@ gck_password_set_property (GObject *obj,
        case PROP_TOKEN:
                object = g_value_dup_object (value);
                if (object != NULL) {
-                       g_assert (self->pv->token_or_key == NULL);
-                       self->pv->token_or_key = object;
-                       self->pv->for_token = TRUE;
+                       g_assert (self->token_or_key == NULL);
+                       self->token_or_key = object;
+                       self->for_token = TRUE;
                }
                break;
        case PROP_KEY:
                object = g_value_dup_object (value);
                if (object != NULL) {
-                       g_assert (self->pv->token_or_key == NULL);
-                       self->pv->token_or_key = object;
-                       self->pv->for_token = FALSE;
+                       g_assert (self->token_or_key == NULL);
+                       self->token_or_key = object;
+                       self->for_token = FALSE;
                }
                break;
        default:
@@ -146,7 +147,7 @@ gck_password_finalize (GObject *obj)
 {
        GckPassword *self = GCK_PASSWORD (obj);
 
-       g_clear_object (&self->pv->token_or_key);
+       g_clear_object (&self->token_or_key);
 
        G_OBJECT_CLASS (gck_password_parent_class)->finalize (obj);
 }
@@ -204,10 +205,10 @@ GckModule *
 gck_password_get_module (GckPassword *self)
 {
        g_return_val_if_fail (GCK_IS_PASSWORD (self), NULL);
-       if (self->pv->for_token)
-               return gck_slot_get_module (self->pv->token_or_key);
+       if (self->for_token)
+               return gck_slot_get_module (self->token_or_key);
        else
-               return gck_object_get_module (self->pv->token_or_key);
+               return gck_object_get_module (self->token_or_key);
 }
 
 /**
@@ -217,17 +218,17 @@ gck_password_get_module (GckPassword *self)
  * If the password request is to unlock a PKCS\#11 token, then this is the
  * slot containing that token.
  *
- * Returns: (transfer full): the slot that contains the token, or %NULL if not
- *          being requested for a token; must be unreferenced after use
+ * Returns: (transfer full) (nullable): the slot that contains the token, or
+ *          %NULL if not being requested for a token.
  */
 GckSlot *
 gck_password_get_token (GckPassword *self)
 {
        g_return_val_if_fail (GCK_IS_PASSWORD (self), NULL);
-       if (!self->pv->for_token)
+       if (!self->for_token)
                return NULL;
-       g_return_val_if_fail (GCK_IS_SLOT (self->pv->token_or_key), NULL);
-       return g_object_ref (self->pv->token_or_key);
+       g_return_val_if_fail (GCK_IS_SLOT (self->token_or_key), NULL);
+       return g_object_ref (self->token_or_key);
 }
 
 /**
@@ -237,15 +238,15 @@ gck_password_get_token (GckPassword *self)
  * If the password request is to unlock a PKCS\#11 key, then this is the
  * the object representing that key.
  *
- * Returns: (transfer full): the password is for this key, or %NULL if not
- *          being requested for a key; must be unreferenced after use
+ * Returns: (transfer full) (nullable): the password is for this key, or %NULL
+ *          if not being requested for a key
  */
 GckObject *
 gck_password_get_key (GckPassword *self)
 {
        g_return_val_if_fail (GCK_IS_PASSWORD (self), NULL);
-       if (self->pv->for_token)
+       if (self->for_token)
                return NULL;
-       g_return_val_if_fail (GCK_IS_OBJECT (self->pv->token_or_key), NULL);
-       return g_object_ref (self->pv->token_or_key);
+       g_return_val_if_fail (GCK_IS_OBJECT (self->token_or_key), NULL);
+       return g_object_ref (self->token_or_key);
 }
diff --git a/gck/gck-password.h b/gck/gck-password.h
index 34f36d2..d47c2b3 100644
--- a/gck/gck-password.h
+++ b/gck/gck-password.h
@@ -12,36 +12,16 @@
 #endif
 
 #include <glib-object.h>
+#include <gio/gio.h>
 
-G_BEGIN_DECLS
-
-#define GCK_TYPE_PASSWORD             (gck_password_get_type ())
-#define GCK_PASSWORD(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCK_TYPE_PASSWORD, GckPassword))
-#define GCK_PASSWORD_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GCK_TYPE_PASSWORD, GckPassword))
-#define GCK_IS_PASSWORD(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCK_TYPE_PASSWORD))
-#define GCK_IS_PASSWORD_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GCK_TYPE_PASSWORD))
-#define GCK_PASSWORD_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GCK_TYPE_PASSWORD, 
GckPasswordClass))
-
-typedef struct _GckPassword GckPassword;
-typedef struct _GckPasswordClass GckPasswordClass;
-typedef struct _GckPasswordPrivate GckPasswordPrivate;
-
-struct _GckPassword {
-       GTlsPassword parent;
+#include <gck/gck-module.h>
+#include <gck/gck-slot.h>
+#include <gck/gck-object.h>
 
-       /*< private >*/
-       GckPasswordPrivate *pv;
-       gpointer reserved[4];
-};
-
-struct _GckPasswordClass {
-       GTlsPasswordClass parent;
-
-       /*< private >*/
-       gpointer reserved[4];
-};
+G_BEGIN_DECLS
 
-GType               gck_password_get_type                   (void) G_GNUC_CONST;
+#define GCK_TYPE_PASSWORD gck_password_get_type ()
+G_DECLARE_FINAL_TYPE (GckPassword, gck_password, GCK, PASSWORD, GTlsPassword)
 
 GckModule *         gck_password_get_module                 (GckPassword *self);
 
@@ -49,8 +29,6 @@ GckSlot *           gck_password_get_token                  (GckPassword *self);
 
 GckObject *         gck_password_get_key                    (GckPassword *self);
 
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (GckPassword, g_object_unref);
-
 G_END_DECLS
 
 #endif /* __GCK_PASSWORD_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]