LCOV - code coverage report
Current view: top level - egg - egg-libgcrypt.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 63.6 % 22 14
Test Date: 2024-05-07 18:02:03 Functions: 50.0 % 6 3

            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 "egg-libgcrypt.h"
      24              : #include "egg-secure-memory.h"
      25              : 
      26              : #include <glib.h>
      27              : 
      28              : #include <gcrypt.h>
      29              : 
      30              : #include <errno.h>
      31              : #include <pthread.h>
      32              : 
      33          550 : EGG_SECURE_DECLARE (libgcrypt);
      34              : 
      35              : static void
      36            0 : log_handler (gpointer unused, int unknown, const gchar *msg, va_list va)
      37              : {
      38              :         /* TODO: Figure out additional arguments */
      39            0 :         g_logv ("gcrypt", G_LOG_LEVEL_MESSAGE, msg, va);
      40            0 : }
      41              : 
      42              : static int 
      43            0 : no_mem_handler (gpointer unused, size_t sz, unsigned int unknown)
      44              : {
      45              :         /* TODO: Figure out additional arguments */
      46            0 :         g_error ("couldn't allocate %lu bytes of memory", 
      47              :                  (unsigned long int)sz);
      48              :         return 0;
      49              : }
      50              : 
      51              : static void
      52            0 : fatal_handler (gpointer unused, int unknown, const gchar *msg)
      53              : {
      54              :         /* TODO: Figure out additional arguments */
      55            0 :         g_log ("gcrypt", G_LOG_LEVEL_ERROR, "%s", msg);
      56            0 : }
      57              : 
      58              : #if GCRYPT_VERSION_NUMBER < 0x010600
      59              : GCRY_THREAD_OPTION_PTHREAD_IMPL;
      60              : #endif
      61              : 
      62              : void
      63          736 : egg_libgcrypt_initialize (void)
      64              : {
      65              :         static gsize gcrypt_initialized = 0;
      66              :         unsigned seed;
      67              : 
      68          736 :         if (g_once_init_enter (&gcrypt_initialized)) {
      69              :                 
      70              :                 /* Only initialize libgcrypt if it hasn't already been initialized */
      71           50 :                 if (!gcry_control (GCRYCTL_INITIALIZATION_FINISHED_P)) {
      72              : #if GCRYPT_VERSION_NUMBER < 0x010600
      73              :                         gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
      74              : #endif
      75           50 :                         gcry_check_version (LIBGCRYPT_VERSION);
      76           50 :                         gcry_set_log_handler (log_handler, NULL);
      77           50 :                         gcry_set_outofcore_handler (no_mem_handler, NULL);
      78           50 :                         gcry_set_fatalerror_handler (fatal_handler, NULL);
      79           50 :                         gcry_set_allocation_handler ((gcry_handler_alloc_t)g_malloc, 
      80              :                                                      (gcry_handler_alloc_t)egg_secure_alloc, 
      81              :                                                      egg_secure_check, 
      82              :                                                      (gcry_handler_realloc_t)egg_secure_realloc, 
      83              :                                                      egg_secure_free);
      84           50 :                         gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
      85              :                 }
      86              :                 
      87           50 :                 gcry_create_nonce (&seed, sizeof (seed));
      88           50 :                 srand (seed);
      89              : 
      90           50 :                 g_once_init_leave (&gcrypt_initialized, 1);
      91              :         }
      92          736 : }
        

Generated by: LCOV version 2.0-1