diff options
Diffstat (limited to 'src/access/envelope.rs')
| -rw-r--r-- | src/access/envelope.rs | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/access/envelope.rs b/src/access/envelope.rs index f697809..d592bff 100644 --- a/src/access/envelope.rs +++ b/src/access/envelope.rs @@ -25,7 +25,8 @@ use sha2::{Digest, Sha256}; use super::{Right, agree, registry, sshsig}; pub(crate) use crate::document::signed::Payload; -use crate::document::{ReadDoc, meta, signed, store}; +use crate::document::view::{self, Read}; +use crate::document::{meta, signed}; /// What a signature over a payload is for (`sshsig`). pub(crate) const NAMESPACE: &str = "continuum-value"; @@ -38,8 +39,8 @@ pub(crate) fn listed_at() -> Vec<String> { /// The paths `doc` lists as user-signed; an entry that isn't a list of strings is left /// out. -pub(crate) fn listed(doc: &impl ReadDoc) -> Vec<Vec<String>> { - let Ok(Some(JsonValue::Array(entries))) = store::read_plain(doc, &listed_at()) else { +pub(crate) fn listed(doc: &impl Read) -> Vec<Vec<String>> { + let Ok(Some(JsonValue::Array(entries))) = view::read_plain(doc, &listed_at()) else { return Vec::new(); }; entries @@ -66,7 +67,7 @@ fn deciding() -> Vec<Vec<String>> { /// The paths whose values their users sign under a strict policy: what decides who may /// do what (`deciding`), and those `doc` lists (`listed`). -pub(crate) fn signed_paths(doc: &impl ReadDoc) -> Vec<Vec<String>> { +pub(crate) fn signed_paths(doc: &impl Read) -> Vec<Vec<String>> { let mut paths = deciding(); paths.extend(listed(doc)); paths @@ -150,7 +151,7 @@ pub(crate) fn read(envelope: &str) -> Result<Payload, String> { /// its swarm, that path, naming what it replaces and numbered after it, signed by one of /// its user's keys, a user who may write there. pub(crate) fn check( - doc: &impl ReadDoc, + doc: &impl Read, envelope: &str, path: &[String], previous: Option<&str>, @@ -160,7 +161,7 @@ pub(crate) fn check( payload, signature, } = signed::open(envelope)?; - let swarm = store::read_path( + let swarm = view::read_path( doc, &crate::document::meta::path(&[crate::document::meta::SWARM]), ) @@ -206,7 +207,7 @@ pub(crate) fn check( /// with only its keys changed from the one at `path` in `doc`, one left at least: a user /// manages its own keys, whatever else it may do. fn own_keys_only( - doc: &impl ReadDoc, + doc: &impl Read, payload: &Payload, user: ®istry::User, path: &[String], @@ -214,7 +215,7 @@ fn own_keys_only( if user.disabled || path != registry::user_path(&payload.user) { return false; } - let Ok(Some(mut before)) = store::read_plain(doc, path) else { + let Ok(Some(mut before)) = view::read_plain(doc, path) else { return false; }; // One key left at least: a user can't sign, nor log in by key, without one. @@ -256,13 +257,13 @@ mod tests { let line = sshsig::PublicKey(key.verifying_key().to_bytes()).line(); let mut doc = Document::new(); change(&mut doc, |doc| { - store::write_path(doc, &path("_continuum/swarm"), &json!("s")).unwrap(); + view::write_path(doc, &path("_continuum/swarm"), &json!("s")).unwrap(); let mut alice = registry::entry("root", 1, &[(path("config"), &[Right::Write][..])]); alice["keys"] = json!({ "laptop": line }); - store::write_path(doc, ®istry::user_path("alice"), &alice).unwrap(); + view::write_path(doc, ®istry::user_path("alice"), &alice).unwrap(); let mut bob = registry::entry("root", 1, &[]); bob["keys"] = json!({ "laptop": line }); - store::write_path(doc, ®istry::user_path("bob"), &bob).unwrap(); + view::write_path(doc, ®istry::user_path("bob"), &bob).unwrap(); }); doc } @@ -363,7 +364,7 @@ mod tests { fn users_sign_their_own_keys() { let key = SigningKey::from_bytes(&[5; 32]); let doc = registry_with(&key); - let entry = store::read_plain(&doc, ®istry::user_path("alice")) + let entry = view::read_plain(&doc, ®istry::user_path("alice")) .unwrap() .unwrap(); let line = @@ -388,7 +389,7 @@ mod tests { fn listed_paths() { let mut doc = Document::new(); change(&mut doc, |doc| { - store::write_path(doc, &listed_at(), &json!([["config"], ["a", "b"], "junk"])).unwrap(); + view::write_path(doc, &listed_at(), &json!([["config"], ["a", "b"], "junk"])).unwrap(); }); assert_eq!(listed(&doc), vec![path("config"), path("a/b")]); let signed = signed_paths(&doc); |
