pub struct Client<S> { /* private fields */ }
Expand description
Client Context of TPKT layer
§Example
use std::io::Cursor;
use rdp::model::link::{Link, Stream};
use rdp::core::tpkt::Client;
let mut stream = Cursor::new(vec![]);
let tpkt_client = Client::new(Link::new(Stream::Raw(stream)));
Implementations§
Source§impl<S: Read + Write> Client<S>
impl<S: Read + Write> Client<S>
Sourcepub fn write<T>(&mut self, message: T) -> RdpResult<()>where
T: Message + 'static,
pub fn write<T>(&mut self, message: T) -> RdpResult<()>where
T: Message + 'static,
Send a message to the link layer with appropriate header Move to avoid copy
§Example
#[macro_use]
let mut tpkt = tpkt::Client::new(link::Link::new(link::Stream::Raw(Cursor::new(vec![]))));
tpkt.write(trame![U16::BE(4), U32::LE(3)]).unwrap();
// get_link and get_stream are not available on Crate
// only use for integration test [features = integration]
if let link::Stream::Raw(e) = tpkt.get_link().get_stream() {
assert_eq!(e.into_inner(), [3, 0, 0, 10, 0, 4, 3, 0, 0, 0])
}
else {
panic!("Must not happen")
}
}
Sourcepub fn read(&mut self) -> RdpResult<Payload>
pub fn read(&mut self) -> RdpResult<Payload>
Read a payload from the underlying layer Check the tpkt header and provide a well formed payload
§Example
use rdp::core::tpkt;
use rdp::model::link;
use std::io::Cursor;
let mut tpkt = tpkt::Client::new(link::Link::new(link::Stream::Raw(Cursor::new(vec![3, 0, 0, 10, 0, 4, 3, 0, 0, 0]))));
if let tpkt::Payload::Raw(c) = tpkt.read().unwrap() {
assert_eq!(c.into_inner(), vec![0, 4, 3, 0, 0, 0])
}
else {
panic!("unexpected result")
}
tpkt = tpkt::Client::new(link::Link::new(link::Stream::Raw(Cursor::new(vec![0, 6, 0, 0, 0, 0]))));
if let tpkt::Payload::FastPath(_, c) = tpkt.read().unwrap() {
assert_eq!(c.into_inner(), vec![0, 0, 0, 0])
}
else {
panic!("unexpected result")
}
tpkt = tpkt::Client::new(link::Link::new(link::Stream::Raw(Cursor::new(vec![0, 0x80, 7, 0, 0, 0, 0]))));
if let tpkt::Payload::FastPath(_, c) = tpkt.read().unwrap() {
assert_eq!(c.into_inner(), vec![0, 0, 0, 0])
}
else {
panic!("unexpected result")
}
Sourcepub fn start_ssl(self, check_certificate: bool) -> RdpResult<Client<S>>
pub fn start_ssl(self, check_certificate: bool) -> RdpResult<Client<S>>
This function transform the link layer with raw data stream into a SSL data stream
§Example
use std::net::{SocketAddr, TcpStream};
use rdp::core::tpkt;
use rdp::model::link;
let addr = "127.0.0.1:3389".parse::<SocketAddr>().unwrap();
let mut tcp = TcpStream::connect(&addr).unwrap();
let mut tpkt = tpkt::Client::new(link::Link::new(link::Stream::Raw(tcp)));
let mut tpkt_ssl = tpkt.start_ssl(false).unwrap();
Sourcepub fn start_nla(
self,
check_certificate: bool,
authentication_protocol: &mut dyn AuthenticationProtocol,
restricted_admin_mode: bool,
) -> RdpResult<Client<S>>
pub fn start_nla( self, check_certificate: bool, authentication_protocol: &mut dyn AuthenticationProtocol, restricted_admin_mode: bool, ) -> RdpResult<Client<S>>
This function is used when NLA (Network Level Authentication) Authentication is negotiated
§Example
use std::net::{SocketAddr, TcpStream};
use rdp::core::tpkt;
use rdp::nla::ntlm::Ntlm;
use rdp::model::link;
let addr = "127.0.0.1:3389".parse::<SocketAddr>().unwrap();
let mut tcp = TcpStream::connect(&addr).unwrap();
let mut tpkt = tpkt::Client::new(link::Link::new(link::Stream::Raw(tcp)));
let mut tpkt_nla = tpkt.start_nla(false, &mut Ntlm::new("domain".to_string(), "username".to_string(), "password".to_string()), false);
Auto Trait Implementations§
impl<S> Freeze for Client<S>where
S: Freeze,
impl<S> RefUnwindSafe for Client<S>where
S: RefUnwindSafe,
impl<S> Send for Client<S>where
S: Send,
impl<S> Sync for Client<S>where
S: Sync,
impl<S> Unpin for Client<S>where
S: Unpin,
impl<S> UnwindSafe for Client<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