Blame guile/src/utils.c

Packit aea12f
/* GnuTLS --- Guile bindings for GnuTLS.
Packit Service 991b93
   Copyright (C) 2007-2012, 2019 Free Software Foundation, Inc.
Packit aea12f
Packit aea12f
   GnuTLS is free software; you can redistribute it and/or
Packit aea12f
   modify it under the terms of the GNU Lesser General Public
Packit aea12f
   License as published by the Free Software Foundation; either
Packit aea12f
   version 2.1 of the License, or (at your option) any later version.
Packit aea12f
Packit aea12f
   GnuTLS is distributed in the hope that it will be useful,
Packit aea12f
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit aea12f
   Lesser General Public License for more details.
Packit aea12f
Packit aea12f
   You should have received a copy of the GNU Lesser General Public
Packit aea12f
   License along with GnuTLS; if not, write to the Free Software
Packit aea12f
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA  */
Packit aea12f
Packit aea12f
/* Written by Ludovic Courtès <ludo@chbouib.org>.  */
Packit aea12f
Packit aea12f
#ifdef HAVE_CONFIG_H
Packit aea12f
#include <config.h>
Packit aea12f
#endif
Packit aea12f
Packit aea12f
#include "utils.h"
Packit aea12f
Packit aea12f
#include <gnutls/gnutls.h>
Packit aea12f
#include <libguile.h>
Packit aea12f
Packit aea12f
#include "enums.h"
Packit aea12f
#include "errors.h"
Packit aea12f
Packit aea12f
SCM
Packit aea12f
scm_from_gnutls_key_usage_flags (unsigned int c_usage)
Packit aea12f
{
Packit aea12f
  SCM usage = SCM_EOL;
Packit aea12f
Packit aea12f
#define MATCH_USAGE(_value)					\
Packit aea12f
  if (c_usage & (_value))					\
Packit aea12f
    {								\
Packit aea12f
      usage = scm_cons (scm_from_gnutls_key_usage (_value),	\
Packit aea12f
			usage);					\
Packit aea12f
      c_usage &= ~(_value);					\
Packit aea12f
    }
Packit aea12f
Packit aea12f
  /* when the key is to be used for signing: */
Packit aea12f
  MATCH_USAGE (GNUTLS_KEY_DIGITAL_SIGNATURE);
Packit aea12f
  MATCH_USAGE (GNUTLS_KEY_NON_REPUDIATION);
Packit aea12f
  /* when the key is to be used for encryption: */
Packit aea12f
  MATCH_USAGE (GNUTLS_KEY_KEY_ENCIPHERMENT);
Packit aea12f
  MATCH_USAGE (GNUTLS_KEY_DATA_ENCIPHERMENT);
Packit aea12f
  MATCH_USAGE (GNUTLS_KEY_KEY_AGREEMENT);
Packit aea12f
  MATCH_USAGE (GNUTLS_KEY_KEY_CERT_SIGN);
Packit aea12f
  MATCH_USAGE (GNUTLS_KEY_CRL_SIGN);
Packit aea12f
  MATCH_USAGE (GNUTLS_KEY_ENCIPHER_ONLY);
Packit aea12f
  MATCH_USAGE (GNUTLS_KEY_DECIPHER_ONLY);
Packit aea12f
Packit aea12f
  if (EXPECT_FALSE (c_usage != 0))
Packit aea12f
    /* XXX: We failed to interpret one of the usage flags.  */
Packit aea12f
    scm_gnutls_error (GNUTLS_E_UNIMPLEMENTED_FEATURE, __func__);
Packit aea12f
Packit aea12f
#undef MATCH_USAGE
Packit aea12f
Packit aea12f
  return usage;
Packit aea12f
}
Packit aea12f
Packit aea12f
/* arch-tag: a55fe230-ead7-495d-ab11-dfe18452ca2a
Packit aea12f
 */