Struct portal_lib::protocol::Protocol
source · pub struct Protocol;
Expand description
Lower-level abstraction around the protocol. Use this directly if you’d like more control than what the higher-level Portal interface provides
Implementations§
source§impl Protocol
impl Protocol
sourcepub fn connect<P: Read + Write>(
peer: &mut P,
id: &str,
direction: Direction,
msg: PortalKeyExchange
) -> Result<PortalKeyExchange, Box<dyn Error>>
pub fn connect<P: Read + Write>( peer: &mut P, id: &str, direction: Direction, msg: PortalKeyExchange ) -> Result<PortalKeyExchange, Box<dyn Error>>
Connect to a peer & receive the initial exchange data
sourcepub fn derive_key(
state: Spake2<Ed25519Group>,
peer_data: &PortalKeyExchange
) -> Result<Vec<u8>, Box<dyn Error>>
pub fn derive_key( state: Spake2<Ed25519Group>, peer_data: &PortalKeyExchange ) -> Result<Vec<u8>, Box<dyn Error>>
Derive a shared key with the exchanged PortalConfirmation data. After this point in the exchange we have not verified that our peer has derived the same key as us, just derived the key for ourselves.
sourcepub fn confirm_peer<P: Read + Write>(
peer: &mut P,
id: &str,
direction: Direction,
key: &[u8]
) -> Result<(), Box<dyn Error>>
pub fn confirm_peer<P: Read + Write>( peer: &mut P, id: &str, direction: Direction, key: &[u8] ) -> Result<(), Box<dyn Error>>
Use the derived session key to verify that our peer has derived the same key as us. After this the peer will be fully confirmed.
sourcepub fn read_encrypted_from<R, D>(
reader: &mut R,
key: &[u8]
) -> Result<D, Box<dyn Error>>where
R: Read,
D: DeserializeOwned,
pub fn read_encrypted_from<R, D>( reader: &mut R, key: &[u8] ) -> Result<D, Box<dyn Error>>where R: Read, D: DeserializeOwned,
Read an encrypted owned & deserialize-able object from the peer.
sourcepub fn read_encrypted_zero_copy<R>(
reader: &mut R,
key: &[u8],
storage: &mut [u8]
) -> Result<usize, Box<dyn Error>>where
R: Read,
pub fn read_encrypted_zero_copy<R>( reader: &mut R, key: &[u8], storage: &mut [u8] ) -> Result<usize, Box<dyn Error>>where R: Read,
Read an encrypted message from the peer, writing the resulting decrypted data into the provided storage region. This allows for the ability to receive an encrypted chunk and decrypt it entirely in-place without extra copies.