wala-rust

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

commit ebd92d0fb81a1d9778e76d55f0facd1a2756b951
parent 8597b4b6ed4b620136c81985b55e90ee30719665
Author: lash <dev@holbrook.no>
Date:   Sun, 17 Jul 2022 12:32:03 +0000

Specify rust version, skip doc tests

Diffstat:
MCargo.toml | 1+
Msrc/auth/mock.rs | 6+++---
Msrc/auth/mod.rs | 14+++++++-------
Msrc/auth/pgp.rs | 3+--
Msrc/main.rs | 1-
Msrc/record.rs | 24+++++++++++++++++++-----
Msrc/request.rs | 4++--
7 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -2,6 +2,7 @@ name = "wala" version = "0.1.0" edition = "2021" +rust-version = "1.60" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/auth/mock.rs b/src/auth/mock.rs @@ -44,7 +44,7 @@ mod tests { #[test] fn test_mock_auth_check() { - let mut auth_spec = AuthSpec::from_str("foo:bar:baz").unwrap(); + let mut auth_spec = AuthSpec::from_str("PUBSIG foo:bar:baz").unwrap(); match auth_check(&auth_spec, empty(), 0) { Ok(v) => { panic!("expected invalid auth"); @@ -53,7 +53,7 @@ mod tests { }, } - auth_spec = AuthSpec::from_str("mock:bar:baz").unwrap(); + auth_spec = AuthSpec::from_str("PUBSIG mock:bar:baz").unwrap(); match auth_check(&auth_spec, empty(), 0) { Ok(v) => { panic!("expected invalid auth"); @@ -62,7 +62,7 @@ mod tests { }, } - auth_spec = AuthSpec::from_str("mock:bar:bar").unwrap(); + auth_spec = AuthSpec::from_str("PUBSIG mock:bar:bar").unwrap(); match auth_check(&auth_spec, empty(), 0) { Ok(v) => { }, diff --git a/src/auth/mod.rs b/src/auth/mod.rs @@ -12,7 +12,7 @@ //! to determine the identity for which a client wishes to generate a mutable reference. The header //! uses the following format: //! -//! ``` +//! ``` ignore, //! Authorization: PUBSIG <scheme>:<identity>:<signature> //! ``` //! @@ -30,17 +30,17 @@ //! //! For example, given the request: //! -//! ``` +//! ``` ignore, //! PUT /xyzzy HTTP/1.1 //! Authorization: PUBSIG foo:123:456 //! Content-Length: 3 //! -//! bar +//! bar //! ``` //! //! If we pretend that `456` is a valid signature for the `123` under the fictional `foo` -//! authentication scheme, then the mutable reference generated will be `SHA256("xyzzy" | "123")` -//! which is `266e6c9060785c64b652cb5aea3a99f0ef019366372ced42ea9db25877288eed`. +//! authentication scheme, then the mutable reference generated will be `SHA256(SHA256("xyzzy") | "123")` +//! which is `925b268b49dbd2455742082134c72291b5afb2b332c8dcb6d60f06eb8e26b350` //! //! The immutable reference (generated from the content body "bar") will simultaneously be stored, //! under `SHA256("bar")`, which is `fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9`. @@ -48,8 +48,8 @@ //! Consequtively, for a `wala` server running on `localhost:8000`, the content can be retrieved using //! both of the following `URLs`: //! -//! ``` -//! http://localhost:8000/266e6c9060785c64b652cb5aea3a99f0ef019366372ced42ea9db25877288eed +//! ``` ignore, +//! http://localhost:8000/925b268b49dbd2455742082134c72291b5afb2b332c8dcb6d60f06eb8e26b350 //! http://localhost:8000/fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9 //! ``` //! diff --git a/src/auth/pgp.rs b/src/auth/pgp.rs @@ -5,10 +5,9 @@ //! //! If using bundle, the encoded data must be from the binary content, e.g. the output value of: //! -//! ``` +//! ``` ignore, //! gpg -b <file> //! ``` -//! use std::io::Read; use crate::auth::{ AuthSpec, diff --git a/src/main.rs b/src/main.rs @@ -1,6 +1,5 @@ #![crate_name = "wala"] - use tiny_http::{ Server, ServerConfig, diff --git a/src/record.rs b/src/record.rs @@ -207,11 +207,20 @@ pub fn put_immutable(path: &Path, mut f: impl Read, expected_size: usize) -> Res /// Store an immutable record on file with a mutable reference. /// +/// This method will fail if the provided [auth::AuthResult](crate::auth::AuthResult) is not a +/// successful authentcation. +/// /// # Arguments /// -/// TODO: use resourcekey instead of pointer here -pub fn put_mutable(pointer: Vec<u8>, path: &Path, mut f: impl Read, expected_size: usize) -> Result<Record, RequestResult> { +/// * `path` - Absolute path to storage directory. +/// * `f` - Reader providing the contents of the file. +/// * `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> { + let pointer = key.pointer_for(auth); let mutable_ref = hex::encode(&pointer); + debug!("generated mutable ref {}", &mutable_ref); let link_path_buf = path.join(&mutable_ref); let record = put_immutable(path, f, expected_size); @@ -266,6 +275,7 @@ mod tests { use std::fs::read; use tempfile::tempdir; use hex; + use std::str::FromStr; use env_logger; use log::{debug, info, error}; @@ -306,10 +316,14 @@ mod tests { let d = tempdir().unwrap(); let b = b"foo"; - let ptr = b"foobar"; - put_mutable(ptr.to_vec(), d.path().clone(), &b[..], 3); + let k = ResourceKey::from_str("baz").unwrap(); + let auth_result = AuthResult{ + identity: Vec::from("bar"), + error: false, + }; + put_mutable(d.path().clone(), &b[..], 3, &k, &auth_result); - let foobar_hex = hex::encode(ptr); + let foobar_hex = "561061c1c6b4fec065f5761e12f072b9591cf3ac55c70fe6fcbb39b0c16c6e20"; let mutable_path_buf = d.path().join(foobar_hex); let mutable_path = mutable_path_buf.as_path(); debug!(">>>>> checking mutable path {:?}", mutable_path); diff --git a/src/request.rs b/src/request.rs @@ -52,8 +52,8 @@ pub fn process_method(method: &Method, url: String, mut f: impl Read, expected_s let res: RequestResult; let rk = ResourceKey::from_str(url.as_str()).unwrap(); debug!("mutable put, authenticated as {:?} using mutable key {} -> {}", auth_result, &url, &rk); - let ptr = rk.pointer_for(&auth_result); - match put_mutable(ptr, path, f, expected_size) { + //let ptr = rk.pointer_for(&auth_result); + match put_mutable(path, f, expected_size, &rk, &auth_result) { Ok(v) => { let digest_hex = hex::encode(v.digest); res = RequestResult{