manpagez: man pages & more
info gnutls
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.2.1 Enumerates and Constants

Lots of enumerates and constants are used in the GnuTLS C API. For each C enumerate type, a disjoint Scheme type is used—thus, enumerate values and constants are not represented by Scheme symbols nor by integers. This makes it impossible to use an enumerate value of the wrong type on the Scheme side: such errors are automatically detected by type-checking.

The enumerate values are bound to variables exported by the (gnutls) and (gnutls extra) modules. These variables are named according to the following convention:

Consider for instance this C-side enumerate:

 
typedef enum
{
  GNUTLS_CRD_CERTIFICATE = 1,
  GNUTLS_CRD_ANON,
  GNUTLS_CRD_SRP,
  GNUTLS_CRD_PSK,
  GNUTLS_CRD_IA
} gnutls_credentials_type_t;

The corresponding Scheme values are bound to the following variables exported by the (gnutls) module:

 
credentials/certificate
credentials/anonymous
credentials/srp
credentials/psk
credentials/ia

Hopefully, most variable names can be deduced from this convention.

Scheme-side “enumerate” values can be compared using eq? (see equality predicates: (guile)Equality section `Equality' in The GNU Guile Reference Manual). Consider the following example:

 
(let ((session (make-session connection-end/client)))

  ;;
  ;; ...
  ;;

  ;; Check the ciphering algorithm currently used by SESSION.
  (if (eq? cipher/arcfour (session-cipher session))
      (format #t "We're using the ARCFOUR algorithm")))

In addition, all enumerate values can be converted to a human-readable string, in a type-specific way. For instance, (cipher->string cipher/arcfour) yields "ARCFOUR 128", while (key-usage->string key-usage/digital-signature) yields "digital-signature". Note that these strings may not be sufficient for use in a user interface since they are fairly concise and not internationalized.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.