use std::{ fs::File, io::Read, str::FromStr, }; use hyper::body::HttpBody; use ciph::salsa::{Psk, Connector, Randomness, HyperSalsaConnector}; #[tokio::main] async fn main() -> Result<(), Box> { const PSK_B64: &str = include_str!("example.psk"); let psk = Psk::from_str(PSK_B64)?; let connector = Connector::new(psk, Randomness::Entropy); let args: Vec = std::env::args() .collect(); assert!(args.len() >= 3); let uri: hyper::Uri = args[1].parse()?; // Slurp our file. let filename = args[2].to_owned(); let mut file =File::open(filename.as_str())?; let mut file_b = Vec::new(); file.read_to_end(&mut file_b)?; let length = file_b.len(); println!("File {} is {} bytes.", &filename, length); let body = hyper::Body::from(file_b.clone()); // Yeeeehaw! let request = hyper::Request::builder() .uri(uri) .method("POST") .body(body)?; let connector = HyperSalsaConnector::new_http(connector); let client = hyper::Client::builder() .build::<_, hyper::Body>(connector); let mut response = client .request(request) .await?; let mut buffer: Vec = Vec::new(); while let Some(chunk) = response.data().await { buffer.extend(chunk?); } assert_eq!(buffer.as_slice(), file_b.as_slice()); println!("Echo equivalent!"); Ok(()) }