Struct async_psec::Session [−][src]
Expand description
A PSEC connection.
Fields
peer_public_key: Option<[u8; 32]>The public key of the remote peer.
It is None before the PSEC handshake was performed. After a successful call to do_handshake, the field is Some. If the handshake was not successful, the field can be either Some or None depending on where the handshake failed.
let stream = TcpStream::connect("10.152.152.10:7530").await?; let mut psec_session = Session::from(stream); psec_session.do_handshake(&identity).await.unwrap(); println!("Peer public key: {:?}", psec_session.peer_public_key.unwrap());
Implementations
impl Session[src]
impl Session[src]pub fn into_split(self) -> Option<(SessionReadHalf, SessionWriteHalf)>[src]
pub fn into_split(self) -> Option<(SessionReadHalf, SessionWriteHalf)>[src]Split the Session in two parts: a reader and a writer.
Calling this before a successful call to do_handshake will return None.
let (mut session_read, mut session_write) = psec_session.into_split().unwrap(); tokio::spawn(async move { session_write.encrypt_and_send(b"Hello world!", true).await.unwrap(); }); tokio::spawn(async move { println!("Received: {:?}", session_read.receive_and_decrypt().await.unwrap()); });
pub fn peer_addr(&self) -> Result<SocketAddr>[src]
pub fn peer_addr(&self) -> Result<SocketAddr>[src]Return the remote address that this Session is connected to.
use std::net::SocketAddr; let addr: SocketAddr = "10.152.152.10:7530".parse().unwrap(); let stream = TcpStream::connect(addr).await?; let psec_session = Session::from(stream); assert_eq!(psec_session.peer_addr()?, addr);
pub async fn do_handshake(
&mut self,
identity: &Identity
) -> Result<(), PsecError>[src]
pub async fn do_handshake(
&mut self,
identity: &Identity
) -> Result<(), PsecError>[src]Performing a PSEC handshake.
If successful, the Session is ready to send and receive data and you can retrieve the peer public key with the peer_public_key attribute. Otherwise, trying to encrypt or decrypt data with this session will panic.
Trait Implementations
impl PsecReader for Session[src]
impl PsecReader for Session[src]fn set_max_recv_size(&mut self, size: usize, is_raw_size: bool)[src]
fn set_max_recv_size(&mut self, size: usize, is_raw_size: bool)[src]Set the maximum size of an acceptable buffer being received. Read more
fn receive_and_decrypt<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, PsecError>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait, [src]
fn receive_and_decrypt<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, PsecError>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait, [src]Read then decrypt from a PSEC session. Read more
fn into_receive_and_decrypt<'async_trait>(
self
) -> Pin<Box<dyn Future<Output = (Result<Vec<u8>, PsecError>, Self)> + Send + 'async_trait>> where
Self: 'async_trait, [src]
fn into_receive_and_decrypt<'async_trait>(
self
) -> Pin<Box<dyn Future<Output = (Result<Vec<u8>, PsecError>, Self)> + Send + 'async_trait>> where
Self: 'async_trait, [src]Take ownership of the PsecReader, read, decrypt, then return back the PsecReader. Useful when used with tokio::select!. Read more
impl PsecWriter for Session[src]
impl PsecWriter for Session[src]fn encrypt_and_send<'life0, 'life1, 'async_trait>(
&'life0 mut self,
plain_text: &'life1 [u8],
use_padding: bool
) -> Pin<Box<dyn Future<Output = Result<(), PsecError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait, [src]
fn encrypt_and_send<'life0, 'life1, 'async_trait>(
&'life0 mut self,
plain_text: &'life1 [u8],
use_padding: bool
) -> Pin<Box<dyn Future<Output = Result<(), PsecError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait, [src]Encrypt then send through a PSEC session. Read more
Auto Trait Implementations
impl !RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl !UnwindSafe for Session
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]pub fn borrow_mut(&mut self) -> &mut T[src]
pub fn borrow_mut(&mut self) -> &mut T[src]Mutably borrows from an owned value. Read more
impl<T> Same<T> for T
impl<T> Same<T> for Ttype Output = T
type Output = TShould always be Self
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,