portal-lib 0.1.0

A Secure file transfer library, written in Rust. The library utilizes SPAKE2 for key negotiation over an insecure channel, and ChaCha20Poly1305 Authenticated Encryption to encrypt the file with the derived shared symmetric key. This enables two peers to transfer a file over any channel without needing to trust the intermediary relay.
Documentation

pub struct PortalChunks<'a, T: 'a> {
    v: &'a [T],
    chunk_size: usize,
}

impl<'a, T: 'a> PortalChunks<'a, T> {
    pub fn init(data: &'a [T], chunk_size: usize) -> PortalChunks<'a,T> {
        PortalChunks{
            v: data, // TODO: verify that this is zero-copy/move
            chunk_size: chunk_size,
        }
    }
}


impl<'a> Iterator for PortalChunks<'a,u8> 
{
    type Item = &'a [u8];

    // The return type is `Option<T>`:
    //     * When the `Iterator` is finished, `None` is returned.
    //     * Otherwise, the next value is wrapped in `Some` and returned.
    fn next(&mut self) -> Option<Self::Item> {

        // return up to the next chunk size
        if self.v.is_empty() {
            return None;
        }

        // split to get the next chunk and move the slice along
        let chunksz = std::cmp::min(self.v.len(), self.chunk_size);
        let (beg,end) = self.v.split_at(chunksz);

        // update next slice 
        self.v = end; 
        Some(beg)
    }
}