2个不稳定版本
0.2.0 | 2021年6月19日 |
---|---|
0.1.0 | 2019年3月14日 |
#2305 in 密码学
2,066 每月下载量
在 2 crates 中使用
365KB
9K SLoC
rust-openssl
为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