summaryrefslogtreecommitdiff
path: root/lib/pin.c
blob: 5fc7fb8ec9c567b727e459ea3d024c4d1eaba5d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * GnuTLS PIN support for PKCS#11 or TPM
 * Copyright (C) 2010-2012 Free Software Foundation, Inc.
 * 
 * Authors: Nikos Mavrogiannopoulos
 *
 * The GnuTLS is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

#include <gnutls_int.h>
#include <gnutls/pkcs11.h>
#include <pin.h>

gnutls_pin_callback_t _gnutls_pin_func;
void *_gnutls_pin_data;

/**
 * gnutls_pkcs11_set_pin_function:
 * @fn: The PIN callback, a gnutls_pin_callback_t() function.
 * @userdata: data to be supplied to callback
 *
 * This function will set a callback function to be used when a PIN is
 * required for PKCS 11 operations.  See
 * gnutls_pin_callback_t() on how the callback should behave.
 *
 * Since: 2.12.0
 **/
void
gnutls_pkcs11_set_pin_function (gnutls_pin_callback_t fn,
                                void *userdata)
{
  _gnutls_pin_func = fn;
  _gnutls_pin_data = userdata;
}

/**
 * gnutls_pkcs11_get_pin_function:
 * @userdata: data to be supplied to callback
 *
 * This function will return the callback function set using
 * gnutls_pkcs11_set_pin_function().
 *
 * Returns: The function set or NULL otherwise.
 * 
 * Since: 3.1.0
 **/
gnutls_pin_callback_t
gnutls_pkcs11_get_pin_function (void **userdata)
{
  if (_gnutls_pin_func != NULL)
    {
      *userdata = _gnutls_pin_data;
      return _gnutls_pin_func;
    }
  return NULL;
}