AifEncodedScope

Struct AifEncodedScope 

Source
pub struct AifEncodedScope(/* private fields */);
Expand description

A scope encoded using the Authorization Information Format (AIF) for ACE.

More specifically, this uses the specific instantiation of AIF intended for REST resources which are identified by URI paths, as described in RFC 9237, section 2.1. An AIF-encoded scope consists of AifEncodedScopeElements, each describing a URI path (the object of the scope) and a set of REST methods (the permissions of the scope).

Note that the libdcaf implementation uses a format in which only a single AifEncodedScopeElement is used in the scope. To use this format, please use the LibdcafEncodedScope instead.

§Example

For example, say you want to create a scope consisting of two elements:

  • A scope for the local path /restricted, consisting only of “read-only” methods GET and FETCH.
  • A scope for the local path /unrestricted, allowing every method.

This would look like the following:

let restricted = AifEncodedScopeElement::new("restricted", AifRestMethod::Get | AifRestMethod::Fetch);
let unrestricted = AifEncodedScopeElement::new("unrestricted", AifRestMethodSet::all());
let scope = AifEncodedScope::new(vec![restricted, unrestricted]);
assert_eq!(scope.elements(), &vec![restricted, unrestricted])

§Encoding

The scope from the example above would be encoded like this (given in JSON):

[["restricted", 17], ["unrestricted", 545460846719]]

As specified in RFC 9237, section 3, GET to iPATCH are encoded from 20 to 26, while the dynamic variants go from 232 to 238. This is why in restricted, the number equals 17 (20 + 24), and in unrestricted equals the sum of all these numbers. AifRestMethod does the work on this (including encoding and decoding bitmasks given as numbers), clients do not need to handle this themselves and can simply use its methods together with the methods provided by AifRestMethodSet.

Implementations§

Source§

impl AifEncodedScope

Source

pub fn new(elements: Vec<AifEncodedScopeElement>) -> AifEncodedScope

Creates a new AifEncodedScope consisting of the given elements.

Source

pub fn elements(&self) -> &Vec<AifEncodedScopeElement>

Returns a reference to the AifEncodedScopeElements of this scope.

§Example
let first = AifEncodedScopeElement::new("first", AifRestMethodSet::empty());
let second = AifEncodedScopeElement::new("second", AifRestMethod::Patch);
// We only clone here for the assert call below. This is usually not required.
let scope = AifEncodedScope::new(vec![first.clone(), second.clone()]);
assert_eq!(scope.elements(), &vec![first, second]);
Source

pub fn to_elements(self) -> Vec<AifEncodedScopeElement>

Returns the AifEncodedScopeElements of this scope.

§Example
let first = AifEncodedScopeElement::new("first", AifRestMethodSet::empty());
let second = AifEncodedScopeElement::new("second", AifRestMethod::Patch);
// We only clone here for the assert call below. This is usually not required.
let scope = AifEncodedScope::new(vec![first.clone(), second.clone()]);
assert_eq!(scope.to_elements(), vec![first, second]);

Trait Implementations§

Source§

impl Clone for AifEncodedScope

Source§

fn clone(&self) -> AifEncodedScope

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 AifEncodedScope

Source§

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

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

impl From<AifEncodedScope> for Scope

Source§

fn from(value: AifEncodedScope) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<(T, BitFlags<AifRestMethod>)>> for AifEncodedScope
where T: Into<String>,

Source§

fn from(value: Vec<(T, BitFlags<AifRestMethod>)>) -> Self

Converts to this type from the input type.
Source§

impl Hash for AifEncodedScope

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 AifEncodedScope

Source§

fn eq(&self, other: &AifEncodedScope) -> 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 AifEncodedScope

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<Scope> for AifEncodedScope

Source§

type Error = WrongSourceTypeError<Scope>

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

fn try_from(value: Scope) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Vec<(String, u64)>> for AifEncodedScope

Source§

type Error = InvalidAifEncodedScopeError

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

fn try_from(value: Vec<(String, u64)>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for AifEncodedScope

Source§

impl StructuralPartialEq for AifEncodedScope

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> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>

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, 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.