LCOV - code coverage report
Current view: top level - pkcs11/ssh-store - gkm-ssh-public-key.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 46.3 % 54 25
Test Date: 2024-04-08 13:24:42 Functions: 66.7 % 12 8

            Line data    Source code
       1              : /*
       2              :  * gnome-keyring
       3              :  *
       4              :  * Copyright (C) 2008 Stefan Walter
       5              :  *
       6              :  * This program is free software; you can redistribute it and/or modify
       7              :  * it under the terms of the GNU Lesser General Public License as
       8              :  * published by the Free Software Foundation; either version 2.1 of
       9              :  * the License, or (at your option) any later version.
      10              :  *
      11              :  * This program is distributed in the hope that it will be useful, but
      12              :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14              :  * Lesser General Public License for more details.
      15              :  *
      16              :  * You should have received a copy of the GNU Lesser General Public
      17              :  * License along with this program; if not, see
      18              :  * <http://www.gnu.org/licenses/>.
      19              :  */
      20              : 
      21              : #include "config.h"
      22              : 
      23              : #include "gkm-ssh-public-key.h"
      24              : 
      25              : #include "gkm/gkm-attributes.h"
      26              : #include "gkm/gkm-module.h"
      27              : #include "gkm/gkm-object.h"
      28              : #include "gkm/gkm-util.h"
      29              : 
      30              : #include <glib/gi18n.h>
      31              : 
      32              : enum {
      33              :         PROP_0,
      34              :         PROP_LABEL
      35              : };
      36              : 
      37              : struct _GkmSshPublicKey {
      38              :         GkmPublicXsaKey parent;
      39              :         gchar *label;
      40              : };
      41              : 
      42           30 : G_DEFINE_TYPE (GkmSshPublicKey, gkm_ssh_public_key, GKM_TYPE_PUBLIC_XSA_KEY);
      43              : 
      44              : /* -----------------------------------------------------------------------------
      45              :  * OBJECT
      46              :  */
      47              : 
      48              : static CK_RV
      49            0 : gkm_ssh_public_key_get_attribute (GkmObject *base, GkmSession *session, CK_ATTRIBUTE_PTR attr)
      50              : {
      51            0 :         GkmSshPublicKey *self = GKM_SSH_PUBLIC_KEY (base);
      52              : 
      53            0 :         switch (attr->type) {
      54            0 :         case CKA_LABEL:
      55            0 :                 return gkm_attribute_set_string (attr, self->label ? self->label : "");
      56              :         }
      57              : 
      58            0 :         return GKM_OBJECT_CLASS (gkm_ssh_public_key_parent_class)->get_attribute (base, session, attr);
      59              : }
      60              : 
      61              : static void
      62            9 : gkm_ssh_public_key_init (GkmSshPublicKey *self)
      63              : {
      64              : 
      65            9 : }
      66              : 
      67              : static void
      68            9 : gkm_ssh_public_key_finalize (GObject *obj)
      69              : {
      70            9 :         GkmSshPublicKey *self = GKM_SSH_PUBLIC_KEY (obj);
      71              : 
      72            9 :         g_free (self->label);
      73            9 :         self->label = NULL;
      74              : 
      75            9 :         G_OBJECT_CLASS (gkm_ssh_public_key_parent_class)->finalize (obj);
      76            9 : }
      77              : 
      78              : static void
      79            0 : gkm_ssh_public_key_set_property (GObject *obj, guint prop_id, const GValue *value,
      80              :                            GParamSpec *pspec)
      81              : {
      82            0 :         GkmSshPublicKey *self = GKM_SSH_PUBLIC_KEY (obj);
      83              : 
      84            0 :         switch (prop_id) {
      85            0 :         case PROP_LABEL:
      86            0 :                 gkm_ssh_public_key_set_label (self, g_value_get_string (value));
      87            0 :                 break;
      88            0 :         default:
      89            0 :                 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
      90            0 :                 break;
      91              :         }
      92            0 : }
      93              : 
      94              : static void
      95            0 : gkm_ssh_public_key_get_property (GObject *obj, guint prop_id, GValue *value,
      96              :                            GParamSpec *pspec)
      97              : {
      98            0 :         GkmSshPublicKey *self = GKM_SSH_PUBLIC_KEY (obj);
      99              : 
     100            0 :         switch (prop_id) {
     101            0 :         case PROP_LABEL:
     102            0 :                 g_value_set_string (value, gkm_ssh_public_key_get_label (self));
     103            0 :                 break;
     104            0 :         default:
     105            0 :                 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
     106            0 :                 break;
     107              :         }
     108            0 : }
     109              : 
     110              : static void
     111            1 : gkm_ssh_public_key_class_init (GkmSshPublicKeyClass *klass)
     112              : {
     113            1 :         GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
     114            1 :         GkmObjectClass *gkm_class = GKM_OBJECT_CLASS (klass);
     115              : 
     116            1 :         gobject_class->finalize = gkm_ssh_public_key_finalize;
     117            1 :         gobject_class->set_property = gkm_ssh_public_key_set_property;
     118            1 :         gobject_class->get_property = gkm_ssh_public_key_get_property;
     119              : 
     120            1 :         gkm_class->get_attribute = gkm_ssh_public_key_get_attribute;
     121              : 
     122            1 :         g_object_class_install_property (gobject_class, PROP_LABEL,
     123              :                    g_param_spec_string ("label", "Label", "Object Label",
     124              :                                         "", G_PARAM_READWRITE));
     125            1 : }
     126              : 
     127              : /* -----------------------------------------------------------------------------
     128              :  * PUBLIC
     129              :  */
     130              : 
     131              : GkmSshPublicKey*
     132            9 : gkm_ssh_public_key_new (GkmModule *module, const gchar *unique)
     133              : {
     134            9 :         return g_object_new (GKM_TYPE_SSH_PUBLIC_KEY, "unique", unique,
     135              :                              "module", module, "manager", gkm_module_get_manager (module), NULL);
     136              : }
     137              : 
     138              : const gchar*
     139            0 : gkm_ssh_public_key_get_label (GkmSshPublicKey *self)
     140              : {
     141            0 :         g_return_val_if_fail (GKM_IS_SSH_PUBLIC_KEY (self), NULL);
     142            0 :         return self->label;
     143              : }
     144              : 
     145              : void
     146            9 : gkm_ssh_public_key_set_label (GkmSshPublicKey *self, const gchar *label)
     147              : {
     148            9 :         g_return_if_fail (GKM_IS_SSH_PUBLIC_KEY (self));
     149            9 :         g_free (self->label);
     150            9 :         self->label = g_strdup (label);
     151            9 :         g_object_notify (G_OBJECT (self), "label");
     152              : }
        

Generated by: LCOV version 2.0-1