File tree 4 files changed +60
-5
lines changed
4 files changed +60
-5
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ with-eui48 = ["eui48"]
27
27
with-openssl = [" openssl" ]
28
28
with-native-tls = [" native-tls" ]
29
29
with-rustc-serialize = [" rustc-serialize" ]
30
+ with-schannel = [" schannel" ]
30
31
with-security-framework = [" security-framework" ]
31
32
with-serde_json = [" serde_json" ]
32
33
with-time = [" time" ]
@@ -47,6 +48,7 @@ eui48 = { version = "0.1", optional = true }
47
48
openssl = { version = " 0.9" , optional = true }
48
49
native-tls = { version = " 0.1" , optional = true }
49
50
rustc-serialize = { version = " 0.3" , optional = true }
51
+ schannel = { version = " 0.1" , optional = true }
50
52
security-framework = { version = " 0.1.2" , optional = true }
51
53
serde_json = { version = " >= 0.6, < 0.9" , optional = true }
52
54
time = { version = " 0.1.14" , optional = true }
Original file line number Diff line number Diff line change 43
43
//!
44
44
//! This crate supports TLS secured connections. The `TlsMode` enum is passed to connection methods
45
45
//! and indicates if the connection will not, may, or must be secured by TLS. The TLS implementation
46
- //! is pluggable through the `TlsHandshake` trait. Implementations for OpenSSL and OSX's Secure
47
- //! Transport are provided behind the `with-openssl`, `with-security-framework`, and
48
- //! `with-native-tls` feature flags respectively.
46
+ //! is pluggable through the `TlsHandshake` trait. Implementations for OpenSSL, Secure Transport,
47
+ //! SChannel, and the `native-tls` crate are provided behind the `with-openssl`,
48
+ //! `with-security-framework`, `with-schannel`, and `with- native-tls` feature flags respectively.
49
49
//!
50
50
//! ## Examples
51
51
//!
Original file line number Diff line number Diff line change @@ -5,12 +5,14 @@ use std::error::Error;
5
5
use std:: io:: prelude:: * ;
6
6
use std:: fmt;
7
7
8
+ #[ cfg( feature = "with-native-tls" ) ]
9
+ pub mod native_tls;
8
10
#[ cfg( feature = "with-openssl" ) ]
9
11
pub mod openssl;
12
+ #[ cfg( feature = "with-schannel" ) ]
13
+ pub mod schannel;
10
14
#[ cfg( feature = "with-security-framework" ) ]
11
15
pub mod security_framework;
12
- #[ cfg( feature = "with-native-tls" ) ]
13
- pub mod native_tls;
14
16
15
17
/// A trait implemented by TLS streams.
16
18
pub trait TlsStream : fmt:: Debug + Read + Write + Send {
Original file line number Diff line number Diff line change
1
+ //! SChannel support.
2
+
3
+ extern crate schannel;
4
+
5
+ use std:: error:: Error ;
6
+ use std:: fmt;
7
+
8
+ use self :: schannel:: schannel_cred:: { SchannelCred , Direction } ;
9
+ use self :: schannel:: tls_stream;
10
+ use tls:: { TlsStream , Stream , TlsHandshake } ;
11
+
12
+ impl TlsStream for tls_stream:: TlsStream < Stream > {
13
+ fn get_ref ( & self ) -> & Stream {
14
+ self . get_ref ( )
15
+ }
16
+
17
+ fn get_mut ( & mut self ) -> & mut Stream {
18
+ self . get_mut ( )
19
+ }
20
+ }
21
+
22
+ /// A `TlsHandshake` implementation that uses the `schannel` crate.
23
+ ///
24
+ /// Requires the `with-schannel` feature.
25
+ pub struct Schannel ( ( ) ) ;
26
+
27
+ impl fmt:: Debug for Schannel {
28
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
29
+ fmt. debug_struct ( "Schannel" ) . finish ( )
30
+ }
31
+ }
32
+
33
+ impl Schannel {
34
+ /// Constructs a new `SChannel` with a default configuration.
35
+ pub fn new ( ) -> Schannel {
36
+ Schannel ( ( ) )
37
+ }
38
+ }
39
+
40
+ impl TlsHandshake for Schannel {
41
+ fn tls_handshake ( & self ,
42
+ host : & str ,
43
+ stream : Stream )
44
+ -> Result < Box < TlsStream > , Box < Error + Sync + Send > > {
45
+ let creds = try!( SchannelCred :: builder ( ) . acquire ( Direction :: Outbound ) ) ;
46
+ let stream = try!( tls_stream:: Builder :: new ( )
47
+ . domain ( host)
48
+ . connect ( creds, stream) ) ;
49
+ Ok ( Box :: new ( stream) )
50
+ }
51
+ }
You can’t perform that action at this time.
0 commit comments