pub struct Capability { /* private fields */ }Expand description
A single capability: a scope and the allowed actions within it.
The wire/string representation is "<scope>:<actions>", see module docs.
Implementations§
Source§impl Capability
impl Capability
Sourcepub fn root() -> Self
pub fn root() -> Self
Shorthand for a root capability at / with read+write.
Equivalent to a capability with scope / and both read and write actions.
use pubky_common::capabilities::Capability;
assert_eq!(Capability::root().to_string(), "/:rw");Sourcepub fn read(scope: impl AsRef<str>) -> Result<Self, CapabilityParseError>
pub fn read(scope: impl AsRef<str>) -> Result<Self, CapabilityParseError>
Construct a read-only capability for scope.
use pubky_common::capabilities::Capability;
assert_eq!(Capability::read("/pub/my.app").unwrap().to_string(), "/pub/my.app:r");Sourcepub fn write(scope: impl AsRef<str>) -> Result<Self, CapabilityParseError>
pub fn write(scope: impl AsRef<str>) -> Result<Self, CapabilityParseError>
Construct a write-only capability for scope.
use pubky_common::capabilities::Capability;
assert_eq!(Capability::write("/pub/tmp").unwrap().to_string(), "/pub/tmp:w");Sourcepub fn read_write(scope: impl AsRef<str>) -> Result<Self, CapabilityParseError>
pub fn read_write(scope: impl AsRef<str>) -> Result<Self, CapabilityParseError>
Construct a read+write capability for scope.
use pubky_common::capabilities::Capability;
assert_eq!(Capability::read_write("/").unwrap().to_string(), "/:rw");Sourcepub fn encryption_keys(
scope: impl AsRef<str>,
) -> Result<Self, CapabilityParseError>
pub fn encryption_keys( scope: impl AsRef<str>, ) -> Result<Self, CapabilityParseError>
Request scoped content keys without granting storage read or write access. Symmetric keys permit both encryption and decryption. Requires approval V1.
Sourcepub fn scope(&self) -> &StoragePath
pub fn scope(&self) -> &StoragePath
Return the resource scope covered by this capability.
Sourcepub fn grants_encryption_keys(&self) -> bool
pub fn grants_encryption_keys(&self) -> bool
Whether this capability grants scoped encryption and decryption keys. Read and write permissions alone do not grant keys.
Sourcepub fn is_root(&self) -> bool
pub fn is_root(&self) -> bool
Whether this grants root storage read/write access (/:rw or /:rwe).
Sourcepub fn scope_covers_path(&self, path: &StoragePath) -> bool
pub fn scope_covers_path(&self, path: &StoragePath) -> bool
Whether this capability’s scope covers the given path.
The trailing / on a scope is significant — it distinguishes a
directory scope from a file scope:
- Directory scope (ends in
/): covers the directory itself and any path inside it./pub/app/covers/pub/app/,/pub/app/foo, and/pub/app/sub/bar, but NOT/pub/appor/pub/app-evil/foo. - File scope (no trailing
/): covers only the exact path./pub/appcovers/pub/appand nothing else — not/pub/app/foo(that’s inside the directory/pub/app/, a different resource) and not/pub/app-evil(no prefix-as-string matching).
Trait Implementations§
Source§impl Clone for Capability
impl Clone for Capability
Source§impl Debug for Capability
impl Debug for Capability
Source§impl<'de> Deserialize<'de> for Capability
impl<'de> Deserialize<'de> for Capability
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for Capability
impl Display for Capability
impl Eq for Capability
Source§impl FromStr for Capability
impl FromStr for Capability
Source§fn from_str(value: &str) -> Result<Self, Self::Err>
fn from_str(value: &str) -> Result<Self, Self::Err>
Parse "<scope>:<actions>".
use pubky_common::capabilities::Capability;
let capability: Capability = "/pub/my-cool-app/:rw".parse().unwrap();
assert_eq!(capability.to_string(), "/pub/my-cool-app/:rw");