Tizen 2.0 Release
[external/libgnutls26.git] / guile / src / utils.c
1 /* GnuTLS --- Guile bindings for GnuTLS.
2    Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
3
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.
8
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.
13
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  */
17
18 /* Written by Ludovic Courtès <ludo@chbouib.org>.  */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include "utils.h"
25
26 #include <gnutls/gnutls.h>
27 #include <libguile.h>
28
29 #include <alloca.h>
30
31 #include "enums.h"
32 #include "errors.h"
33
34 SCM
35 scm_from_gnutls_key_usage_flags (unsigned int c_usage)
36 {
37   SCM usage = SCM_EOL;
38
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);                                     \
45     }
46
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);
58
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__);
62
63 #undef MATCH_USAGE
64
65   return usage;
66 }
67
68 /* arch-tag: a55fe230-ead7-495d-ab11-dfe18452ca2a
69  */