1 个不稳定版本

0.4.1-alpha.02023 年 2 月 25 日

#988异步


用于 kapiti

MIT/Apache

36KB
571

async-native-tls

异步原生 TLS


Native TLS for async-stdtokio

此 crate 在 Windows 上使用 SChannel(通过 schannel),在 OSX 上使用 Secure Transport(通过 security-framework),在其他所有平台上使用 OpenSSL(通过 openssl)。

安装

$ cargo add async-native-tls

Cargo 功能标志

  • runtime-async-std(默认开启):使用 async-std 运行时。

  • runtime-tokio:使用 tokio 运行时。此选项与 runtime-async-std 互斥。

示例

async-std

需要 runtime-async-std 功能(默认开启)。

# Cargo.toml
[dependencies]
async-native-tls = "0.4"
use async_std::prelude::*;
use async_std::net::TcpStream;

let stream = TcpStream::connect("google.com:443").await?;
let mut stream = async_native_tls::connect("google.com", stream).await?;
stream.write_all(b"GET / HTTP/1.0\r\n\r\n").await?;

let mut res = Vec::new();
stream.read_to_end(&mut res).await?;
println!("{}", String::from_utf8_lossy(&res));

tokio

需要 runtime-tokio 功能。

# Cargo.toml
[dependencies]
async-native-tls = { version = "0.4", default-features = false, features = [ "runtime-tokio" ] }
use tokio::prelude::*;
use tokio::net::TcpStream;

let stream = TcpStream::connect("google.com:443").await?;
let mut stream = async_native_tls::connect("google.com", stream).await?;
stream.write_all(b"GET / HTTP/1.0\r\n\r\n").await?;

let mut res = Vec::new();
stream.read_to_end(&mut res).await?;
println!("{}", String::from_utf8_lossy(&res));

贡献

想要加入我们吗?查看我们的 "贡献" 指南 并查看一些这些问题

许可

许可协议为 Apache License,Version 2.0 或 MIT 许可证,您可选择。
除非您明确说明,否则根据 Apache-2.0 许可证定义,您提交的任何有意包含在此 crate 中的贡献,将按上述方式双许可,没有额外的条款或条件。

依赖

~1–12MB
~177K SLoC