diff options
Diffstat (limited to 'src/access/sealed.rs')
| -rw-r--r-- | src/access/sealed.rs | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/access/sealed.rs b/src/access/sealed.rs index 2b8085a..c30bea7 100644 --- a/src/access/sealed.rs +++ b/src/access/sealed.rs @@ -25,7 +25,8 @@ use serde_json::Value as JsonValue; use sha2::{Digest, Sha256}; use super::{agree, envelope, registry, sshsig}; -use crate::document::{ReadDoc, meta, store}; +use crate::document::meta; +use crate::document::view::{self, Read}; /// What every sealed value starts with. const PREFIX: &str = "cs1."; @@ -47,8 +48,8 @@ pub(crate) struct Declared { } /// What `doc` declares sealed; an entry that doesn't read as one is left out. -pub(crate) fn declared(doc: &impl ReadDoc) -> Vec<Declared> { - let Ok(Some(JsonValue::Array(entries))) = store::read_plain(doc, &declared_at()) else { +pub(crate) fn declared(doc: &impl Read) -> Vec<Declared> { + let Ok(Some(JsonValue::Array(entries))) = view::read_plain(doc, &declared_at()) else { return Vec::new(); }; entries @@ -140,11 +141,7 @@ pub(crate) fn recipients(sealed: &str) -> Result<BTreeSet<String>, String> { /// (as its writer saw it): a sealed value, or, signed by its user (`access::envelope`), /// one holding a sealed value or `null` (deleted); with readers declared, sealed for /// exactly their keys. -pub(crate) fn check( - doc: &impl ReadDoc, - declared: &Declared, - value: &JsonValue, -) -> Result<(), String> { +pub(crate) fn check(doc: &impl Read, declared: &Declared, value: &JsonValue) -> Result<(), String> { let JsonValue::String(text) = value else { return Err("a sealed value is a string (cs1.<age file>)".to_owned()); }; @@ -187,7 +184,7 @@ pub(crate) fn check( /// Checks what is at `path` in `doc` after a write there: nothing within a declared /// place but its value, and every value at one (at `path` or below it) as `check` says. /// Why not, if not. -pub(crate) fn kept(doc: &impl ReadDoc, path: &[String]) -> Result<(), String> { +pub(crate) fn kept(doc: &impl Read, path: &[String]) -> Result<(), String> { let declared = declared(doc); if declared.is_empty() || !reaches(&declared, path) { return Ok(()); @@ -196,7 +193,7 @@ pub(crate) fn kept(doc: &impl ReadDoc, path: &[String]) -> Result<(), String> { return Err(format!("/{} is within a sealed value", path.join("/"))); } fn walk( - doc: &impl ReadDoc, + doc: &impl Read, declared: &[Declared], value: &JsonValue, at: &mut Vec<String>, @@ -215,7 +212,7 @@ pub(crate) fn kept(doc: &impl ReadDoc, path: &[String]) -> Result<(), String> { } Ok(()) } - match store::read_path(doc, path) { + match view::read_path(doc, path) { Ok(Some(value)) => walk(doc, &declared, &value, &mut path.to_vec()), Ok(None) => Ok(()), Err(error) => Err(error.to_string()), @@ -270,11 +267,11 @@ mod tests { change(&mut doc, |doc| { let mut alice = registry::entry("root", 1, &[]); alice["keys"] = json!({ "laptop": key(1).line(), "phone": key(2).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": key(3).line() }); - store::write_path(doc, ®istry::user_path("bob"), &bob).unwrap(); - store::write_path( + view::write_path(doc, ®istry::user_path("bob"), &bob).unwrap(); + view::write_path( doc, &declared_at(), &json!([ @@ -360,13 +357,13 @@ mod tests { let mut doc = swarm(); let all = sealed_for(&[key(1), key(2), key(3)]); change(&mut doc, |doc| { - store::write_path(doc, &path("secrets"), &json!({"db": all, "other": all})).unwrap(); - store::write_path(doc, &path("elsewhere"), &json!("plain")).unwrap(); + view::write_path(doc, &path("secrets"), &json!({"db": all, "other": all})).unwrap(); + view::write_path(doc, &path("elsewhere"), &json!("plain")).unwrap(); }); assert!(kept(&doc, &path("secrets")).is_ok()); assert!(kept(&doc, &path("elsewhere")).is_ok()); change(&mut doc, |doc| { - store::write_path(doc, &path("secrets/web"), &json!("plain")).unwrap(); + view::write_path(doc, &path("secrets/web"), &json!("plain")).unwrap(); }); assert!(kept(&doc, &path("secrets")).is_err()); assert!(kept(&doc, &path("secrets/web")).is_err()); |
