A small Protocol Library for Portal - An encrypted file transfer utility
This crate enables a consumer to:
```rust use portal_lib::{Portal,Direction};
// receiver let id = "id".tostring(); let pass ="test".tostring(); let (mut receiver,receiver_msg) = Portal::init(Direction::Receiver,id,pass,None);
// sender let id = "id".tostring(); let pass ="test".tostring(); let (mut sender,sender_msg) = Portal::init(Direction::Sender,id,pass,None);
// Both clients should derive the same key receiver.derivekey(&sendermsg).unwrap(); sender.derivekey(&receivermsg).unwrap(); ```
You can use the confirm_peer() method to verify that a remote peer has derived the same key as you, as long as the communication stream implements the std::io::Read and std::io::Write traits.
```rust use portal_lib::{Portal,Direction}; use std::net::TcpStream; use std::io::Write;
let mut client = TcpStream::connect("127.0.0.1:34254").unwrap();
// Create portal request as the Sender let id = "id".tostring(); let pass ="test".tostring(); let (mut portal,msg) = Portal::init(Direction::Sender,id,pass,None);
// complete key derivation + peer verification
let mut file = portal.load_file("/tmp/test").unwrap();
// Encrypt the file and share state file.encrypt().unwrap(); file.syncfilestate(&mut client).unwrap();
for data in file.getchunks(portallib::CHUNKSIZE) { client.writeall(&data).unwrap(); } ```
```rust use portal_lib::{Portal,Direction}; use std::net::TcpStream; use std::io::Write;
let mut client = TcpStream::connect("127.0.0.1:34254").unwrap();
// receiver let dir = Direction::Receiver; let pass ="test".tostring(); let (mut portal,msg) = Portal::init(dir,"id".tostring(),pass,None);
// serialize & send request let request = portal.serialize().unwrap(); client.write_all(&request).unwrap();
// get response let response = Portal::readresponsefrom(&client).unwrap();
// complete key derivation + peer verification
// create outfile let fsize = response.getfilesize(); let mut file = portal.create_file("/tmp/test", fsize).unwrap();
let callback = |x| { println!("Received {} bytes",x); };
// Receive until connection is done let len = file.download_file(&client,callback).unwrap();
assert_eq!(len as u64, fsize);
// Decrypt the file file.decrypt().unwrap(); ```