LCOV - code coverage report
Current view: top level - builds/gnutls/coverage/gnutls-git/lib - pin.c (source / functions) Hit Total Coverage
Test: GnuTLS-3.6.14 Code Coverage Lines: 15 18 83.3 %
Date: 2020-10-30 04:50:48 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * GnuTLS PIN support for PKCS#11 or TPM
       3             :  * Copyright (C) 2010-2012 Free Software Foundation, Inc.
       4             :  * 
       5             :  * Authors: Nikos Mavrogiannopoulos
       6             :  *
       7             :  * The GnuTLS is free software; you can redistribute it and/or
       8             :  * modify it under the terms of the GNU Lesser General Public License
       9             :  * as published by the Free Software Foundation; either version 2.1 of
      10             :  * the License, or (at your option) any later version.
      11             :  *
      12             :  * This library is distributed in the hope that it will be useful, but
      13             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :  * Lesser General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU Lesser General Public License
      18             :  * along with this program.  If not, see <https://www.gnu.org/licenses/>
      19             :  */
      20             : 
      21             : #include "gnutls_int.h"
      22             : #include <gnutls/pkcs11.h>
      23             : #include <pin.h>
      24             : #include "errors.h"
      25             : 
      26             : gnutls_pin_callback_t _gnutls_pin_func;
      27             : void *_gnutls_pin_data;
      28             : 
      29             : /**
      30             :  * gnutls_pkcs11_set_pin_function:
      31             :  * @fn: The PIN callback, a gnutls_pin_callback_t() function.
      32             :  * @userdata: data to be supplied to callback
      33             :  *
      34             :  * This function will set a callback function to be used when a PIN is
      35             :  * required for PKCS 11 operations.  See
      36             :  * gnutls_pin_callback_t() on how the callback should behave.
      37             :  *
      38             :  * Since: 2.12.0
      39             :  **/
      40             : void
      41        2094 : gnutls_pkcs11_set_pin_function(gnutls_pin_callback_t fn, void *userdata)
      42             : {
      43        2094 :         _gnutls_pin_func = fn;
      44        2094 :         _gnutls_pin_data = userdata;
      45        2094 : }
      46             : 
      47             : /**
      48             :  * gnutls_pkcs11_get_pin_function:
      49             :  * @userdata: data to be supplied to callback
      50             :  *
      51             :  * This function will return the callback function set using
      52             :  * gnutls_pkcs11_set_pin_function().
      53             :  *
      54             :  * Returns: The function set or NULL otherwise.
      55             :  * 
      56             :  * Since: 3.1.0
      57             :  **/
      58           1 : gnutls_pin_callback_t gnutls_pkcs11_get_pin_function(void **userdata)
      59             : {
      60           1 :         if (_gnutls_pin_func != NULL) {
      61           1 :                 *userdata = _gnutls_pin_data;
      62           1 :                 return _gnutls_pin_func;
      63             :         }
      64             :         return NULL;
      65             : }
      66             : 
      67             : int
      68           4 : _gnutls_retrieve_pin(struct pin_info_st *pin_info, const char *url, const char *label,
      69             :                      unsigned flags,
      70             :                      char pin[GNUTLS_PKCS11_MAX_PIN_LEN], unsigned pin_size)
      71             : {
      72           4 :         int ret;
      73             : 
      74           4 :         if (pin_info && pin_info->cb)
      75           0 :                 ret =
      76           0 :                     pin_info->cb(pin_info->data, 0,
      77             :                                  (char *) url, label, flags,
      78             :                                  pin, pin_size);
      79           4 :         else if (_gnutls_pin_func)
      80           4 :                 ret =
      81           4 :                     _gnutls_pin_func(_gnutls_pin_data, 0,
      82             :                                      (char *) url, label, flags,
      83             :                                      pin, pin_size);
      84             :         else
      85           0 :                 ret = gnutls_assert_val(GNUTLS_E_PKCS11_PIN_ERROR);
      86             : 
      87           4 :         return ret;
      88             : }

Generated by: LCOV version 1.14