aboutsummaryrefslogtreecommitdiffstats
path: root/src/access/token.rs
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/token.rs
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/token.rs')
-rw-r--r--src/access/token.rs16
1 files changed, 10 insertions, 6 deletions
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 {