wala-rust

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

commit b2c7a7554f650fa29c25577853eab338f37fcd89
parent 30ab03b4fa1f103391c2b77a6df5f83eb3346e05
Author: lash <dev@holbrook.no>
Date:   Fri, 23 Sep 2022 13:10:20 +0000

Add send cli binary with immutable put and mutable pointer

Diffstat:
MCargo.toml | 10++++++++++
Asrc/main_send.rs | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/record.rs | 2+-
3 files changed, 117 insertions(+), 1 deletion(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -10,6 +10,11 @@ repository = "https://git.defalsify.org/wala" # from https://crates.io/category_slugs categories = ["web-programming::http-server"] +[[bin]] +name = 'wala_send' +path = 'src/main_send.rs' +required_features = 'client' + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -22,6 +27,7 @@ tempfile = "^3.3.0" mime = "^0.3.13" ascii = "^1.0.0" clap = "^2.34.0" +url = "^2.2.2" [dependencies.tree_magic] version = "^0.2.3" @@ -36,6 +42,9 @@ optional = true version = "^0.13.0" optional = true +[dependencies.ureq] +version = "^2.5.0" +optional = true [features] pgpauth = ["pgp", "base64"] @@ -43,3 +52,4 @@ dev = [] magic = ["tree_magic"] meta = [] trace = [] +client = ["ureq"] diff --git a/src/main_send.rs b/src/main_send.rs @@ -0,0 +1,106 @@ +use log::{debug}; +use ureq::{Agent, AgentBuilder}; +use env_logger; +use clap::{ + App, + Arg, +}; +use url::Url; + +use wala::record::{ResourceKey}; +use wala::auth::{AuthResult}; + + +//fn clean_hex(s: &[u8]) -> &[u8] { + +//} + +fn main() { + env_logger::init(); + + let mut o = App::new("wala_send"); + o = o.version("0.1.0"); + o = o.author("Louis Holbrook <dev@holbrook.no>"); + + o = o.arg(clap::Arg::with_name("id") + .short("i") + .long("id") + .takes_value(true) + .multiple(true) + ); + + o = o.arg(clap::Arg::with_name("key") + .short("k") + .long("key") + .takes_value(true) + ); + + o = o.arg(clap::Arg::with_name("URL") + .required(true) + .index(1) + ); + + let args = o.get_matches(); + + let mut d: Vec<u8> = vec!(); + let mut nv = String::from("0"); + for mut v in args.values_of("id").unwrap() { + if v.len() < 2 { + continue; + } + if &v[..2] == "0x" { + v = &v[2..]; + if v.len() % 2 > 0 { + nv.push_str(v); + v = nv.as_ref(); + } + debug!("hex input {:?}", &v); + let mut r = hex::decode(v).unwrap(); + d.append(&mut r); + } else { + d.append(&mut v.as_bytes().to_vec()); + } + } + + let mut auth: Option<AuthResult> = None; + + let url_src = args.value_of("URL").unwrap(); + let mut url = Url::parse(url_src).unwrap(); + + match args.value_of("key") { + Some(mut v) => { + debug!("have key {:?}", v); + if v.len() > 1 { + if &v[..2] == "0x" { + v = &v[2..]; + } + } + if v.len() % 2 > 0 { + nv.push_str(v); + v = nv.as_ref(); + } + debug!("hex key input {:?}", &v); + let auth_data = AuthResult { + identity: v.as_bytes().to_vec(), + error: false, + }; + + let rk = ResourceKey { + v: d.clone(), + }; + let url_postfix = rk.pointer_for(&auth_data); + //let url_postfix_str = String::from_utf8(url_postfix).unwrap(); + let url_postfix_hex = hex::encode(url_postfix); + url = url.join(&url_postfix_hex).unwrap(); + }, + None => {}, + } + + + + let ua = AgentBuilder::new().build(); + let r = ua.put(url.as_str()) + .send_bytes(&d); + + debug!("r {:?}", r.unwrap().into_string()); +} diff --git a/src/record.rs b/src/record.rs @@ -136,7 +136,7 @@ pub struct Record { /// Identifier part of the for mutable content reference. pub struct ResourceKey { - v: Vec<u8>, + pub v: Vec<u8>, } impl FromStr for ResourceKey {