Skip to main content

Capability

Struct Capability 

Source
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

Source

pub const MAX_LEN: usize = 64

Maximum length for capability strings.

Source

pub fn sign_commit() -> Self

Creates the sign_commit capability.

Grants permission to sign commits.

Source

pub fn sign_release() -> Self

Creates the sign_release capability.

Grants permission to sign releases.

Source

pub fn manage_members() -> Self

Creates the manage_members capability.

Grants permission to add/remove members in an organization.

Source

pub fn rotate_keys() -> Self

Creates the rotate_keys capability.

Grants permission to rotate keys for an identity.

Source

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 namespace
Source

pub fn custom(s: impl Into<String>) -> Option<Self>

👎Deprecated since 0.2.0: Use parse() for better error handling

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.

Source

pub fn validate_custom(s: &str) -> bool

👎Deprecated since 0.2.0: Use parse() for validation

Validates a custom capability string.

§Deprecated

This method is retained for backward compatibility. Use parse() instead.

Source

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.

Source

pub fn is_well_known(&self) -> bool

Returns true if this is a well-known Auths capability.

Source

pub fn namespace(&self) -> Option<&str>

Returns the namespace portion of the capability (before first colon), if any.

Trait Implementations§

Source§

impl Clone for Capability

Source§

fn clone(&self) -> Capability

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Capability

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Capability

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Capability

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Capability> for String

Source§

fn from(cap: Capability) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Capability

Source§

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");
Source§

type Err = CapabilityError

The associated error which can be returned from parsing.
Source§

impl Hash for Capability

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Capability

Source§

fn eq(&self, other: &Capability) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Capability

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<String> for Capability

Source§

type Error = CapabilityError

The type returned in the event of a conversion error.
Source§

fn try_from(s: String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Capability

Source§

impl StructuralPartialEq for Capability

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,