Increased maximum password len in PKCS #12.
[gnutls.git] / guile / src / utils.h
blob8e04f726d30f317dc38394391e0bd7a9fe074b83
1 /* GnuTLS --- Guile bindings for GnuTLS.
2 Copyright (C) 2007-2010, 2012 Free Software Foundation, Inc.
4 GnuTLS is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 GnuTLS is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with GnuTLS; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
18 #ifndef GUILE_GNUTLS_UTILS_H
19 #define GUILE_GNUTLS_UTILS_H
21 /* Common utilities. */
23 #include <libguile.h>
26 /* Compiler twiddling. */
28 #ifdef __GNUC__
29 #define EXPECT __builtin_expect
30 #define NO_RETURN __attribute__ ((__noreturn__))
31 #else
32 #define EXPECT(_expr, _value) (_expr)
33 #define NO_RETURN
34 #endif
36 #define EXPECT_TRUE(_expr) EXPECT ((_expr), 1)
37 #define EXPECT_FALSE(_expr) EXPECT ((_expr), 0)
40 /* Arrays as byte vectors. */
42 extern const char scm_gnutls_array_error_message[];
44 /* Initialize C_HANDLE and C_LEN and return the contiguous C array
45 corresponding to ARRAY. */
46 static inline const char *
47 scm_gnutls_get_array (SCM array, scm_t_array_handle * c_handle,
48 size_t * c_len, const char *func_name)
50 const char *c_array = NULL;
51 const scm_t_array_dim *c_dims;
53 scm_array_get_handle (array, c_handle);
54 c_dims = scm_array_handle_dims (c_handle);
55 if ((scm_array_handle_rank (c_handle) != 1) || (c_dims->inc != 1))
57 scm_array_handle_release (c_handle);
58 scm_misc_error (func_name, scm_gnutls_array_error_message,
59 scm_list_1 (array));
61 else
63 size_t c_elem_size;
65 c_elem_size = scm_array_handle_uniform_element_size (c_handle);
66 *c_len = c_elem_size * (c_dims->ubnd - c_dims->lbnd + 1);
68 c_array = (char *) scm_array_handle_uniform_elements (c_handle);
71 return (c_array);
74 /* Initialize C_HANDLE and C_LEN and return the contiguous C array
75 corresponding to ARRAY. The returned array can be written to. */
76 static inline char *
77 scm_gnutls_get_writable_array (SCM array, scm_t_array_handle * c_handle,
78 size_t * c_len, const char *func_name)
80 char *c_array = NULL;
81 const scm_t_array_dim *c_dims;
83 scm_array_get_handle (array, c_handle);
84 c_dims = scm_array_handle_dims (c_handle);
85 if ((scm_array_handle_rank (c_handle) != 1) || (c_dims->inc != 1))
87 scm_array_handle_release (c_handle);
88 scm_misc_error (func_name, scm_gnutls_array_error_message,
89 scm_list_1 (array));
91 else
93 size_t c_elem_size;
95 c_elem_size = scm_array_handle_uniform_element_size (c_handle);
96 *c_len = c_elem_size * (c_dims->ubnd - c_dims->lbnd + 1);
98 c_array =
99 (char *) scm_array_handle_uniform_writable_elements (c_handle);
102 return (c_array);
105 #define scm_gnutls_release_array scm_array_handle_release
109 /* Type conversion. */
111 /* Return a list corresponding to the key usage values ORed in C_USAGE. */
112 SCM_API SCM scm_from_gnutls_key_usage_flags (unsigned int c_usage);
114 #endif
116 /* arch-tag: a33400bc-b5e3-429e-80e0-6ff14cab79e7