Fix CVE-2017-6891 in minitasn1 code
[platform/upstream/gnutls.git] / lib / pin.c
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 <http://www.gnu.org/licenses/>
19  */
20
21 #include <gnutls_int.h>
22 #include <gnutls/pkcs11.h>
23 #include <pin.h>
24
25 gnutls_pin_callback_t _gnutls_pin_func;
26 void *_gnutls_pin_data;
27
28 /**
29  * gnutls_pkcs11_set_pin_function:
30  * @fn: The PIN callback, a gnutls_pin_callback_t() function.
31  * @userdata: data to be supplied to callback
32  *
33  * This function will set a callback function to be used when a PIN is
34  * required for PKCS 11 operations.  See
35  * gnutls_pin_callback_t() on how the callback should behave.
36  *
37  * Since: 2.12.0
38  **/
39 void
40 gnutls_pkcs11_set_pin_function(gnutls_pin_callback_t fn, void *userdata)
41 {
42         _gnutls_pin_func = fn;
43         _gnutls_pin_data = userdata;
44 }
45
46 /**
47  * gnutls_pkcs11_get_pin_function:
48  * @userdata: data to be supplied to callback
49  *
50  * This function will return the callback function set using
51  * gnutls_pkcs11_set_pin_function().
52  *
53  * Returns: The function set or NULL otherwise.
54  * 
55  * Since: 3.1.0
56  **/
57 gnutls_pin_callback_t gnutls_pkcs11_get_pin_function(void **userdata)
58 {
59         if (_gnutls_pin_func != NULL) {
60                 *userdata = _gnutls_pin_data;
61                 return _gnutls_pin_func;
62         }
63         return NULL;
64 }