2 unstable releases

0.2.0 Jun 19, 2021
0.1.0 Mar 14, 2019

#2305 in Cryptography

Download history 936/week @ 2024-03-14 512/week @ 2024-03-21 762/week @ 2024-03-28 1160/week @ 2024-04-04 601/week @ 2024-04-11 584/week @ 2024-04-18 686/week @ 2024-04-25 449/week @ 2024-05-02 761/week @ 2024-05-09 613/week @ 2024-05-16 548/week @ 2024-05-23 590/week @ 2024-05-30 567/week @ 2024-06-06 920/week @ 2024-06-13 377/week @ 2024-06-20 168/week @ 2024-06-27

2,066 downloads per month
Used in 2 crates

MIT/Apache

365KB
9K SLoC

rust-openssl

crates.io

OpenSSL bindings for the Rust programming language.

Documentation.

Release Support

The current supported release of openssl is 0.10 and openssl-sys is 0.9.

New major versions will be published at most once per year. After a new release, the previous major version will be partially supported with bug fixes for 3 months, after which support will be dropped entirely.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed under the terms of both the Apache License, Version 2.0 and the MIT license without any additional terms or conditions.


lib.rs:

Custom error library support for the openssl crate.

OpenSSL allows third-party libraries to integrate with its error API. This crate provides a safe interface to that.

Examples

use openssl_errors::{openssl_errors, put_error};
use openssl::error::Error;

// Errors are organized at the top level into "libraries". The
// openssl_errors! macro can define these.
//
// Libraries contain a set of functions and reasons. The library itself,
// its functions, and its definitions all all have an associated message
// string. This string is what's shown in OpenSSL errors.
//
// The macro creates a type for each library with associated constants for
// its functions and reasons.
openssl_errors! {
    pub library MyLib("my cool library") {
        functions {
            FIND_PRIVATE_KEY("find_private_key");
        }

        reasons {
            IO_ERROR("IO error");
            BAD_PASSWORD("invalid private key password");
        }
    }
}

// The put_error! macro pushes errors onto the OpenSSL error stack.
put_error!(MyLib::FIND_PRIVATE_KEY, MyLib::BAD_PASSWORD);

// Prints `error:80001002:my cool library:find_private_key:invalid private key password:src/lib.rs:27:`
println!("{}", Error::get().unwrap());

// You can also optionally attach an extra string of context using the
// standard Rust format syntax.
let tries = 2;
put_error!(MyLib::FIND_PRIVATE_KEY, MyLib::IO_ERROR, "tried {} times", tries);

// Prints `error:80001001:my cool library:find_private_key:IO error:src/lib.rs:34:tried 2 times`
println!("{}", Error::get().unwrap());

Dependencies

~8–255KB