2个不稳定版本

0.2.0 2021年6月19日
0.1.0 2019年3月14日

#2305 in 密码学

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 每月下载量
2 crates 中使用

MIT/Apache

365KB
9K SLoC

rust-openssl

crates.io

为Rust编程语言提供的OpenSSL绑定。

文档.

版本支持

当前支持的OpenSSL版本是0.10,openssl-sys版本是0.9。

新主要版本每年最多发布一次。新版本发布后,之前的重大版本将提供3个月的有限支持,以修复错误,之后将完全停止支持。

贡献

除非您明确表示,否则任何有意提交以包含在您的工作中的贡献,如Apache-2.0许可证中定义的,将根据Apache许可证版本2.0和MIT许可证的双重许可,不附加任何额外条款或条件。


lib.rs:

为openssl crate提供自定义错误库支持。

OpenSSL允许第三方库与其错误API集成。这个crate提供了一个安全的接口。

示例

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());

依赖项

~8–255KB