{"id":13438911,"url":"https://github.com/sfackler/rust-native-tls","last_synced_at":"2025-05-13T19:09:32.529Z","repository":{"id":7600298,"uuid":"56415591","full_name":"sfackler/rust-native-tls","owner":"sfackler","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-19T19:24:45.000Z","size":427,"stargazers_count":507,"open_issues_count":69,"forks_count":212,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-26T12:45:29.298Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sfackler.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["sfackler"]}},"created_at":"2016-04-17T02:40:11.000Z","updated_at":"2025-04-26T05:13:49.000Z","dependencies_parsed_at":"2024-10-19T07:37:56.693Z","dependency_job_id":"8ad95d29-514d-4e78-97aa-8dddf17da48a","html_url":"https://github.com/sfackler/rust-native-tls","commit_stats":{"total_commits":368,"total_committers":40,"mean_commits":9.2,"dds":0.4184782608695652,"last_synced_commit":"a0e6f1827f212ea431c367a58a409dc46355057e"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sfackler%2Frust-native-tls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sfackler%2Frust-native-tls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sfackler%2Frust-native-tls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sfackler%2Frust-native-tls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sfackler","download_url":"https://codeload.github.com/sfackler/rust-native-tls/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251089620,"owners_count":21534523,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:09.555Z","updated_at":"2025-04-27T05:01:33.228Z","avatar_url":"https://github.com/sfackler.png","language":"Rust","readme":"# rust-native-tls\n\n[Documentation](https://docs.rs/native-tls)\n\nAn abstraction over platform-specific TLS implementations.\n\nSpecifically, this crate uses SChannel on Windows (via the [`schannel`] crate),\nSecure Transport on macOS (via the [`security-framework`] crate), and OpenSSL (via\nthe [`openssl`] crate) on all other platforms.\n\n[`schannel`]: https://crates.io/crates/schannel\n[`security-framework`]: https://crates.io/crates/security-framework\n[`openssl`]: https://crates.io/crates/openssl\n\n## Installation\n\n```toml\n# Cargo.toml\n[dependencies]\nnative-tls = \"0.2\"\n```\n\n## Usage\n\nAn example client looks like:\n\n```rust,ignore\nextern crate native_tls;\n\nuse native_tls::TlsConnector;\nuse std::io::{Read, Write};\nuse std::net::TcpStream;\n\nfn main() {\n    let connector = TlsConnector::new().unwrap();\n\n    let stream = TcpStream::connect(\"google.com:443\").unwrap();\n    let mut stream = connector.connect(\"google.com\", stream).unwrap();\n\n    stream.write_all(b\"GET / HTTP/1.0\\r\\n\\r\\n\").unwrap();\n    let mut res = vec![];\n    stream.read_to_end(\u0026mut res).unwrap();\n    println!(\"{}\", String::from_utf8_lossy(\u0026res));\n}\n```\n\nTo accept connections as a server from remote clients:\n\n```rust,ignore\nextern crate native_tls;\n\nuse native_tls::{Identity, TlsAcceptor, TlsStream};\nuse std::fs::File;\nuse std::io::{Read};\nuse std::net::{TcpListener, TcpStream};\nuse std::sync::Arc;\nuse std::thread;\n\nfn main() {\n    let mut file = File::open(\"identity.pfx\").unwrap();\n    let mut identity = vec![];\n    file.read_to_end(\u0026mut identity).unwrap();\n    let identity = Identity::from_pkcs12(\u0026identity, \"hunter2\").unwrap();\n\n    let acceptor = TlsAcceptor::new(identity).unwrap();\n    let acceptor = Arc::new(acceptor);\n\n    let listener = TcpListener::bind(\"0.0.0.0:8443\").unwrap();\n\n    fn handle_client(stream: TlsStream\u003cTcpStream\u003e) {\n        // ...\n    }\n\n    for stream in listener.incoming() {\n        match stream {\n            Ok(stream) =\u003e {\n                let acceptor = acceptor.clone();\n                thread::spawn(move || {\n                    let stream = acceptor.accept(stream).unwrap();\n                    handle_client(stream);\n                });\n            }\n            Err(e) =\u003e { /* connection failed */ }\n        }\n    }\n}\n```\n\n# License\n\n`rust-native-tls` is primarily distributed under the terms of both the MIT\nlicense and the Apache License (Version 2.0), with portions covered by various\nBSD-like licenses.\n\nSee LICENSE-APACHE, and LICENSE-MIT for details.\n","funding_links":["https://github.com/sponsors/sfackler"],"categories":["Libraries","Rust","库 Libraries","库"],"sub_categories":["Cryptography","密码学 Cryptography","加密"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsfackler%2Frust-native-tls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsfackler%2Frust-native-tls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsfackler%2Frust-native-tls/lists"}