corrected call to gnutls_error_is_fatal().
[gnutls.git] / guile / src / utils.c
blobd4ca3b9f0f75a4f3d06e23f51832bc8f1eac2e5b
1 /* GnuTLS --- Guile bindings for GnuTLS.
2 Copyright (C) 2007-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 /* Written by Ludovic Courtès <ludo@chbouib.org>. */
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
24 #include "utils.h"
26 #include <gnutls/gnutls.h>
27 #include <libguile.h>
29 #include <alloca.h>
31 #include "enums.h"
32 #include "errors.h"
34 SCM
35 scm_from_gnutls_key_usage_flags (unsigned int c_usage)
37 SCM usage = SCM_EOL;
39 #define MATCH_USAGE(_value) \
40 if (c_usage & (_value)) \
41 { \
42 usage = scm_cons (scm_from_gnutls_key_usage (_value), \
43 usage); \
44 c_usage &= ~(_value); \
47 /* when the key is to be used for signing: */
48 MATCH_USAGE (GNUTLS_KEY_DIGITAL_SIGNATURE);
49 MATCH_USAGE (GNUTLS_KEY_NON_REPUDIATION);
50 /* when the key is to be used for encryption: */
51 MATCH_USAGE (GNUTLS_KEY_KEY_ENCIPHERMENT);
52 MATCH_USAGE (GNUTLS_KEY_DATA_ENCIPHERMENT);
53 MATCH_USAGE (GNUTLS_KEY_KEY_AGREEMENT);
54 MATCH_USAGE (GNUTLS_KEY_KEY_CERT_SIGN);
55 MATCH_USAGE (GNUTLS_KEY_CRL_SIGN);
56 MATCH_USAGE (GNUTLS_KEY_ENCIPHER_ONLY);
57 MATCH_USAGE (GNUTLS_KEY_DECIPHER_ONLY);
59 if (EXPECT_FALSE (c_usage != 0))
60 /* XXX: We failed to interpret one of the usage flags. */
61 scm_gnutls_error (GNUTLS_E_UNIMPLEMENTED_FEATURE, __func__);
63 #undef MATCH_USAGE
65 return usage;
68 /* arch-tag: a55fe230-ead7-495d-ab11-dfe18452ca2a