[][src]Struct portal_lib::file::PortalFile

pub struct PortalFile {
    pub mmap: MmapMut,
    pub cipher: ChaCha20Poly1305,
    // some fields omitted
}

A file mapping that contains state to encrypt/decrypt files in memory

Fields

mmap: MmapMutcipher: ChaCha20Poly1305

Implementations

impl PortalFile[src]

pub fn init(mmap: MmapMut, cipher: ChaCha20Poly1305) -> PortalFile[src]

pub fn encrypt(&mut self) -> Result<()>[src]

Encrypts the current PortalFile, by encrypting the mmap'd memory in-place

pub fn decrypt(&mut self) -> Result<()>[src]

Decrypts the current PortalFile, by decrypting the mmap'd memory in-place

pub fn sync_file_state<W>(&mut self, writer: W) -> Result<usize> where
    W: Write
[src]

Writes the nonce and tag for this file to the provided writer. Use after encrypting a file to communicate state data to the peer that will decrypt the file

pub fn download_file<R, F>(&mut self, reader: R, callback: F) -> Result<u64> where
    R: Read,
    F: Fn(u64), 
[src]

Downloads a file, first by retrieving the Tag and Nonce communicated by sync_file_state() and then reading in the file until EOF

This example is not tested
Peer A                  Peer B
encrypt()               download_file()
sync_file_state()       decrypt()
// send chunks

pub fn get_chunks<'a>(
    &'a self,
    chunk_size: usize
) -> impl Iterator<Item = &'a [u8]>
[src]

Returns an iterator over the chunks to send it over the network

Examples

This example is not tested
for data in file.get_chunks(portal::CHUNK_SIZE) {
     client.write_all(&data)?
     total += data.len();
     pb.set_position(total as u64);
}

pub fn write_given_chunk(&mut self, data: &[u8]) -> Result<u64>[src]

Writes the provided data to the file in-memory at the current position

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,