Trait PsecReader

Source
pub trait PsecReader {
    // Required methods
    fn set_max_recv_size(&mut self, size: usize, is_raw_size: bool);
    fn receive_and_decrypt<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, PsecError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    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;
}
Expand description

Read from a PSEC session.

Required Methods§

Source

fn set_max_recv_size(&mut self, size: usize, is_raw_size: bool)

Set the maximum size of an acceptable buffer being received.

Any received buffer larger than this value will be discarded and a BufferTooLarge error will be returned. Then, the PSEC session should be closed to prevent any DOS attacks.

If is_raw_size is set to true, the specified size will correspond to the maximum encrypted buffer size, including potential padding. Otherwise, the maximum buffer size will correspond to the length of a message of this size after applying padding and encryption.

Source

fn receive_and_decrypt<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, PsecError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Read then decrypt from a PSEC session.

§Panic

Panics if the PSEC handshake is not finished and successful.

Source

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,

Take ownership of the PsecReader, read, decrypt, then return back the PsecReader. Useful when used with tokio::select!.

§Panic

Panics if the PSEC handshake is not finished and successful.

let receiving = psec_session.into_receive_and_decrypt();
tokio::pin!(receiving);

loop {
    tokio::select! {
        result = &mut receiving => {
            let (buffer, psec_session) = result;

            receiving.set(psec_session.into_receive_and_decrypt());
             
            match buffer {
                Ok(buffer) => println!("Received: {:?}", buffer),
                Err(e) => println!("Error: {}", e)
            }
        }
        //other select! branches...
    }
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§