commit c4b45a5ee21fdc32c44b7c141ddd8e070c45002c
parent 92ec0de9984771ab187c4470808607b6af260c4e
Author: lash <dev@holbrook.no>
Date: Fri, 2 May 2025 13:21:13 +0100
Remove warnings
Diffstat:
13 files changed, 229 insertions(+), 121 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -224,7 +224,7 @@ dependencies = [
"js-sys",
"num-traits",
"wasm-bindgen",
- "windows-targets 0.52.3",
+ "windows-targets 0.52.6",
]
[[package]]
@@ -1472,6 +1472,7 @@ dependencies = [
"tree_magic",
"ureq",
"url",
+ "xdg-home",
]
[[package]]
@@ -1590,7 +1591,7 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
dependencies = [
- "windows-targets 0.52.3",
+ "windows-targets 0.52.6",
]
[[package]]
@@ -1608,7 +1609,16 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
- "windows-targets 0.52.3",
+ "windows-targets 0.52.6",
+]
+
+[[package]]
+name = "windows-sys"
+version = "0.59.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
+dependencies = [
+ "windows-targets 0.52.6",
]
[[package]]
@@ -1628,17 +1638,18 @@ dependencies = [
[[package]]
name = "windows-targets"
-version = "0.52.3"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d380ba1dc7187569a8a9e91ed34b8ccfc33123bbacb8c0aed2d1ad7f3ef2dc5f"
+checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
- "windows_aarch64_gnullvm 0.52.3",
- "windows_aarch64_msvc 0.52.3",
- "windows_i686_gnu 0.52.3",
- "windows_i686_msvc 0.52.3",
- "windows_x86_64_gnu 0.52.3",
- "windows_x86_64_gnullvm 0.52.3",
- "windows_x86_64_msvc 0.52.3",
+ "windows_aarch64_gnullvm 0.52.6",
+ "windows_aarch64_msvc 0.52.6",
+ "windows_i686_gnu 0.52.6",
+ "windows_i686_gnullvm",
+ "windows_i686_msvc 0.52.6",
+ "windows_x86_64_gnu 0.52.6",
+ "windows_x86_64_gnullvm 0.52.6",
+ "windows_x86_64_msvc 0.52.6",
]
[[package]]
@@ -1649,9 +1660,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_gnullvm"
-version = "0.52.3"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "68e5dcfb9413f53afd9c8f86e56a7b4d86d9a2fa26090ea2dc9e40fba56c6ec6"
+checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
@@ -1661,9 +1672,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_aarch64_msvc"
-version = "0.52.3"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8dab469ebbc45798319e69eebf92308e541ce46760b49b18c6b3fe5e8965b30f"
+checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
@@ -1673,9 +1684,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_gnu"
-version = "0.52.3"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
+
+[[package]]
+name = "windows_i686_gnullvm"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2a4e9b6a7cac734a8b4138a4e1044eac3404d8326b6c0f939276560687a033fb"
+checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
@@ -1685,9 +1702,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_i686_msvc"
-version = "0.52.3"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "28b0ec9c422ca95ff34a78755cfa6ad4a51371da2a5ace67500cf7ca5f232c58"
+checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
@@ -1697,9 +1714,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnu"
-version = "0.52.3"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "704131571ba93e89d7cd43482277d6632589b18ecf4468f591fbae0a8b101614"
+checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
@@ -1709,9 +1726,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_gnullvm"
-version = "0.52.3"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "42079295511643151e98d61c38c0acc444e52dd42ab456f7ccfd5152e8ecf21c"
+checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
@@ -1721,9 +1738,19 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "windows_x86_64_msvc"
-version = "0.52.3"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
+
+[[package]]
+name = "xdg-home"
+version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0770833d60a970638e989b3fa9fd2bb1aaadcf88963d1659fd7d9990196ed2d6"
+checksum = "ec1cdab258fb55c0da61328dc52c8764709b249011b2cad0454c72f0bf10a1f6"
+dependencies = [
+ "libc",
+ "windows-sys 0.59.0",
+]
[[package]]
name = "xxhash-rust"
diff --git a/Cargo.toml b/Cargo.toml
@@ -69,10 +69,14 @@ optional = true
version = "^0.3.15"
optional = true
+[dependencies.xdg-home]
+version = "^1.3.0"
+optional = true
+
[features]
pgpauth = ["sequoia-openpgp", "base64", "nettle"]
dev = []
magic = ["tree_magic"]
meta = []
trace = []
-client = ["ureq", "sequoia-openpgp", "rpassword", "base64"]
+client = ["ureq", "sequoia-openpgp", "rpassword", "base64", "xdg-home"]
diff --git a/src/arg.rs b/src/arg.rs
@@ -3,7 +3,7 @@ use clap::{
App,
Arg,
ArgMatches,
- SubCommand,
+// SubCommand,
};
pub struct Settings {
diff --git a/src/auth/mock.rs b/src/auth/mock.rs
@@ -20,7 +20,7 @@ use crate::auth::{
/// * `auth` - Authentication data submitted by client.
/// * `data` - Content body submitted by client, to match signature against.
/// * `data_length` - Length of content body
-pub fn auth_check(auth: &AuthSpec, data: impl Read, data_length: usize) -> Result<AuthResult, AuthError> {
+pub fn auth_check(auth: &AuthSpec, _data: impl Read, _data_length: usize) -> Result<AuthResult, AuthError> {
if auth.method != "mock" {
return Err(AuthError{});
}
diff --git a/src/auth/mod.rs b/src/auth/mod.rs
@@ -133,7 +133,7 @@ impl Error for AuthSpecError {
impl fmt::Display for AuthSpecError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
- fmt.write_str(self.description())
+ fmt.write_str(&self.to_string())
}
}
@@ -196,7 +196,7 @@ pub struct AuthError;
impl fmt::Display for AuthError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
- fmt.write_str(self.description())
+ fmt.write_str(&self.to_string())
}
}
diff --git a/src/auth/pgp_sequoia.rs b/src/auth/pgp_sequoia.rs
@@ -19,7 +19,7 @@ use crate::auth::{
use sequoia_openpgp::Cert;
use sequoia_openpgp::KeyHandle;
use sequoia_openpgp::Result as PGPResult;
-use sequoia_openpgp::cert::prelude::*;
+//use sequoia_openpgp::cert::prelude::*;
use sequoia_openpgp::packet::key::PrimaryRole;
use sequoia_openpgp::packet::key::PublicParts;
use sequoia_openpgp::packet::prelude::*;
@@ -34,7 +34,8 @@ use nettle::hash::Sha256;
use base64;
-use log::{debug, info, error};
+use log::debug;
+use log::error;
fn check_key_single(data: &Vec<u8>) -> Option<Key<PublicParts, PrimaryRole>> {
@@ -43,7 +44,7 @@ fn check_key_single(data: &Vec<u8>) -> Option<Key<PublicParts, PrimaryRole>> {
let pubkey: Key<PublicParts, PrimaryRole> = v.into();
return Some(pubkey);
},
- Err(e) => {
+ Err(_) => {
},
};
None
@@ -56,7 +57,7 @@ fn check_key_bundle(data: &Vec<u8>) -> Option<Cert> {
//return Some(pubkey.clone());
return Some(v);
},
- Err(e) => {
+ Err(_) => {
},
};
None
@@ -65,21 +66,23 @@ fn check_key_bundle(data: &Vec<u8>) -> Option<Cert> {
fn check_sig_single(public_key: &Key<PublicParts, PrimaryRole>, signature_data: Vec<u8>, mut message: impl Read, message_length: usize) -> bool {
match Signature::from_bytes(&signature_data) {
Ok(mut v) => {
+ //let mut hasher = Sha256::default();
let mut hasher = Sha256::default();
let mut message_data: Vec<u8> = vec!();
- message.read_to_end(&mut message_data);
- debug!("checking mesage {:?}", &message_data);
+ _ = message.read_to_end(&mut message_data);
hasher.update(&message_data);
match v.verify_hash(&public_key, Box::new(hasher)) {
- Ok(v) => {
+ Ok(_) => {
return true;
},
- Err(e) => {
+ Err(_) => {
},
}
},
- Err(e) => {
-
+ Err(_) => {
+ _ = public_key;
+ _ = message;
+ _ = message_length;
},
}
false
@@ -90,14 +93,14 @@ struct Helper {
}
impl VerificationHelper for Helper {
- fn get_certs(&mut self, ids: &[KeyHandle]) -> PGPResult<Vec<Cert>> {
+ fn get_certs(&mut self, _ids: &[KeyHandle]) -> PGPResult<Vec<Cert>> {
let mut certs = Vec::new();
certs.push(self.cert.clone());
return Ok(certs);
}
fn check(&mut self, structure: MessageStructure) -> PGPResult<()> {
- let mut good = false;
+ //let good = false;
for (i, layer) in structure.into_iter().enumerate() {
match (i, layer) {
@@ -109,7 +112,7 @@ impl VerificationHelper for Helper {
panic!("none");
},
Some(Err(e)) => {
- panic!("err");
+ panic!("err {}", e);
},
};
},
@@ -122,12 +125,16 @@ impl VerificationHelper for Helper {
}
}
+// TODO handle unreadable message
fn check_sig_bundle(public_key: &Cert, signature_data: Vec<u8>, mut message: impl Read, message_length: usize) -> bool {
+ _ = message_length;
let p = StandardPolicy::new();
let mut sig_bundle_packets = PacketParser::from_bytes(&signature_data).unwrap();
- while let PacketParserResult::Some(mut pp) = sig_bundle_packets {
+ //while let PacketParserResult::Some(mut pp) = sig_bundle_packets {
+ while let PacketParserResult::Some(pp) = sig_bundle_packets {
let mut pk = pp.packet.clone();
if let Packet::Signature(ref mut sig) = pk {
+ _ = sig;
let pbytes = pk.to_vec().unwrap();
let helper = Helper{
cert: public_key.clone(),
@@ -135,12 +142,12 @@ fn check_sig_bundle(public_key: &Cert, signature_data: Vec<u8>, mut message: imp
let mut verifier = DetachedVerifierBuilder::from_bytes(&pbytes).unwrap().with_policy(&p, None, helper).unwrap();
let mut message_all: Vec<u8> = vec!();
- message.read_to_end(&mut message_all);
+ _ = message.read_to_end(&mut message_all);
match verifier.verify_bytes(&message_all) {
- Ok(v) => {
+ Ok(_) => {
return true;
},
- Err(e) => {
+ Err(_) => {
},
};
}
@@ -185,7 +192,7 @@ pub fn auth_check(auth: &AuthSpec, data: impl Read, data_length: usize) -> Resul
Ok(v) => {
v
},
- Err(e) => {
+ Err(_) => {
return Err(AuthError{});
}
};
@@ -195,7 +202,7 @@ pub fn auth_check(auth: &AuthSpec, data: impl Read, data_length: usize) -> Resul
Ok(v) => {
v
},
- Err(e) => {
+ Err(_) => {
return Err(AuthError{});
}
};
diff --git a/src/main.rs b/src/main.rs
@@ -10,7 +10,8 @@ use tiny_http::{
use mime::Mime;
use std::net::{Ipv4Addr, SocketAddrV4};
use std::str::FromStr;
-use std::path::{PathBuf, Path};
+//use std::path::{PathBuf, Path};
+use std::path::Path;
use std::fs::{
File,
create_dir_all,
@@ -19,7 +20,7 @@ use std::error::Error;
use std::fmt;
use std::io::{
copy as io_copy,
- Read,
+// Read,
Seek,
empty,
};
@@ -30,8 +31,8 @@ use std::sync::atomic::{AtomicBool, Ordering};
use env_logger;
use ascii::AsciiStr;
-use signal_hook::flag;
-use signal_hook::consts;
+//use signal_hook::flag;
+//use signal_hook::consts;
use wala::auth::{
AuthSpec,
@@ -78,7 +79,7 @@ impl Error for NoAuthError {
impl fmt::Display for NoAuthError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
- fmt.write_str(self.description())
+ fmt.write_str(&self.to_string())
}
}
@@ -89,6 +90,7 @@ fn exec_auth(auth_spec: AuthSpec, data: &File, data_length: usize) -> Option<Aut
return Some(v);
},
Err(e) => {
+ error!("mock auth check error ({})", e)
},
}
@@ -98,6 +100,7 @@ fn exec_auth(auth_spec: AuthSpec, data: &File, data_length: usize) -> Option<Aut
return Some(v);
},
Err(e) => {
+ error!("pgp auth check error ({})", e)
},
}
@@ -128,7 +131,7 @@ fn auth_from_headers(headers: &[Header], method: &Method) -> Option<AuthSpec> {
return Some(v);
},
Err(e) => {
- error!("malformed auth string: {}", &h.value);
+ error!("malformed auth string: {} ({})", &h.value, e);
let r = AuthSpec{
method: String::from(method.as_str()),
key: String::new(),
@@ -183,7 +186,7 @@ fn process_meta(req: &Request, path: &Path, digest: Vec<u8>) -> Option<Mime> {
let v = &h.value;
m = match Mime::from_str(v.as_str()) {
Err(e) => {
- error!("invalid mime type");
+ error!("invalid mime type ({})", e);
return None;
},
Ok(v) => {
@@ -235,13 +238,14 @@ fn main() {
let base_path = settings.dir.as_path();
let spool_path = base_path.join("spool");
- let mut spool_ok = false;
+ //let mut spool_ok = false;
+ //
#[cfg(feature = "trace")]
{
match create_dir_all(&spool_path) {
- Ok(v) => {
- spool_ok = true;
+ Ok(_) => {
+ // spool_ok = true;
},
Err(e) => {
warn!("spool directory could not be created: {:?}", e);
@@ -266,12 +270,13 @@ fn main() {
#[cfg(feature = "docker")]
signal_hook::flag::register(signal_hook::consts::SIGTERM, Arc::clone(&term)).unwrap();
- const loop_timeout: Duration = Duration::new(1, 0);
+ const LOOP_TIMEOUT: Duration = Duration::new(1, 0);
while !term.load(Ordering::Relaxed) {
- let b = srv.recv_timeout(loop_timeout);
- let mut hasreq: Option<Request>;
+ let b = srv.recv_timeout(LOOP_TIMEOUT);
+ //let mut hasreq: Option<Request>;
+ let hasreq: Option<Request>;
match b {
Ok(v) => hasreq = v,
Err(e) => {
@@ -308,25 +313,49 @@ fn main() {
},
};
let f = req.as_reader();
- let mut path = base_path.clone();
+ //let mut path = base_path.clone();
+ let path = base_path.clone();
let mut res: AuthResult = AuthResult{
identity: vec!(),
error: false,
};
let rw: Option<File> = match tempfile() {
Ok(mut v) => {
- io_copy(f, &mut v);
- v.rewind();
+ match io_copy(f, &mut v) {
+ Ok(_) => {
+ },
+ Err(e) => {
+ error!("could not copy file: {:?} ({})", path, e);
+ continue;
+ },
+ };
+ match v.rewind() {
+ Ok(_) => {
+ },
+ Err(e) => {
+ error!("could not rewind file for request: {:?} ({})", path, e);
+ continue;
+ },
+ };
res = process_request(&mut req, &mut v);
- v.rewind();
+ match v.rewind() {
+ Ok(_) => {
+ },
+ Err(e) => {
+ error!("could not rewind file for return: {:?} ({})", path, e);
+ continue;
+ },
+ };
Some(v)
},
Err(e) => {
- None
+ error!("tempfile error: {:?} ({})", path, e);
+ None
},
};
- let mut result: RequestResult;
+ //let mut result: RequestResult;
+ let result: RequestResult;
match rw {
Some(v) => {
result = process_method(&method, url, v, expected_size, &path, res);
diff --git a/src/meta.rs b/src/meta.rs
@@ -79,12 +79,20 @@ fn filename_path(path: &Path, digest: &Vec<u8>) -> Result<PathBuf, std::io::Erro
/// * `path` - Absolute path to storage diectory.
/// * `digest` - Immutable reference to content.
/// * `typ` - MIME type to store for the content.
+/// TODO: return none on write meta error
pub fn register_type(path: &Path, digest: &Vec<u8>, typ: Mime) -> Result<(), std::io::Error> {
match meta_path(path, digest) {
Ok(v) => {
match File::create(v) {
Ok(mut f) => {
- f.write(typ.as_ref().as_bytes());
+ match f.write(typ.as_ref().as_bytes()) {
+ Ok(_) => {
+ debug!("wrote meta to {:?}", f);
+ },
+ Err(e) => {
+ error!("could not write meta to {:?} ({})", f, e);
+ },
+ };
}
Err(e) => {
return Err(e);
@@ -104,13 +112,20 @@ pub fn register_type(path: &Path, digest: &Vec<u8>, typ: Mime) -> Result<(), std
/// * `path` - Absolute path to storage diectory.
/// * `digest` - Immutable reference to content.
/// * `typ` - MIME type to store for the content.
+/// TODO: return none on write error
pub fn register_filename(path: &Path, digest: &Vec<u8>, name: String) -> Result<(), std::io::Error> {
match filename_path(path, digest) {
Ok(v) => {
match File::create(v) {
Ok(mut f) => {
- f.write(name.as_str().as_bytes());
- debug!("wrote to {:?}", f);
+ match f.write(name.as_str().as_bytes()) {
+ Ok(_) => {
+ debug!("wrote to {:?}", f);
+ },
+ Err(e) => {
+ error!("could not write to {:?} ({})", f, e);
+ },
+ };
}
Err(e) => {
return Err(e);
diff --git a/src/record.rs b/src/record.rs
@@ -1,5 +1,5 @@
use std::str::FromStr;
-use std::io;
+//use std::io;
use std::convert::Infallible;
use std::fs::{
File,
@@ -20,7 +20,7 @@ use sha2::{Sha256, Digest};
use std::fmt;
use crate::auth::AuthResult;
-use tiny_http::Request;
+//use tiny_http::Request;
use tempfile::NamedTempFile;
use mime::Mime;
@@ -108,7 +108,7 @@ impl RequestResult {
impl fmt::Display for RequestResult {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
- fmt.write_str(self.description())
+ fmt.write_str(&self.to_string())
}
}
@@ -186,12 +186,13 @@ impl ResourceKey {
/// * `path` - Absolute path to storage directory.
/// * `f` - Reader providing the contents of the file.
/// * `expected_size` - Size hint of content.
+/// TODO: handle write fail
pub fn put_immutable(path: &Path, mut f: impl Read, expected_size: usize) -> Result<Record, RequestResult> {
let z: Vec<u8>;
let hash: String;
- let mut total_size: usize = 0;
let tempfile = match NamedTempFile::new() {
Ok(of) => {
+ let mut total_size: usize = 0;
debug!("writing to tempfile {:?} expected size {}", of.path(), expected_size);
let mut buf: [u8; 65535] = [0; 65535];
let mut h = Sha256::new();
@@ -204,7 +205,7 @@ pub fn put_immutable(path: &Path, mut f: impl Read, expected_size: usize) -> Res
total_size += v;
let data = &buf[..v];
h.update(data);
- of.as_file().write(data);
+ _ = of.as_file().write(data);
},
Err(e) => {
error!("cannot read from request body: {}", e);
@@ -223,10 +224,10 @@ pub fn put_immutable(path: &Path, mut f: impl Read, expected_size: usize) -> Res
z = h.finalize().to_vec();
hash = hex::encode(&z);
- info!("have hash {} for content", hash);
+ info!("have hash {} for content, length {}", hash, total_size);
of
},
- Err(e) => {
+ Err(_) => {
let err = RequestResult::new(RequestResultType::WriteError);
return Err(err);
}
@@ -234,14 +235,20 @@ pub fn put_immutable(path: &Path, mut f: impl Read, expected_size: usize) -> Res
let final_path_buf = path.join(&hash);
let final_path = final_path_buf.as_path();
- fs_copy(tempfile.path(), final_path);
+ match fs_copy(tempfile.path(), &final_path) {
+ Ok(_) => {
+ },
+ Err(e) => {
+ error!("could not store immutable: {:?} ({})", final_path, e);
+ },
+ }
- let r = Record{
+ let rec = Record{
digest: z,
path: final_path_buf,
alias: None,
};
- Ok(r)
+ Ok(rec)
}
/// Store an immutable record on file with a mutable reference.
@@ -256,7 +263,8 @@ pub fn put_immutable(path: &Path, mut f: impl Read, expected_size: usize) -> Res
/// * `expected_size` - Size hint of content.
/// * `key` - Mutable reference generator.
/// * `auth` - Authentication result containing the client identity.
-pub fn put_mutable(path: &Path, mut f: impl Read, expected_size: usize, key: &ResourceKey, auth: &AuthResult) -> Result<Record, RequestResult> {
+//pub fn put_mutable(path: &Path, mut f: impl Read, expected_size: usize, key: &ResourceKey, auth: &AuthResult) -> Result<Record, RequestResult> {
+pub fn put_mutable(path: &Path, f: impl Read, expected_size: usize, key: &ResourceKey, auth: &AuthResult) -> Result<Record, RequestResult> {
let pointer = key.pointer_for(auth);
let mutable_ref = hex::encode(&pointer);
debug!("generated mutable ref {}", &mutable_ref);
@@ -266,15 +274,22 @@ pub fn put_mutable(path: &Path, mut f: impl Read, expected_size: usize, key: &Re
match record {
Ok(v) => {
match remove_file(&link_path_buf) {
- Ok(r) => {
+ Ok(_) => {
debug!("unlinked mutable ref on {:?}", &link_path_buf);
},
Err(e) => {
- debug!("clear symlink failed {:?}", &e);
+ debug!("clear symlink failed {:?}", e);
}
};
- symlink(&v.path, &link_path_buf);
- info!("linked mutable ref {:?} -> {:?}", &link_path_buf, &v.path);
+ match symlink(&v.path, &link_path_buf) {
+ Ok(_) => {
+ info!("linked mutable ref {:?} -> {:?}", &link_path_buf, &v.path);
+ },
+ Err(e) => {
+ error!("could not link mutable ref {:?} -> {:?} ({})", &link_path_buf, &v.path, e);
+ },
+
+ };
let r = Record{
digest: pointer,
path: link_path_buf.clone(),
@@ -296,11 +311,12 @@ pub fn put_mutable(path: &Path, mut f: impl Read, expected_size: usize, key: &Re
/// * `pointer` - A reference to the pointer.
/// * `path` - Absolute path to storage directory.
pub fn get(pointer: Vec<u8>, path: &Path) -> Option<File> {
+ _ = pointer;
let path_canon = match path.canonicalize() {
Ok(v) => {
v
},
- Err(e) => {
+ Err(_) => {
return None;
},
};
diff --git a/src/request.rs b/src/request.rs
@@ -2,9 +2,9 @@ use std::path::Path;
use std::str::FromStr;
use tiny_http::{
Method,
- Response,
- Request,
- StatusCode,
+// Response,
+// Request,
+// StatusCode,
};
use crate::record::{
put_immutable,
@@ -40,7 +40,8 @@ use log::{
/// * `expected_size` - Size hint for content body.
/// * `path` - Absolute path to storage directory.
/// * `auth_result` - Result of authentication (if any) the client has provided with the request.
-pub fn process_method(method: &Method, url: String, mut f: impl Read, expected_size: usize, path: &Path, auth_result: AuthResult) -> RequestResult {
+//pub fn process_method(method: &Method, url: String, mut f: impl Read, expected_size: usize, path: &Path, auth_result: AuthResult) -> RequestResult {
+pub fn process_method(method: &Method, url: String, f: impl Read, expected_size: usize, path: &Path, auth_result: AuthResult) -> RequestResult {
match method {
Method::Put => {
if !auth_result.valid() {
@@ -154,7 +155,7 @@ pub fn process_method(method: &Method, url: String, mut f: impl Read, expected_s
res.n = get_meta_filename(path, &digest);
}
},
- Err(e) => {
+ Err(_) => {
res = RequestResult::new(RequestResultType::ReadError);
},
}
diff --git a/src/response.rs b/src/response.rs
@@ -11,8 +11,8 @@ use tiny_http::{
};
use ascii::AsciiString;
-use mime::Mime;
-use mime::TEXT;
+//use mime::Mime;
+//use mime::TEXT;
use crate::record::{
RequestResult,
@@ -79,11 +79,13 @@ pub fn preflight_response(req: Request) {
for v in auth_origin_headers.iter() {
res.add_header(v.clone());
}
- req.respond(res);
+ _ = req.respond(res);
debug!("served options request");
return;
}
+// req marked as unused but seems used in all branches
+// TODO: return something reasonable in all cases e.g. the respond return value
pub fn exec_response(req: Request, r: RequestResult) {
let res_status: StatusCode;
match r.typ {
@@ -110,10 +112,11 @@ pub fn exec_response(req: Request, r: RequestResult) {
},
}
- let auth_origin_headers = origin_headers();
+ debug!("have status, {:?}", &res_status);
match r.v {
Some(v) => {
+ let auth_origin_headers = origin_headers();
let mut res = Response::from_string(v);
res = res.with_status_code(res_status);
for v in auth_origin_headers.iter() {
@@ -131,10 +134,11 @@ pub fn exec_response(req: Request, r: RequestResult) {
},
};
- req.respond(res);
+ _ = req.respond(res);
return;
},
None => {
+ let auth_origin_headers = origin_headers();
match r.f {
Some(v) => {
let mut content_type = String::new();
@@ -198,13 +202,13 @@ pub fn exec_response(req: Request, r: RequestResult) {
for v in auth_origin_headers.iter() {
res.add_header(v.clone());
}
- req.respond(res);
+ _ = req.respond(res);
return;
},
None => {
let mut res = Response::empty(res_status);
for v in auth_origin_headers.iter() {
- res.add_header(v.clone());
+ _ = res.add_header(v.clone());
}
match r.l {
@@ -219,7 +223,7 @@ pub fn exec_response(req: Request, r: RequestResult) {
},
};
- req.respond(res);
+ _ = req.respond(res);
return;
},
}
diff --git a/src/trace.rs b/src/trace.rs
@@ -1,7 +1,7 @@
use std::path::Path;
use std::fs::{
File,
- OpenOptions,
+// OpenOptions,
};
use std::io::Write;
@@ -43,9 +43,10 @@ pub fn trace_request(p: &Path, res: &RequestResult, store_identity: bool) {
None => {
},
}
+ debug!("have identity: {}", identity);
let fp = p.join(&rf);
let mut f = File::create(fp).unwrap();
- f.write(content.as_ref());
+ _ = f.write(content.as_ref());
// useless update because we can always resolve mutable to immutable from data dir
// if content.len() != 0 {
diff --git a/src/wala_send/main.rs b/src/wala_send/main.rs
@@ -26,24 +26,28 @@
//! For more details on what funcionality [wala](wala) provides, please consult the
//! [library crate documentation](wala).
-use std::env::home_dir;
-use std::io::stdout;
-use std::io::copy;
+//use std::env::home_dir;
+//use std::io::stdout;
+//use std::io::copy;
use std::io::Write;
use env_logger;
use url::Url;
-use log::{info, debug};
+//use log::{info, debug};
+use log::{debug};
-use ureq::{Agent, AgentBuilder};
+//use ureq::{Agent, AgentBuilder};
+use ureq::AgentBuilder;
use clap::{
App,
Arg,
};
+use xdg_home::home_dir;
+
use sequoia_openpgp::packet::prelude::*;
use sequoia_openpgp::cert::prelude::CertParser;
use sequoia_openpgp::serialize::Serialize;
@@ -53,13 +57,13 @@ use sequoia_openpgp::policy::StandardPolicy;
use sequoia_openpgp::packet::Key;
use sequoia_openpgp::packet::key::SecretParts;
use sequoia_openpgp::packet::key::PublicParts;
-use sequoia_openpgp::packet::key::UnspecifiedRole;
+//use sequoia_openpgp::packet::key::UnspecifiedRole;
use sequoia_openpgp::packet::key::PrimaryRole;
use sequoia_openpgp::serialize::stream::Message;
use sequoia_openpgp::serialize::stream::Signer;
-use sequoia_openpgp::serialize::stream::LiteralWriter;
+//use sequoia_openpgp::serialize::stream::LiteralWriter;
-use base64::encode;
+//use base64::encode;
use wala::record::{ResourceKey};
use wala::auth::{AuthResult};
@@ -129,12 +133,13 @@ fn main() {
let data = args.value_of("DATA").unwrap();
- let mut auth: Option<AuthResult> = None;
+ //let mut auth: Option<AuthResult> = None;
+ //let auth: Option<AuthResult> = None;
let url_src = args.value_of("url").unwrap();
let mut url = Url::parse(url_src).unwrap();
- let mut have_auth = false;
+ //let have_auth = false;
let mut rk = ResourceKey {
v: Vec::new(),
};
@@ -202,16 +207,15 @@ fn main() {
let mut sig_sink = vec!();
let mut pubkey_sink = vec!();
- let mut pwd = String::new();
if k.secret().is_encrypted() {
- pwd = rpassword::prompt_password("Key passphrase: ").unwrap();
+ let pwd = rpassword::prompt_password("Key passphrase: ").unwrap();
let algo = k.pk_algo();
- k.secret_mut()
+ _ = k.secret_mut()
.decrypt_in_place(algo, &pwd.into());
-
}
- let mut sig_msg = Message::new(&mut sig_sink);
+ //let mut sig_msg = Message::new(&mut sig_sink);
+ let sig_msg = Message::new(&mut sig_sink);
let kp = k.clone().into_keypair().unwrap();
let pk: Key<PublicParts, PrimaryRole> = kp.public().clone().role_into_primary();
@@ -219,10 +223,10 @@ fn main() {
.detached()
.build()
.unwrap();
- signer.write_all(&data.as_bytes());
- signer.finalize();
+ _ = signer.write_all(&data.as_bytes());
+ _ = signer.finalize();
- Packet::from(pk).serialize(&mut pubkey_sink);
+ _ = Packet::from(pk).serialize(&mut pubkey_sink);
sig_bsf = base64::encode(sig_sink);
pubkey_bsf = base64::encode(pubkey_sink);