aboutsummaryrefslogtreecommitdiffstats
path: root/src/access
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-29 03:21:43 +0000
committertv <tv@krebsco.de>2026-11-29 03:21:43 +0000
commite63d30c2581033a85489b10c3f5b252fdbb5049e (patch)
tree5f4e6f65f1cecfb32f841e7ad7d9d106aeb69b20 /src/access
parent9188fa6e13ea7facfab5fb6f55bf26444ec2c01e (diff)
state: plain writes take a view to write, Automerge's are asked for as such
AppState::mutate_doc, mutate_doc_registering and mutate_doc_by hand what they are given a document::view::Write: the member registry, the users, sessions, forgetting and bootstrap write through them, and take whatever kind of document gives it. AppState::mutate_doc_for is for what asks more of an Automerge document than values at paths (the store's API, a remake's host, a store's events), and gives the heads after the write. What reads a view takes one of any size (dyn Write among them).
Diffstat (limited to 'src/access')
-rw-r--r--src/access/bans.rs2
-rw-r--r--src/access/challenge.rs2
-rw-r--r--src/access/envelope.rs8
-rw-r--r--src/access/policy.rs4
-rw-r--r--src/access/registry.rs12
-rw-r--r--src/access/rules.rs17
-rw-r--r--src/access/sealed.rs12
-rw-r--r--src/access/strict.rs6
-rw-r--r--src/access/token.rs16
9 files changed, 46 insertions, 33 deletions
diff --git a/src/access/bans.rs b/src/access/bans.rs
index 999f610..1cb1452 100644
--- a/src/access/bans.rs
+++ b/src/access/bans.rs
@@ -14,6 +14,6 @@ pub(crate) fn path(node: &str) -> Vec<String> {
}
/// Whether `doc` bans `node`.
-pub(crate) fn banned(doc: &impl Read, node: &str) -> bool {
+pub(crate) fn banned(doc: &(impl Read + ?Sized), node: &str) -> bool {
view::read_plain(doc, &path(node)).ok().flatten().is_some()
}
diff --git a/src/access/challenge.rs b/src/access/challenge.rs
index 4dd8dfb..670574c 100644
--- a/src/access/challenge.rs
+++ b/src/access/challenge.rs
@@ -70,7 +70,7 @@ pub(crate) struct Used(HashMap<String, (u64, String)>);
/// `per_user` of its own still remembered. Why not, if not.
#[allow(clippy::too_many_arguments)]
pub(crate) fn take(
- doc: &impl Read,
+ doc: &(impl Read + ?Sized),
key: &NodeKey,
challenge: &str,
signature: &str,
diff --git a/src/access/envelope.rs b/src/access/envelope.rs
index d592bff..95371d3 100644
--- a/src/access/envelope.rs
+++ b/src/access/envelope.rs
@@ -39,7 +39,7 @@ 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 Read) -> Vec<Vec<String>> {
+pub(crate) fn listed(doc: &(impl Read + ?Sized)) -> Vec<Vec<String>> {
let Ok(Some(JsonValue::Array(entries))) = view::read_plain(doc, &listed_at()) else {
return Vec::new();
};
@@ -67,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 Read) -> Vec<Vec<String>> {
+pub(crate) fn signed_paths(doc: &(impl Read + ?Sized)) -> Vec<Vec<String>> {
let mut paths = deciding();
paths.extend(listed(doc));
paths
@@ -151,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 Read,
+ doc: &(impl Read + ?Sized),
envelope: &str,
path: &[String],
previous: Option<&str>,
@@ -207,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 Read,
+ doc: &(impl Read + ?Sized),
payload: &Payload,
user: &registry::User,
path: &[String],
diff --git a/src/access/policy.rs b/src/access/policy.rs
index e4027b8..e596175 100644
--- a/src/access/policy.rs
+++ b/src/access/policy.rs
@@ -119,7 +119,7 @@ pub(crate) fn as_written(value: &JsonValue) -> Result<Policy, String> {
/// where its `store` is, as continuum writes them: an Automerge text there, or one holding
/// the policy, reads as a string in plain JSON, so a policy that would read so only
/// through a text is one nobody knows, never what its characters spell.
-pub(crate) fn of(doc: &impl Read) -> Policy {
+pub(crate) fn of(doc: &(impl Read + ?Sized)) -> Policy {
match view::read_plain(doc, &path()) {
Ok(Some(value)) => match read(&value) {
policy if policy.strict() && !a_string(doc, "values") => {
@@ -138,7 +138,7 @@ pub(crate) fn of(doc: &impl Read) -> Policy {
/// Whether the policy `doc` holds, read in typed JSON (where a text is tagged, and an
/// envelope reads as its payload), has a string for its `key`.
-fn a_string(doc: &impl Read, key: &str) -> bool {
+fn a_string(doc: &(impl Read + ?Sized), key: &str) -> bool {
matches!(
doc.read_typed(&path()),
Ok(Some(value)) if value.get(key).is_some_and(JsonValue::is_string)
diff --git a/src/access/registry.rs b/src/access/registry.rs
index 5a58e1f..f0034ba 100644
--- a/src/access/registry.rs
+++ b/src/access/registry.rs
@@ -35,12 +35,12 @@ pub(crate) fn user_path(name: &str) -> Vec<String> {
/// Whether the swarm has a registry: until it has, every user a node lets in may do
/// everything but write protocol data (`docs/access.md`, A swarm without a registry).
-pub(crate) fn exists(doc: &impl Read) -> bool {
+pub(crate) fn exists(doc: &(impl Read + ?Sized)) -> bool {
matches!(view::keys_at(doc, &users_dir()), Ok(Some(_)))
}
/// The registered users' names, sorted.
-pub(crate) fn names(doc: &impl Read) -> Vec<String> {
+pub(crate) fn names(doc: &(impl Read + ?Sized)) -> Vec<String> {
let mut names = view::keys_at(doc, &users_dir())
.ok()
.flatten()
@@ -128,7 +128,7 @@ impl User {
}
/// The entry of user `name`, if it has one.
-pub(crate) fn user(doc: &impl Read, name: &str) -> Option<User> {
+pub(crate) fn user(doc: &(impl Read + ?Sized), name: &str) -> Option<User> {
let value = view::read_plain(doc, &user_path(name)).ok()??;
let mut user = value.is_object().then(|| User::from_json(&value))?;
// A damaged one revokes every token.
@@ -156,7 +156,7 @@ pub(crate) fn session_path(name: &str, session: &str) -> Vec<String> {
}
/// Whether user `name`'s session `session` was ended (`session_path`).
-pub(crate) fn session_ended(doc: &impl Read, name: &str, session: &str) -> bool {
+pub(crate) fn session_ended(doc: &(impl Read + ?Sized), name: &str, session: &str) -> bool {
view::read_path(doc, &session_path(name, session))
.ok()
.flatten()
@@ -164,7 +164,7 @@ pub(crate) fn session_ended(doc: &impl Read, name: &str, session: &str) -> bool
}
/// The users who may manage users: enabled, with `write` on `_continuum/users`.
-pub(crate) fn managers(doc: &impl Read) -> Vec<String> {
+pub(crate) fn managers(doc: &(impl Read + ?Sized)) -> Vec<String> {
names(doc)
.into_iter()
.filter(|name| caps_of(doc, name).allows(Right::Write, &users_dir()))
@@ -172,7 +172,7 @@ pub(crate) fn managers(doc: &impl Read) -> Vec<String> {
}
/// What user `name` may do: none if it isn't registered (or is disabled).
-pub(crate) fn caps_of(doc: &impl Read, name: &str) -> Caps {
+pub(crate) fn caps_of(doc: &(impl Read + ?Sized), name: &str) -> Caps {
user(doc, name).map(|user| user.caps()).unwrap_or_default()
}
diff --git a/src/access/rules.rs b/src/access/rules.rs
index 93cef63..d8831ce 100644
--- a/src/access/rules.rs
+++ b/src/access/rules.rs
@@ -219,7 +219,7 @@ pub(crate) fn judge_reading(
/// In a swarm holding a store of some fold, as `holding` judges it there, which is its
/// kind of document's to say.
pub(crate) fn judge_seen(
- at: &impl Read,
+ at: &(impl Read + ?Sized),
epoch: Epoch,
unit: &Unit<'_>,
read: &mut Seen,
@@ -502,7 +502,7 @@ pub(crate) fn judge_held(
/// string put there that is one (or deleting what is there); nothing within one; nothing
/// in an object nowhere to be found, which might be one.
fn sealed_values(
- at: &impl Read,
+ at: &(impl Read + ?Sized),
declared: &[super::sealed::Declared],
ops: &[Op],
) -> Result<(), String> {
@@ -534,7 +534,7 @@ fn sealed_values(
/// as a write replacing it does); nothing within one; above one,
/// nothing replacing or deleting what holds one (a map made where there is none yet,
/// what is inside a list or text, which holds none).
-fn signed_values(at: &impl Read, ops: &[Op]) -> Result<(), String> {
+fn signed_values(at: &(impl Read + ?Sized), ops: &[Op]) -> Result<(), String> {
let signed = super::envelope::signed_paths(at);
for op in ops {
let path = &op.path;
@@ -589,7 +589,7 @@ fn signed_values(at: &impl Read, ops: &[Op]) -> Result<(), String> {
/// Whether what is at `path` in `at` holds a value at a place for one its user signs,
/// of `signed` (`envelope::signed_paths`), signed or from before the policy; one that
/// doesn't read, as if it did.
-fn holds_signed(at: &impl Read, path: &[String], signed: &[Vec<String>]) -> bool {
+fn holds_signed(at: &(impl Read + ?Sized), path: &[String], signed: &[Vec<String>]) -> bool {
fn within(value: &serde_json::Value, place: &mut Vec<String>, signed: &[Vec<String>]) -> bool {
if super::envelope::is_signed(signed, place) {
return true;
@@ -628,7 +628,12 @@ fn shown(path: &Path) -> String {
/// Whether remake `id`, coordinated by `node`, made `epoch`: as its snapshot's metadata
/// says (`remake::snapshot`), at `at`. Never genesis.
-pub(super) fn made_the_epoch(at: &impl Read, epoch: Epoch, id: &str, node: &str) -> bool {
+pub(super) fn made_the_epoch(
+ at: &(impl Read + ?Sized),
+ epoch: Epoch,
+ id: &str,
+ node: &str,
+) -> bool {
if epoch.generation == 0 {
return false;
}
@@ -647,7 +652,7 @@ pub(super) fn made_the_epoch(at: &impl Read, epoch: Epoch, id: &str, node: &str)
}
/// The coordinator remake `id`'s proposal names, at `at`.
-pub(super) fn coordinator(at: &impl Read, id: &str) -> Option<String> {
+pub(super) fn coordinator(at: &(impl Read + ?Sized), id: &str) -> Option<String> {
let proposal = view::read_path(at, &meta::path(&[meta::REMAKES, id, "proposal"]))
.ok()
.flatten()?;
diff --git a/src/access/sealed.rs b/src/access/sealed.rs
index c30bea7..b39a465 100644
--- a/src/access/sealed.rs
+++ b/src/access/sealed.rs
@@ -48,7 +48,7 @@ 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 Read) -> Vec<Declared> {
+pub(crate) fn declared(doc: &(impl Read + ?Sized)) -> Vec<Declared> {
let Ok(Some(JsonValue::Array(entries))) = view::read_plain(doc, &declared_at()) else {
return Vec::new();
};
@@ -141,7 +141,11 @@ 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 Read, declared: &Declared, value: &JsonValue) -> Result<(), String> {
+pub(crate) fn check(
+ doc: &(impl Read + ?Sized),
+ 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());
};
@@ -184,7 +188,7 @@ pub(crate) fn check(doc: &impl Read, declared: &Declared, value: &JsonValue) ->
/// 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 Read, path: &[String]) -> Result<(), String> {
+pub(crate) fn kept(doc: &(impl Read + ?Sized), path: &[String]) -> Result<(), String> {
let declared = declared(doc);
if declared.is_empty() || !reaches(&declared, path) {
return Ok(());
@@ -193,7 +197,7 @@ pub(crate) fn kept(doc: &impl Read, path: &[String]) -> Result<(), String> {
return Err(format!("/{} is within a sealed value", path.join("/")));
}
fn walk(
- doc: &impl Read,
+ doc: &(impl Read + ?Sized),
declared: &[Declared],
value: &JsonValue,
at: &mut Vec<String>,
diff --git a/src/access/strict.rs b/src/access/strict.rs
index 9857bed..0aac192 100644
--- a/src/access/strict.rs
+++ b/src/access/strict.rs
@@ -95,9 +95,9 @@ pub(crate) fn digest(value: &JsonValue) -> String {
/// The places values are signed in `doc` (`envelope::signed_paths`, `*` as `doc` has
/// them) that hold one, with it, as the store reads it.
-pub(crate) fn held(doc: &impl Read) -> Vec<(Vec<String>, JsonValue)> {
+pub(crate) fn held(doc: &(impl Read + ?Sized)) -> Vec<(Vec<String>, JsonValue)> {
fn expand(
- doc: &impl Read,
+ doc: &(impl Read + ?Sized),
pattern: &[String],
at: Vec<String>,
out: &mut Vec<(Vec<String>, JsonValue)>,
@@ -135,7 +135,7 @@ pub(crate) fn held(doc: &impl Read) -> Vec<(Vec<String>, JsonValue)> {
/// held at a signed place now, the policy `policy`, for `user` to look over and sign at
/// `at`. Its exact line.
pub(crate) fn manifest_of(
- doc: &impl Read,
+ doc: &(impl Read + ?Sized),
swarm: &str,
epoch: crate::document::replica::EpochRecord,
base: &[crate::document::ChangeHash],
diff --git a/src/access/token.rs b/src/access/token.rs
index 073d1e4..7c7b0ed 100644
--- a/src/access/token.rs
+++ b/src/access/token.rs
@@ -118,7 +118,7 @@ pub(crate) enum Refused {
/// (`registry::User::tokens_not_before`), of a session not ended
/// (`registry::session_ended`).
pub(crate) fn verify(
- doc: &impl Read,
+ doc: &(impl Read + ?Sized),
token: &str,
swarm: &str,
now: u64,
@@ -162,7 +162,11 @@ pub(crate) fn verify(
/// store, only one it issued itself (`docs/store.md`, Members), as a node there is
/// whoever its operator lets in, and lets in nobody's but its own.
#[cfg(feature = "federation")]
-pub(crate) fn issued_here(doc: &impl Read, local: &str, claims: Claims) -> Result<Claims, Refused> {
+pub(crate) fn issued_here(
+ doc: &(impl Read + ?Sized),
+ local: &str,
+ claims: Claims,
+) -> Result<Claims, Refused> {
match super::policy::of(doc) {
super::policy::Policy::Store(_) if claims.issuer != local => Err(Refused::ElsewhereIssued),
_ => Ok(claims),
@@ -173,13 +177,13 @@ pub(crate) fn issued_here(doc: &impl Read, local: &str, claims: Claims) -> Resul
/// its issuer a member and not banned, its user registered, enabled, its tokens not
/// revoked since and its session not ended. What a stream opened with it is judged by
/// as the document changes (`api::login::streams_end`).
-pub(crate) fn still_taken(doc: &impl Read, claims: &Claims) -> Result<(), Refused> {
+pub(crate) fn still_taken(doc: &(impl Read + ?Sized), claims: &Claims) -> Result<(), Refused> {
issuer_counts(doc, claims)?;
user_counts(doc, claims)
}
/// Its issuer a member of the swarm, not banned.
-fn issuer_counts(doc: &impl Read, claims: &Claims) -> Result<(), Refused> {
+fn issuer_counts(doc: &(impl Read + ?Sized), claims: &Claims) -> Result<(), Refused> {
let member = view::read_path(doc, &meta::path(&[meta::MEMBERS, &claims.issuer]))
.ok()
.flatten()
@@ -195,7 +199,7 @@ fn issuer_counts(doc: &impl Read, claims: &Claims) -> Result<(), Refused> {
/// In a swarm with a registry: its user registered, enabled, its tokens not revoked
/// since it was issued, its session not ended.
-fn user_counts(doc: &impl Read, claims: &Claims) -> Result<(), Refused> {
+fn user_counts(doc: &(impl Read + ?Sized), claims: &Claims) -> Result<(), Refused> {
user_taken(doc, &claims.user)?;
if let Some(user) = registry::user(doc, &claims.user) {
if claims.iat < user.tokens_not_before {
@@ -211,7 +215,7 @@ fn user_counts(doc: &impl Read, claims: &Claims) -> Result<(), Refused> {
/// In a swarm with a registry: user `name` registered and enabled. What a stream opened
/// by password or a proxy's header is judged by as the document changes
/// (`api::login::streams_end`), as one opened with a token is by `still_taken`.
-pub(crate) fn user_taken(doc: &impl Read, name: &str) -> Result<(), Refused> {
+pub(crate) fn user_taken(doc: &(impl Read + ?Sized), name: &str) -> Result<(), Refused> {
if registry::exists(doc) {
let user = registry::user(doc, name).ok_or(Refused::UnknownUser)?;
if user.disabled {