pub struct Capability(/* private fields */);Expand description
A validated capability identifier.
Capabilities are the atomic unit of authorization in Auths. They follow a namespace convention:
- Well-known capabilities:
sign_commit,sign_release,manage_members,rotate_keys - Custom capabilities: any valid string (alphanumeric +
:+-+_, max 64 chars)
The auths: prefix is reserved for future well-known capabilities and cannot be
used in custom capabilities created via parse().
§Examples
use auths_verifier::Capability;
// Well-known capabilities
let cap = Capability::sign_commit();
assert_eq!(cap.as_str(), "sign_commit");
// Custom capabilities
let custom = Capability::parse("acme:deploy").unwrap();
assert_eq!(custom.as_str(), "acme:deploy");
// Reserved namespace is rejected
assert!(Capability::parse("auths:custom").is_err());Implementations§
Source§impl Capability
impl Capability
Sourcepub fn sign_commit() -> Self
pub fn sign_commit() -> Self
Creates the sign_commit capability.
Grants permission to sign commits.
Sourcepub fn sign_release() -> Self
pub fn sign_release() -> Self
Creates the sign_release capability.
Grants permission to sign releases.
Sourcepub fn manage_members() -> Self
pub fn manage_members() -> Self
Creates the manage_members capability.
Grants permission to add/remove members in an organization.
Sourcepub fn rotate_keys() -> Self
pub fn rotate_keys() -> Self
Creates the rotate_keys capability.
Grants permission to rotate keys for an identity.
Sourcepub fn parse(raw: &str) -> Result<Self, CapabilityError>
pub fn parse(raw: &str) -> Result<Self, CapabilityError>
Parses and validates a capability string.
This is the primary way to create custom capabilities. The input is trimmed and lowercased to produce a canonical form.
§Validation Rules
- Non-empty
- Maximum 64 characters
- Only alphanumeric characters, colons (
:), hyphens (-), and underscores (_) - Cannot start with
auths:(reserved namespace)
§Examples
use auths_verifier::Capability;
// Valid custom capabilities
assert!(Capability::parse("deploy").is_ok());
assert!(Capability::parse("acme:deploy").is_ok());
assert!(Capability::parse("org:team:action").is_ok());
// Invalid capabilities
assert!(Capability::parse("").is_err()); // empty
assert!(Capability::parse("has space").is_err()); // invalid char
assert!(Capability::parse("auths:custom").is_err()); // reserved namespaceSourcepub fn custom(s: impl Into<String>) -> Option<Self>
👎Deprecated since 0.2.0: Use parse() for better error handling
pub fn custom(s: impl Into<String>) -> Option<Self>
Creates a custom capability after validation.
This is a convenience method that returns Option<Self> instead of Result.
§Deprecated
Prefer using parse() for better error handling.
Sourcepub fn validate_custom(s: &str) -> bool
👎Deprecated since 0.2.0: Use parse() for validation
pub fn validate_custom(s: &str) -> bool
Validates a custom capability string.
§Deprecated
This method is retained for backward compatibility. Use parse() instead.
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the canonical string representation of this capability.
This is the authoritative string form used for comparison, display, and serialization.
Sourcepub fn is_well_known(&self) -> bool
pub fn is_well_known(&self) -> bool
Returns true if this is a well-known Auths capability.
Trait Implementations§
Source§impl Clone for Capability
impl Clone for Capability
Source§fn clone(&self) -> Capability
fn clone(&self) -> Capability
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§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
Source§impl From<Capability> for String
impl From<Capability> for String
Source§fn from(cap: Capability) -> Self
fn from(cap: Capability) -> Self
Source§impl FromStr for Capability
impl FromStr for Capability
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parses a capability string with CLI-friendly alias resolution.
Normalizes the input (trim, lowercase, replace hyphens with underscores)
and matches well-known capabilities before falling through to
Capability::parse() for custom capability validation.
Unlike the deprecated parse_capability_cli, this returns an error
for unrecognized well-known names instead of silently defaulting.
Args:
s: The capability string (e.g., “sign_commit”, “Sign-Commit”).
Usage:
use auths_verifier::Capability;
let cap: Capability = "sign_commit".parse().unwrap();
assert_eq!(cap.as_str(), "sign_commit");