Compare commits
2 Commits
e4e2498e0a
...
676cda3109
Author | SHA1 | Date | |
---|---|---|---|
|
676cda3109 | ||
|
aca5aa61d0 |
61
Cargo.lock
generated
61
Cargo.lock
generated
@ -115,6 +115,17 @@ dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi 0.1.19",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
@ -142,25 +153,6 @@ version = "0.21.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9"
|
||||
|
||||
[[package]]
|
||||
name = "bincli"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"aes-gcm",
|
||||
"base64",
|
||||
"bs58",
|
||||
"clap",
|
||||
"miniz_oxide",
|
||||
"pbkdf2",
|
||||
"rand",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_with",
|
||||
"sha2",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
@ -571,6 +563,15 @@ version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.3.3"
|
||||
@ -843,7 +844,7 @@ version = "1.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"hermit-abi 0.3.3",
|
||||
"libc",
|
||||
]
|
||||
|
||||
@ -912,6 +913,26 @@ dependencies = [
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pbin"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"aes-gcm",
|
||||
"atty",
|
||||
"base64",
|
||||
"bs58",
|
||||
"clap",
|
||||
"miniz_oxide",
|
||||
"pbkdf2",
|
||||
"rand",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_with",
|
||||
"sha2",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pbkdf2"
|
||||
version = "0.12.2"
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "bincli"
|
||||
name = "pbin"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
@ -7,6 +7,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
aes-gcm = { version = "0.10.3", features = ["aes"] }
|
||||
atty = "0.2.14"
|
||||
base64 = "0.21.5"
|
||||
bs58 = "0.5.0"
|
||||
clap = { version = "4.4.8", features = ["derive"] }
|
||||
|
57
src/main.rs
57
src/main.rs
@ -1,5 +1,5 @@
|
||||
use aes_gcm::{KeyInit,Nonce,aead::Aead};
|
||||
use clap::{ArgAction, Parser};
|
||||
use clap::{ArgAction, Parser,ValueEnum};
|
||||
use pbkdf2::pbkdf2_hmac;
|
||||
use rand::RngCore;
|
||||
use reqwest::Method;
|
||||
@ -21,14 +21,26 @@ struct Cli {
|
||||
burn_after_reading: Option<bool>, // used
|
||||
#[arg(short, long, action=ArgAction::SetFalse, help = "Disable gzip compression")]
|
||||
gzip: Option<bool>, // used
|
||||
#[arg(short, long)]
|
||||
formatter: Option<String>, // used
|
||||
#[arg(short, long, value_enum)]
|
||||
formatter: Option<PasteFormat>, // used
|
||||
#[arg(short, long)]
|
||||
password: Option<String>, // used
|
||||
#[arg(long)]
|
||||
filename: Option<String>,
|
||||
filename: Option<String>, // used
|
||||
#[arg(short, long)]
|
||||
attachment: Option<PathBuf>,
|
||||
attachment: Option<PathBuf>, // used
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Serialize, Clone, ValueEnum)]
|
||||
pub enum PasteFormat {
|
||||
#[serde(rename = "plaintext")]
|
||||
Plaintext,
|
||||
|
||||
#[serde(rename = "syntaxhighlighting")]
|
||||
Syntax,
|
||||
|
||||
#[serde(rename = "markdown")]
|
||||
Markdown,
|
||||
}
|
||||
|
||||
#[skip_serializing_none]
|
||||
@ -46,18 +58,22 @@ fn main() {
|
||||
|
||||
// read piped input
|
||||
let mut input = String::new();
|
||||
std::io::stdin().read_to_string(&mut input).unwrap();
|
||||
//println!("{}", input);
|
||||
|
||||
if atty::isnt(atty::Stream::Stdin) {
|
||||
std::io::stdin().read_to_string(&mut input).unwrap();
|
||||
}
|
||||
|
||||
//println!("{}", input);
|
||||
|
||||
let pasteurl = create_paste(cli, input);
|
||||
println!("url: {}", pasteurl);
|
||||
println!("{}", 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();
|
||||
|
||||
let paste_data = PasteData {
|
||||
let mut paste_data = PasteData {
|
||||
paste: input,
|
||||
attachment: None,
|
||||
attachment_name: None,
|
||||
@ -65,7 +81,18 @@ fn create_paste(cfg: Cli, input: String) -> String {
|
||||
};
|
||||
// check if attachment exists
|
||||
if cfg.attachment.is_some() {
|
||||
// TODO read attachment into paste_data.attachment
|
||||
// read file
|
||||
let file_contents = std::fs::read_to_string(cfg.attachment.unwrap()).unwrap();
|
||||
// encode file contents as data URI
|
||||
let data_uri = format!("data:application/octet-stream;base64,{}", b64.encode(file_contents.as_bytes()));
|
||||
|
||||
paste_data.attachment = Some(data_uri);
|
||||
if cfg.filename.is_some() {
|
||||
paste_data.attachment_name = Some(cfg.filename.unwrap());
|
||||
} else {
|
||||
// must have a filename to show up on the paste
|
||||
paste_data.attachment_name = Some("attachment".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// more info at https://github.com/PrivateBin/PrivateBin/wiki/Encryption-format
|
||||
@ -124,7 +151,7 @@ fn create_paste(cfg: Cli, input: String) -> String {
|
||||
"gcm",
|
||||
compression
|
||||
],
|
||||
cfg.formatter.unwrap_or("plaintext".to_string()),
|
||||
cfg.formatter.unwrap_or(PasteFormat::Plaintext),
|
||||
cfg.open_discussion.unwrap_or_default() as u8,
|
||||
cfg.burn_after_reading.unwrap_or_default() as u8
|
||||
],
|
||||
@ -185,7 +212,13 @@ fn create_paste(cfg: Cli, input: String) -> String {
|
||||
}
|
||||
};
|
||||
|
||||
paste_id = rsv.get("id").unwrap().as_str().unwrap().to_string();
|
||||
paste_id = match rsv.get("id") {
|
||||
Some(v) => v.as_str().unwrap().to_string(),
|
||||
None => {
|
||||
println!("Error: {}", rsv.get("message").unwrap());
|
||||
return String::new();
|
||||
}
|
||||
};
|
||||
}
|
||||
format!(
|
||||
"{}?{}#{}",
|
||||
|
Loading…
x
Reference in New Issue
Block a user