native-tls crate 文档 一个对平台特定 TLS 实现的抽象。具体来说,此 crate 在 Windows 上使用 SChannel ...
native-tls crate 文档 一个对平台特定 TLS 实现的抽象。具体来说,此 crate 在 Windows 上使用 SChannel ...
An abstraction over platform-specific TLS implementations.
Specifically, this crate uses SChannel on Windows (via the schannel crate),
Secure Transport on macOS (via the security-framework crate), and OpenSSL (via
the openssl crate) on all other platforms.
Using platform-native TLS library can reduce binary sizes, compilation times, and improve compatibility with system-wide proxies and CA certificate stores.
cargo add native-tls or
# Cargo.toml
[dependencies]
native-tls = "0.2"
An example client looks like:
use native_tls::TlsConnector;
use std::io::{Read, Write};
use std::net::TcpStream;
fn main() {
let connector = TlsConnector::new().unwrap();
let stream = TcpStream::connect("google.com:443").unwrap();
let mut stream = connector.connect("google.com", stream).unwrap();
stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap();
let mut res = vec![];
stream.read_to_end(&mut res).unwrap();
println!("{}", String::from_utf8_lossy(&res));
}
To accept connections as a server from remote clients:
…
This crate supports the following features out of the box:
native-tls is primarily distributed under the terms of both the MIT
license and the Apache License (Version 2.0), with portions covered by various
BSD-like licenses.
See LICENSE-APACHE, and LICENSE-MIT for details.
暂无开放 Issues,或尚未同步最近议题。