pub struct PodPath { /* private fields */ }Expand description
A validated pod request path.
A PodPath is one of two shapes, and nothing else:
/pods/<pk>/<rest>: a resource or container inside the pod of<pk>.<rest>may be empty, which names the pod root/pods/<pk>/.- exactly
/pods/<pk>.acl: the pod’s root access-control resource, which the pod server keeps beside the pod rather than inside it.
Here <pk> is 64 lowercase hexadecimal digits naming a valid BIP-340
x-only key, available as owner. In addition, every
character of the whole path is one of A–Z a–z 0–9 - . _ ~ /; no segment
is . or ..; and no segment is empty, except that a single trailing /
is allowed and marks a container. There is no
percent-encoding: % is refused, so the path a caller sees is the path
the pod server acts on.
The text form is the path itself; Display,
FromStr and serde all use it, and deserialisation applies the same
checks as parse.
§Examples
use stratum_node_core::{DidNostr, PodPath};
let owner = DidNostr::from_hex("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798")?;
let root = PodPath::pod_root(&owner);
assert_eq!(root.as_str(), format!("/pods/{}/", owner.to_hex()));
let note = root.join("private/")?.join("x.txt")?;
assert_eq!(note.owner(), owner);
assert!(!note.is_container());
let acl = note.acl_path().ok_or("a resource has an acl")?;
assert_eq!(acl.as_str(), format!("/pods/{}/private/x.txt.acl", owner.to_hex()));
assert_eq!(
root.acl_path().ok_or("the pod root has an acl")?.as_str(),
format!("/pods/{}.acl", owner.to_hex()),
);
// 404 for anything outside the allow-list, 400 for a forbidden shape.
assert!(PodPath::parse("/.well-known/solid").unwrap_err().is_not_a_pod_path());
let dotted = format!("/pods/{}/a/../b", owner.to_hex());
assert!(!PodPath::parse(&dotted).unwrap_err().is_not_a_pod_path());Implementations§
Source§impl PodPath
impl PodPath
Sourcepub fn parse(path: &str) -> Result<Self, ParsePodPathError>
pub fn parse(path: &str) -> Result<Self, ParsePodPathError>
Parses and validates a request path.
path is the path part of the request target only, without the
query string or the ? that introduces it.
§Errors
Returns ParsePodPathError::NotAPodPath when the path is outside
the allow-list: it does not start with /pods/, the key is not 64
lowercase hex digits naming a valid key, or what follows the key is
neither / nor exactly .acl. Otherwise returns
ParsePodPathError::ForbiddenCharacter,
ParsePodPathError::DotSegment or
ParsePodPathError::EmptySegment for a pod path of a forbidden
shape, checked in that order.
ParsePodPathError::is_not_a_pod_path tells the two groups apart.
Sourcepub fn owner(&self) -> DidNostr
pub fn owner(&self) -> DidNostr
Returns the owner of the pod this path is in, from the key in the path.
Sourcepub fn is_root_acl(&self) -> bool
pub fn is_root_acl(&self) -> bool
Returns true for the root access-control resource /pods/<pk>.acl.
Sourcepub fn is_container(&self) -> bool
pub fn is_container(&self) -> bool
Returns true when the path ends in /, which names a container.
The pod root is a container; the root ACL is not.
Sourcepub fn join(&self, child: &str) -> Result<Self, ParsePodPathError>
pub fn join(&self, child: &str) -> Result<Self, ParsePodPathError>
Appends a relative child to this container.
child is one or more segments with no leading /, such as x.txt,
private/ or a/b.txt; a trailing / makes the result a container.
The result is validated as a whole by parse.
§Errors
Returns ParsePodPathError::NotAContainer when self is not a
container (including the root ACL), and otherwise the error
parse gives for the joined path: an empty child or
one starting with / is ParsePodPathError::EmptySegment.
Sourcepub fn is_acl(&self) -> bool
pub fn is_acl(&self) -> bool
Returns true when this path is an access-control resource: the root
ACL /pods/<pk>.acl or a non-container whose last segment ends in the
four bytes .acl, compared byte for byte and case-sensitively.
Uses is_acl_path, the one ACL predicate shared by the gate, signer,
proxy and manifest validation.
Sourcepub fn acl_path(&self) -> Option<Self>
pub fn acl_path(&self) -> Option<Self>
Returns the path of the access-control resource beside this one, or
None when this path is itself an access-control resource.
The pod server keeps an ACL as a sibling: the ACL of the pod root
/pods/<pk>/ is /pods/<pk>.acl, of a container /pods/<pk>/a/ is
/pods/<pk>/a.acl, and of a resource /pods/<pk>/a/x.txt is
/pods/<pk>/a/x.txt.acl. A resource (not a container) whose name ends
in .acl, and the root ACL, are access-control resources and have no
ACL of their own.