LCOV - code coverage report
Current view: top level - pkcs11/gkm - gkm-null-key.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 80.0 % 30 24
Test Date: 2024-04-08 13:24:42 Functions: 100.0 % 8 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-attributes.h"
      24              : #include "gkm-null-mechanism.h"
      25              : #include "gkm-null-key.h"
      26              : #include "gkm-session.h"
      27              : #include "gkm-util.h"
      28              : 
      29              : #include "pkcs11/pkcs11.h"
      30              : #include "pkcs11/pkcs11i.h"
      31              : 
      32              : struct _GkmNullKey {
      33              :         GkmSecretKey parent;
      34              : };
      35              : 
      36           66 : G_DEFINE_TYPE (GkmNullKey, gkm_null_key, GKM_TYPE_SECRET_KEY);
      37              : 
      38              : /* -----------------------------------------------------------------------------
      39              :  * INTERNAL
      40              :  */
      41              : 
      42              : static GkmObject*
      43           16 : factory_create_null_key (GkmSession *session, GkmTransaction *transaction,
      44              :                          CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs)
      45              : {
      46              :         GkmNullKey *key;
      47              :         GkmManager *manager;
      48              : 
      49           16 :         manager = gkm_manager_for_template (attrs, n_attrs, session);
      50           16 :         key = g_object_new (GKM_TYPE_NULL_KEY,
      51              :                             "module", gkm_session_get_module (session),
      52              :                             "manager", manager,
      53              :                             NULL);
      54              : 
      55           16 :         gkm_session_complete_object_creation (session, transaction, GKM_OBJECT (key),
      56              :                                               TRUE, attrs, n_attrs);
      57           16 :         return GKM_OBJECT (key);
      58              : }
      59              : 
      60              : /* -----------------------------------------------------------------------------
      61              :  * OBJECT
      62              :  */
      63              : 
      64              : static CK_RV
      65          143 : gkm_null_key_real_get_attribute (GkmObject *base, GkmSession *session, CK_ATTRIBUTE *attr)
      66              : {
      67          143 :         switch (attr->type)
      68              :         {
      69           16 :         case CKA_KEY_TYPE:
      70           16 :                 return gkm_attribute_set_ulong (attr, CKK_G_NULL);
      71              : 
      72           18 :         case CKA_UNWRAP:
      73              :         case CKA_WRAP:
      74           18 :                 return gkm_attribute_set_bool (attr, CK_TRUE);
      75              : 
      76            0 :         case CKA_VALUE:
      77            0 :                 return gkm_attribute_set_empty (attr);
      78              : 
      79            0 :         case CKA_VALUE_LEN:
      80            0 :                 return gkm_attribute_set_ulong (attr, 0);
      81              : 
      82            0 :         case CKA_CHECK_VALUE:
      83            0 :                 return gkm_attribute_set_data (attr, "\0\0\0", 3);
      84              : 
      85           36 :         case CKA_ALLOWED_MECHANISMS:
      86           36 :                 return gkm_attribute_set_data (attr, (CK_VOID_PTR)GKM_NULL_MECHANISMS,
      87              :                                                sizeof (GKM_NULL_MECHANISMS));
      88              :         };
      89              : 
      90           73 :         return GKM_OBJECT_CLASS (gkm_null_key_parent_class)->get_attribute (base, session, attr);
      91              : }
      92              : 
      93              : static void
      94           16 : gkm_null_key_init (GkmNullKey *self)
      95              : {
      96              : 
      97           16 : }
      98              : 
      99              : static void
     100           16 : gkm_null_key_class_init (GkmNullKeyClass *klass)
     101              : {
     102           16 :         GkmObjectClass *gkm_class = GKM_OBJECT_CLASS (klass);
     103              : 
     104           16 :         gkm_null_key_parent_class = g_type_class_peek_parent (klass);
     105           16 :         gkm_class->get_attribute = gkm_null_key_real_get_attribute;
     106           16 : }
     107              : 
     108              : /* -----------------------------------------------------------------------------
     109              :  * PUBLIC
     110              :  */
     111              : 
     112              : GkmFactory*
     113          287 : gkm_null_key_get_factory (void)
     114              : {
     115              :         static CK_OBJECT_CLASS klass = CKO_SECRET_KEY;
     116              :         static CK_KEY_TYPE type = CKK_G_NULL;
     117              : 
     118              :         static CK_ATTRIBUTE attributes[] = {
     119              :                 { CKA_CLASS, &klass, sizeof (klass) },
     120              :                 { CKA_KEY_TYPE, &type, sizeof (type) }
     121              :         };
     122              : 
     123              :         static GkmFactory factory = {
     124              :                 attributes,
     125              :                 G_N_ELEMENTS (attributes),
     126              :                 factory_create_null_key
     127              :         };
     128              : 
     129          287 :         return &factory;
     130              : }
        

Generated by: LCOV version 2.0-1