| 1 |
/* GnuTLS --- Guile bindings for GnuTLS. |
| 2 |
Copyright (C) 2007-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of Guile-GnuTLS. |
| 5 |
|
| 6 |
This library is free software; you can redistribute it and/or |
| 7 |
modify it under the terms of the GNU Lesser General Public |
| 8 |
License as published by the Free Software Foundation; either |
| 9 |
version 2.1 of the License, or (at your option) any later version. |
| 10 |
|
| 11 |
This library is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
Lesser General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU Lesser General Public License |
| 17 |
along with this library; if not, see <https://www.gnu.org/licenses/>. */ |
| 18 |
|
| 19 |
/* Written by Ludovic Courtès <[email protected]>. */ |
| 20 |
|
| 21 |
#ifdef HAVE_CONFIG_H |
| 22 |
# include <config.h> |
| 23 |
#endif |
| 24 |
|
| 25 |
#include "utils.h" |
| 26 |
|
| 27 |
#include <gnutls/gnutls.h> |
| 28 |
#include <gnutls/crypto.h> |
| 29 |
#include <libguile.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 |
*/ |