1 个不稳定版本
使用旧的 Rust 2015
0.1.0 | 2018 年 4 月 10 日 |
---|
#29 in #encoded
17KB
476 行代码(不包括注释)
rfc2253-rust
一个小的 Rust 库,用于解析 RFC2253 编码的区分名称字符串。您可以使用此库来解码 openssl 的 x509_NAME_print_ex(..., XN_FLAG_RFC2253)
或 nginx 的 $ssl_client_s_dn
和 $ssl_client_i_dn
变量。
用法
将以下内容添加到您的 Cargo.toml
文件中
[dependencies]
rfc2253 = "*"
以下示例显示了如何解析 RFC2253 编码的区分名称。
extern crate rfc2253;
fn main() {
let dn_str = "C=DE,CN=Hans Tester,OU=ACME Inc.,O=ACME Inc.,L=Berlin,ST=Berlin";
let dn = rfc2253::parse_distinguished_name_str(dn_str).unwrap();
println!("{:?}", dn);
assert!(dn.attributes.len() == 6);
assert!(dn.attributes.get("CN").unwrap() == "Hans Tester");
assert!(dn.attributes.get("C").unwrap() == "DE");
assert!(dn.attributes.get("L").unwrap() == "Berlin");
assert!(dn.attributes.get("ST").unwrap() == "Berlin");
assert!(dn.attributes.get("O").unwrap() == "ACME Inc.");
assert!(dn.attributes.get("OU").unwrap() == "ACME Inc.");
}
构建
要构建 rfc2253-rust
库,运行 cargo build
$ cd rfc2253-rust
$ cargo build
在您对代码进行了任何更改后,通过执行 cargo test
来运行测试套件
$ cd rfc2253-rust
$ cargo test
许可证
Copyright © 2018 Nyantec GmbH <[email protected]>
Authors:
Paul Asmuth <[email protected]>
Provided that these terms and disclaimer and all copyright notices
are retained or reproduced in an accompanying document, permission
is granted to deal in this work without restriction, including un‐
limited rights to use, publicly perform, distribute, sell, modify,
merge, give away, or sublicence.
This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
the utmost extent permitted by applicable law, neither express nor
implied; without malicious intent or gross negligence. In no event
may a licensor, author or contributor be held liable for indirect,
direct, other damage, loss, or other issues arising in any way out
of dealing in the work, even if advised of the possibility of such
damage or existence of a defect, except proven that it results out
of said person’s immediate fault when using the work as intended.