Skip to content

gpg-rs/libgcrypt

Repository files navigation

libgcrypt-rs

Build Status crates.io version LGPL-2.1 licensed downloads

Libgcrypt bindings for Rust.

Documentation

Building

These crates require the libgcrypt library and its development files (e.g., headers, libgcrypt-config) to be installed. The buildscript will attempt to detect the necessary information using the libgcrypt-config script distributed with libgcrypt. If for whatever reason this does not work, the required information can also be specified using one or more environment variables:

  • LIBGCRYPT_INCLUDE specifies the path(s) where header files can be found.
  • LIBGCRYPT_LIB_DIR specifies the path(s) where library files (e.g., *.so, *.a, *.dll, etc.) can be found.
  • LIBGCRYPT_LIBS specifies the name(s) of all required libraries.
  • LIBGCRYPT_STATIC controls whether libraries are linked to statically or dynamically by default. Individual libraries can have their linkage overridden by prefixing their names with either static= or dynamic= in LIBGCRYPT_LIBS.
  • LIBGCRYPT_CONFIG specifies the path to the libgcrypt-config script.

Each environment variable, with the exceptions of LIBGCRYPT_STATIC and LIBGCRYPT_CONFIG, can take multiple values separated by the platform's path separator.

NOTE: These crates also depend on the gpg-error crate which has its own requirements.

NOTE: Previous versions of these crates bundled the sources of the libgcrypt library and attempted to build them via the buildscript. This is no longer supported.

Usage

The library requires initialization before first use. The functions init, init_fips, and init_default can be used to initialize the library. The closure passed to the first two functions is used to configure the library. For the third function a default configuration is used. More information on configuration options can be found in the libgcrypt documentation.

An example:

let token = gcrypt::init(|x| {
    x.disable_secmem();
});

Calling any function in the wrapper that requires initialization before one of the initialization functions has been called will cause the wrapper to attempt to initialize the library with a call to init_default.