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>
impl<S: Read + Write> Link<S>
Sourcepub fn new(stream: Stream<S>) -> Self
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()));
Sourcepub fn write(&mut self, message: &dyn Message) -> RdpResult<()>
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")
}
Sourcepub fn read(&mut self, expected_size: usize) -> RdpResult<Vec<u8>>
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])
Sourcepub fn start_ssl(self, check_certificate: bool) -> RdpResult<Link<S>>
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();
Sourcepub fn get_peer_certificate(&self) -> RdpResult<Option<Certificate>>
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();
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more