Line data Source code
1 : /* 2 : * Copyright (C) 2000-2012 Free Software Foundation, Inc. 3 : * 4 : * Author: Nikos Mavrogiannopoulos 5 : * 6 : * This file is part of GnuTLS. 7 : * 8 : * The GnuTLS is free software; you can redistribute it and/or 9 : * modify it under the terms of the GNU Lesser General Public License 10 : * as published by the Free Software Foundation; either version 2.1 of 11 : * the License, or (at your option) any later version. 12 : * 13 : * This library is distributed in the hope that it will be useful, but 14 : * WITHOUT ANY WARRANTY; without even the implied warranty of 15 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 : * Lesser General Public License for more details. 17 : * 18 : * You should have received a copy of the GNU Lesser General Public License 19 : * along with this program. If not, see <https://www.gnu.org/licenses/> 20 : * 21 : */ 22 : 23 : #ifndef GNUTLS_LIB_DATUM_H 24 : #define GNUTLS_LIB_DATUM_H 25 : 26 : # include "gnutls_int.h" 27 : 28 : /* This will copy the provided data in @dat. If the provided data are 29 : * NULL or zero-size @dat will be NULL as well. 30 : */ 31 : NODISCARD ATTRIBUTE_NONNULL((1)) 32 : int _gnutls_set_datum(gnutls_datum_t * dat, const void *data, 33 : size_t data_size); 34 : 35 : /* This will always return a non-NULL, and zero-terminated string in @dat. 36 : */ 37 : NODISCARD ATTRIBUTE_NONNULL((1)) 38 : int _gnutls_set_strdatum(gnutls_datum_t * dat, const void *data, 39 : size_t data_size); 40 : 41 : 42 : inline static 43 791285 : void _gnutls_free_datum(gnutls_datum_t * dat) 44 : { 45 414738 : if (dat != NULL) { 46 521109 : gnutls_free(dat->data); 47 608813 : dat->size = 0; 48 : } 49 19939 : } 50 : 51 : inline static ATTRIBUTE_NONNULL() 52 154160 : void _gnutls_free_temp_key_datum(gnutls_datum_t * dat) 53 : { 54 154160 : if (dat->data != NULL) { 55 16902 : zeroize_temp_key(dat->data, dat->size); 56 16902 : gnutls_free(dat->data); 57 : } 58 : 59 154160 : dat->size = 0; 60 154160 : } 61 : 62 : inline static ATTRIBUTE_NONNULL() 63 2778 : void _gnutls_free_key_datum(gnutls_datum_t * dat) 64 : { 65 2778 : if (dat->data != NULL) { 66 2758 : zeroize_key(dat->data, dat->size); 67 2758 : gnutls_free(dat->data); 68 : } 69 : 70 2778 : dat->size = 0; 71 2778 : } 72 : 73 : #endif /* GNUTLS_LIB_DATUM_H */