fn explicit_tls_version() {
    use rustls::{ClientSession, ProtocolVersion, TLSError};
    use std::io::Read;
    use std::net::TcpStream;

    let _server = Server::new(&["--addr", "[::]:1976", "-3"]);

    let mut config = rustls::ClientConfig::new();
    // try to connect using only TLS 1.2
    config.versions = vec![ProtocolVersion::TLSv1_2];

    let dns_name = webpki::DNSNameRef::try_from_ascii_str("localhost").unwrap();
    let mut session = ClientSession::new(&std::sync::Arc::new(config), dns_name);
    let mut tcp = TcpStream::connect(addr(1976)).unwrap();
    let mut tls = rustls::Stream::new(&mut session, &mut tcp);

    let mut buf = [0; 10];
    assert_eq!(
        *tls.read(&mut buf)
            .unwrap_err()
            .into_inner()
            .unwrap()
            .downcast::<TLSError>()
            .unwrap(),
        TLSError::AlertReceived(rustls::internal::msgs::enums::AlertDescription::ProtocolVersion)
    )
}
/// - if TLSv1.3 is selected, does not accept TLSv1.2 connections
///   (lower versions do not have to be tested because rustls does not even
///   support them, making agate incapable of accepting them)
if TLSv1.3 is selected, does not accept TLSv1.2 connections
(lower versions do not have to be tested because rustls does not even
support them, making agate incapable of accepting them)
if TLSv1 . 3 is selected does not accept TLSv1 . 2 connections ( lower versions do not have to be tested because rustls does not even support them making agate incapable of accepting them )
fn explicit_tls_version() {
    use rustls::{ClientSession, ProtocolVersion, TLSError};
    use std::io::Read;
    use std::net::TcpStream;
    let _server = Server::new(&["--addr", "[::]:1976", "-3"]);
    let mut config = rustls::ClientConfig::new();
    // try to connect using only TLS 1.2
    config.versions = vec![ProtocolVersion::TLSv1_2];
    let dns_name = webpki::DNSNameRef::try_from_ascii_str("localhost").unwrap();
    let mut session = ClientSession::new(&std::sync::Arc::new(config), dns_name);
    let mut tcp = TcpStream::connect(addr(1976)).unwrap();
    let mut tls = rustls::Stream::new(&mut session, &mut tcp);
    let mut buf = [0; 10];
    assert_eq!(
        *tls.read(&mut buf)
            .unwrap_err()
            .into_inner()
            .unwrap()
            .downcast::<TLSError>()
            .unwrap(),
        TLSError::AlertReceived(rustls::internal::msgs::enums::AlertDescription::ProtocolVersion)
    )
}
fn explicit_tls_version ( ) { use rustls :: { ClientSession , ProtocolVersion , TLSError } ; use std :: io :: Read ; use std :: net :: TcpStream ; let _server = Server :: new ( & [ " " , " " , " " ] ) ; let mut config = rustls :: ClientConfig :: new ( ) ; // try to connect using only TLS 1.2 config . versions = vec ! [ ProtocolVersion TLSv1_2 ] ; let dns_name = webpki :: DNSNameRef :: try_from_ascii_str ( " " ) . unwrap ( ) ; let mut session = ClientSession :: new ( & std :: sync :: Arc :: new ( config ) , dns_name ) ; let mut tcp = TcpStream :: connect ( addr ( 1976 ) ) . unwrap ( ) ; let mut tls = rustls :: Stream :: new ( & mut session , & mut tcp ) ; let mut buf = [ 0 ; 10 ] ; assert_eq ! ( tls read ( mut buf ) unwrap_err ( ) into_inner ( ) unwrap ( ) downcast TLSError ( ) unwrap ( ) TLSError AlertReceived ( rustls internal msgs enums AlertDescription ProtocolVersion ) ) }
if TLSv1.3 is selected, does not accept TLSv1.2 connections
(lower versions do not have to be tested because rustls does not even
support them, making agate incapable of accepting them)
if TLSv1 . 3 is selected does not accept TLSv1 . 2 connections ( lower versions do not have to be tested because rustls does not even support them making agate incapable of accepting them )