Trait async_psec::PsecReader[][src]

pub trait PsecReader {
    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
        'life0: 'async_trait,
        Self: '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

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.

Read then decrypt from a PSEC session.

Panic

Panics if the PSEC handshake is not finished and successful.

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...
    }
}

Implementors