From e63d30c2581033a85489b10c3f5b252fdbb5049e Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 Nov 2026 03:21:43 +0000 Subject: 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). --- src/access/token.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/access/token.rs') 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 { +pub(crate) fn issued_here( + doc: &(impl Read + ?Sized), + local: &str, + claims: Claims, +) -> Result { 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 { -- cgit v1.3.1