Struct async_psec::Session[][src]

pub struct Session {
    pub peer_public_key: Option<[u8; 32]>,
    // some fields omitted
}
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

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());
});    

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);

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

Formats the value using the given formatter. Read more

Performs the conversion.

Set the maximum size of an acceptable buffer being received. Read more

Read then decrypt from a PSEC session. Read more

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

Encrypt then send through a PSEC session. Read more

Encrypt a buffer but return it instead of sending it. Read more

Send a previously encrypted buffer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.