Struct StreamBuilder

Source
pub struct StreamBuilder<'a> { /* private fields */ }
Expand description

a builder for Stream

Implementations§

Source§

impl<'a> StreamBuilder<'a>

Source

pub fn socks4(self, proxy: SocketAddr) -> Self

enable socks4 proxying

let builder = builder.socks4("127.0.0.1:9050".parse().unwrap());
Source

pub fn socks4_with_userid(self, proxy: SocketAddr, userid: &'a str) -> Self

enable socks4 proxying with a userid

let builder = builder.socks4_with_userid("127.0.0.1:9050".parse().unwrap(), "meow");
Source

pub fn socks5(self, proxy: SocketAddr) -> Self

enable socks5 proxying

let builder = builder.socks5("127.0.0.1:9050".parse().unwrap());
Source

pub fn socks5_with_password( self, proxy: SocketAddr, username: &'a str, password: &'a str, ) -> Self

enable socks5 proxying with password authentication

let builder =
    builder.socks5_with_password("127.0.0.1:9050".parse().unwrap(), "AzureDiamond", "hunter2");
Source

pub fn tls_danger_insecure(self, domain: Option<ServerName<'static>>) -> Self

enable tls without any verification

use tokio_rustls::rustls::pki_types::ServerName;
let builder = builder.tls_danger_insecure(Some(ServerName::try_from("google.com").unwrap()));
Source

pub fn tls_with_root( self, domain: Option<ServerName<'static>>, root: impl Into<Arc<RootCertStore>>, ) -> Self

enable tls with root certificate verification

can also be used to pin a self-signed cert as long as it has a CA:FALSE constraint

use tokio_rustls::rustls::RootCertStore;
use tokio_rustls::rustls::pki_types::{CertificateDer, ServerName, pem::PemObject};

let mut root = RootCertStore::empty();
root.add_parsable_certificates(
    CertificateDer::pem_file_iter("/etc/ssl/cert.pem")
        .unwrap()
        .flatten(),
);
let builder = builder.tls_with_root(None, root);
Source

pub fn tls_with_webpki( self, domain: Option<ServerName<'static>>, webpki: Arc<WebPkiServerVerifier>, ) -> Self

enable tls with a webpki verifier

Source

pub fn client_cert( self, cert_chain: Vec<CertificateDer<'static>>, key_der: PrivateKeyDer<'static>, ) -> Self

use a tls client certificate

requires tls to be enabled

use irc_connect::Stream;
use std::net::SocketAddr;
use tokio_rustls::rustls::pki_types::{CertificateDer, PrivateKeyDer, ServerName, pem::PemObject};

let builder = Stream::new_tcp("[::1]:6667").tls_danger_insecure(None);
let cert = CertificateDer::pem_file_iter("cert.pem")
    .unwrap()
    .collect::<Result<Vec<_>, _>>()
    .unwrap();
let key = PrivateKeyDer::from_pem_file("cert.key").unwrap();
let builder = builder.client_cert(cert, key);
Source

pub async fn connect(self) -> Result<Stream, Error>

finish building and open the connection

let stream = builder.connect().await.unwrap();
§Errors

will return Error if an invalid combination of options has been given to the builder, or if it is unable to connect

Trait Implementations§

Source§

impl<'a> Debug for StreamBuilder<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for StreamBuilder<'a>

§

impl<'a> !RefUnwindSafe for StreamBuilder<'a>

§

impl<'a> Send for StreamBuilder<'a>

§

impl<'a> Sync for StreamBuilder<'a>

§

impl<'a> Unpin for StreamBuilder<'a>

§

impl<'a> !UnwindSafe for StreamBuilder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.