fix import statements

This commit is contained in:
winwinner 2023-11-22 12:50:43 +00:00
parent ce6447f30a
commit e4e2498e0a
Signed by: winneratwin
GPG Key ID: F11B4D71AD94CFB8

View File

@ -1,11 +1,9 @@
use aes_gcm::aead::Aead;
use aes_gcm::KeyInit;
use aes_gcm::Nonce;
use aes_gcm::{KeyInit,Nonce,aead::Aead};
use clap::{ArgAction, Parser};
use pbkdf2::pbkdf2_hmac;
use rand::RngCore;
use serde::Deserialize;
use serde::Serialize;
use reqwest::Method;
use serde::{Deserialize,Serialize};
use serde_with::skip_serializing_none;
use sha2::Sha256;
use std::{io::Read, path::PathBuf};
@ -28,7 +26,7 @@ struct Cli {
#[arg(short, long)]
password: Option<String>, // used
#[arg(long)]
filename: Option<String>,
filename: Option<String>,
#[arg(short, long)]
attachment: Option<PathBuf>,
}
@ -52,10 +50,9 @@ fn main() {
//println!("{}", input);
let pasteurl = create_paste(cli, input);
println!("url: {}", pasteurl);
println!("url: {}", pasteurl);
}
fn create_paste(cfg: Cli, input: String) -> String {
use base64::{engine::general_purpose::STANDARD as b64, Engine as _};
let mut rng = rand::thread_rng();
@ -69,15 +66,14 @@ fn create_paste(cfg: Cli, input: String) -> String {
// check if attachment exists
if cfg.attachment.is_some() {
// TODO read attachment into paste_data.attachment
}
// more info at https://github.com/PrivateBin/PrivateBin/wiki/Encryption-format
// generate random 256 bit key
let mut paste_key = [0u8; 32]; // 256 bits
rng.fill_bytes(&mut paste_key);
// add password to key if it exists
rng.fill_bytes(&mut paste_key);
// add password to key if it exists
let key_and_password: Vec<u8> = paste_key
.iter()
.chain(cfg.password.unwrap_or("".to_string()).as_bytes().iter())
@ -170,33 +166,31 @@ fn create_paste(cfg: Cli, input: String) -> String {
//println!("b58: {}", post_key);
// check if url is set and upload to that url
let mut paste_id = String::new();
let mut paste_id = String::new();
if let Some(url) = &cfg.url {
use reqwest::{Method, Url};
//println!("url: {}", url);
let client = reqwest::blocking::Client::builder().build().unwrap();
let mut request = client.request(Method::POST, url);
request = request.header("X-Requested-With", "JSONHttpRequest");
let res = request.body::<String>(serde_json::to_string(&post_body).unwrap()).send().unwrap();
request = request.header("X-Requested-With", "JSONHttpRequest");
let res = request
.body::<String>(serde_json::to_string(&post_body).unwrap())
.send()
.unwrap();
let rsv: serde_json::Value = match res.json() {
Ok(v) => {
v
},
Err(e) => {
println!("Error: {}", e);
return String::new();
}
};
let rsv: serde_json::Value = match res.json() {
Ok(v) => v,
Err(e) => {
println!("Error: {}", e);
return String::new();
}
};
paste_id = rsv.get("id").unwrap().as_str().unwrap().to_string();
paste_id = rsv.get("id").unwrap().as_str().unwrap().to_string();
}
format!(
"{}?{}#{}",
cfg.url.unwrap_or("https://EXAMPLE.com/".to_string()),
paste_id,
post_key
)
format!(
"{}?{}#{}",
cfg.url.unwrap_or("https://EXAMPLE.com/".to_string()),
paste_id,
post_key
)
}