Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

sfackler/rust-native-tls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Documentation

An abstraction over platform-specific TLS implementations.

Specifically, this crate uses SChannel on Windows (via theschannel crate),Secure Transport on macOS (via thesecurity-framework crate), and OpenSSL (viatheopenssl crate) on all other platforms.

Installation

# Cargo.toml[dependencies]native-tls ="0.2"

Usage

An example client looks like:

externcrate native_tls;use native_tls::TlsConnector;use std::io::{Read,Write};use std::net::TcpStream;fnmain(){let connector =TlsConnector::new().unwrap();let stream =TcpStream::connect("google.com:443").unwrap();letmut stream = connector.connect("google.com", stream).unwrap();    stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap();letmut res =vec![];    stream.read_to_end(&mut res).unwrap();println!("{}",String::from_utf8_lossy(&res));}

To accept connections as a server from remote clients:

externcrate native_tls;use native_tls::{Identity,TlsAcceptor,TlsStream};use std::fs::File;use std::io::{Read};use std::net::{TcpListener,TcpStream};use std::sync::Arc;use std::thread;fnmain(){letmut file =File::open("identity.pfx").unwrap();letmut identity =vec![];    file.read_to_end(&mut identity).unwrap();let identity =Identity::from_pkcs12(&identity,"hunter2").unwrap();let acceptor =TlsAcceptor::new(identity).unwrap();let acceptor =Arc::new(acceptor);let listener =TcpListener::bind("0.0.0.0:8443").unwrap();fnhandle_client(stream:TlsStream<TcpStream>){// ...}for streamin listener.incoming(){match stream{Ok(stream) =>{let acceptor = acceptor.clone();                thread::spawn(move ||{let stream = acceptor.accept(stream).unwrap();handle_client(stream);});}Err(e) =>{/* connection failed */}}}}

License

rust-native-tls is primarily distributed under the terms of both the MITlicense and the Apache License (Version 2.0), with portions covered by variousBSD-like licenses.

See LICENSE-APACHE, and LICENSE-MIT for details.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors37

Languages


[8]ページ先頭

©2009-2025 Movatter.jp