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
impl AifEncodedScope
Sourcepub fn new(elements: Vec<AifEncodedScopeElement>) -> AifEncodedScope
pub fn new(elements: Vec<AifEncodedScopeElement>) -> AifEncodedScope
Creates a new AifEncodedScope consisting of the given elements.
Sourcepub fn elements(&self) -> &Vec<AifEncodedScopeElement>
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]);Sourcepub fn to_elements(self) -> Vec<AifEncodedScopeElement>
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
impl Clone for AifEncodedScope
Source§fn clone(&self) -> AifEncodedScope
fn clone(&self) -> AifEncodedScope
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more