Struct Link

Source
pub struct Link<S> { /* private fields */ }
Expand description

Link layer is a wrapper around TCP or SSL stream It can swicth from TCP to SSL

Implementations§

Source§

impl<S: Read + Write> Link<S>

Source

pub fn new(stream: Stream<S>) -> Self

Create a new link layer from a Stream

§Example
use rdp::model::link::{Link, Stream};
use std::io::Cursor;
use std::net::{TcpStream, SocketAddr};
let link = Link::new(Stream::Raw(Cursor::new(vec![])));
let addr = "127.0.0.1:3389".parse::<SocketAddr>().unwrap();
let link_tcp = Link::new(Stream::Raw(TcpStream::connect(&addr).unwrap()));
Source

pub fn write(&mut self, message: &dyn Message) -> RdpResult<()>

This method is designed to write a Message either for TCP or SSL stream

§Example
    let mut link = Link::new(Stream::Raw(Cursor::new(vec![])));
    link.write(&component![
        "foo" => U32::LE(1)
    ]).unwrap();

    if let Stream::Raw(r) = link.get_stream() {
        assert_eq!(r.into_inner(), [1, 0, 0, 0])
    }
    else {
        panic!("invalid")
    }
Source

pub fn read(&mut self, expected_size: usize) -> RdpResult<Vec<u8>>

This function will block until the expected size will be read

§Example
use rdp::model::link::{Link, Stream};
use std::io::Cursor;
let mut link = Link::new(Stream::Raw(Cursor::new(vec![0, 1, 2])));
assert_eq!(link.read(2).unwrap(), [0, 1])
Source

pub fn start_ssl(self, check_certificate: bool) -> RdpResult<Link<S>>

Start a ssl connection from a raw stream

§Example
use rdp::model::link::{Link, Stream};
use std::net::{TcpStream, SocketAddr};
let addr = "127.0.0.1:3389".parse::<SocketAddr>().unwrap();
let link_tcp = Link::new(Stream::Raw(TcpStream::connect(&addr).unwrap()));
let link_ssl = link_tcp.start_ssl(false).unwrap();
Source

pub fn get_peer_certificate(&self) -> RdpResult<Option<Certificate>>

Retrive the peer certificate Use by the NLA authentication protocol to avoid MITM attack

§Example
use rdp::model::link::{Link, Stream};
use std::net::{TcpStream, SocketAddr};
let addr = "127.0.0.1:3389".parse::<SocketAddr>().unwrap();
let link_tcp = Link::new(Stream::Raw(TcpStream::connect(&addr).unwrap()));
let link_ssl = link_tcp.start_ssl(false).unwrap();
let certificate = link_ssl.get_peer_certificate().unwrap().unwrap();
Source

pub fn shutdown(&mut self) -> RdpResult<()>

Close the stream Only works on SSL Stream

Auto Trait Implementations§

§

impl<S> Freeze for Link<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Link<S>
where S: RefUnwindSafe,

§

impl<S> Send for Link<S>
where S: Send,

§

impl<S> Sync for Link<S>
where S: Sync,

§

impl<S> Unpin for Link<S>
where S: Unpin,

§

impl<S> UnwindSafe for Link<S>
where S: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V