|
Packit Service |
4684c1 |
/* GnuTLS --- Guile bindings for GnuTLS.
|
|
Packit Service |
4684c1 |
Copyright (C) 2007-2010, 2012 Free Software Foundation, Inc.
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
GnuTLS is free software; you can redistribute it and/or
|
|
Packit Service |
4684c1 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
4684c1 |
License as published by the Free Software Foundation; either
|
|
Packit Service |
4684c1 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
GnuTLS is distributed in the hope that it will be useful,
|
|
Packit Service |
4684c1 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
Lesser General Public License for more details.
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
4684c1 |
License along with GnuTLS; if not, write to the Free Software
|
|
Packit Service |
4684c1 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifndef GUILE_GNUTLS_UTILS_H
|
|
Packit Service |
4684c1 |
#define GUILE_GNUTLS_UTILS_H
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Common utilities. */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <libguile.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Compiler twiddling. */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef __GNUC__
|
|
Packit Service |
4684c1 |
#define EXPECT __builtin_expect
|
|
Packit Service |
4684c1 |
#define NO_RETURN __attribute__ ((__noreturn__))
|
|
Packit Service |
4684c1 |
#else
|
|
Packit Service |
4684c1 |
#define EXPECT(_expr, _value) (_expr)
|
|
Packit Service |
4684c1 |
#define NO_RETURN
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#define EXPECT_TRUE(_expr) EXPECT ((_expr), 1)
|
|
Packit Service |
4684c1 |
#define EXPECT_FALSE(_expr) EXPECT ((_expr), 0)
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Arrays as byte vectors. */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
extern const char scm_gnutls_array_error_message[];
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Initialize C_HANDLE and C_LEN and return the contiguous C array
|
|
Packit Service |
4684c1 |
corresponding to ARRAY. */
|
|
Packit Service |
4684c1 |
static inline const char *
|
|
Packit Service |
4684c1 |
scm_gnutls_get_array (SCM array, scm_t_array_handle * c_handle,
|
|
Packit Service |
4684c1 |
size_t * c_len, const char *func_name)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
const char *c_array = NULL;
|
|
Packit Service |
4684c1 |
const scm_t_array_dim *c_dims;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
scm_array_get_handle (array, c_handle);
|
|
Packit Service |
4684c1 |
c_dims = scm_array_handle_dims (c_handle);
|
|
Packit Service |
4684c1 |
if ((scm_array_handle_rank (c_handle) != 1) || (c_dims->inc != 1))
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
scm_array_handle_release (c_handle);
|
|
Packit Service |
4684c1 |
scm_misc_error (func_name, scm_gnutls_array_error_message,
|
|
Packit Service |
4684c1 |
scm_list_1 (array));
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
else
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
size_t c_elem_size;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
c_elem_size = scm_array_handle_uniform_element_size (c_handle);
|
|
Packit Service |
4684c1 |
*c_len = c_elem_size * (c_dims->ubnd - c_dims->lbnd + 1);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
c_array = (char *) scm_array_handle_uniform_elements (c_handle);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return (c_array);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Initialize C_HANDLE and C_LEN and return the contiguous C array
|
|
Packit Service |
4684c1 |
corresponding to ARRAY. The returned array can be written to. */
|
|
Packit Service |
4684c1 |
static inline char *
|
|
Packit Service |
4684c1 |
scm_gnutls_get_writable_array (SCM array, scm_t_array_handle * c_handle,
|
|
Packit Service |
4684c1 |
size_t * c_len, const char *func_name)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
char *c_array = NULL;
|
|
Packit Service |
4684c1 |
const scm_t_array_dim *c_dims;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
scm_array_get_handle (array, c_handle);
|
|
Packit Service |
4684c1 |
c_dims = scm_array_handle_dims (c_handle);
|
|
Packit Service |
4684c1 |
if ((scm_array_handle_rank (c_handle) != 1) || (c_dims->inc != 1))
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
scm_array_handle_release (c_handle);
|
|
Packit Service |
4684c1 |
scm_misc_error (func_name, scm_gnutls_array_error_message,
|
|
Packit Service |
4684c1 |
scm_list_1 (array));
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
else
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
size_t c_elem_size;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
c_elem_size = scm_array_handle_uniform_element_size (c_handle);
|
|
Packit Service |
4684c1 |
*c_len = c_elem_size * (c_dims->ubnd - c_dims->lbnd + 1);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
c_array =
|
|
Packit Service |
4684c1 |
(char *) scm_array_handle_uniform_writable_elements (c_handle);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return (c_array);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#define scm_gnutls_release_array scm_array_handle_release
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Type conversion. */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Return a list corresponding to the key usage values ORed in C_USAGE. */
|
|
Packit Service |
4684c1 |
SCM_API SCM scm_from_gnutls_key_usage_flags (unsigned int c_usage);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* arch-tag: a33400bc-b5e3-429e-80e0-6ff14cab79e7
|
|
Packit Service |
4684c1 |
*/
|