Enum dcaf::common::scope::Scope

source ·
pub enum Scope {
    TextEncoded(TextEncodedScope),
    BinaryEncoded(BinaryEncodedScope),
    AifEncoded(AifEncodedScope),
    LibdcafEncoded(LibdcafEncodedScope),
}
Expand description

Scope of an access token as specified in RFC 9200, section 5.8.1.

May be used both for AccessTokenRequests and AccessTokenResponses. Note that you rarely need to create instances of this type for that purpose, instead you can just pass in the concrete types (e.g. TextEncodedScope, BinaryEncodedScope) directly into the builder.

Example

You can create binary, AIF-, or text-encoded scopes:

let text_scope = Scope::from(TextEncodedScope::try_from("dcaf rs")?);
let binary_scope = Scope::from(BinaryEncodedScope::try_from(vec![0xDC, 0xAF].as_slice())?);
let aif_scope = Scope::from(AifEncodedScope::from(vec![("/tmp", AifRestMethod::Get.into())]));

For information on how to initialize a specific scope type or retrieve the individual elements inside them, see their respective documentation pages.

Variants§

§

TextEncoded(TextEncodedScope)

Scope encoded using Text, as specified in RFC 6749, section 1.3.

For details, see the documentation of TextEncodedScope.

Example

Creating a scope containing “device_alpha” and “device_beta” (note that spaces in their name wouldn’t work):

let scope = TextEncodedScope::try_from(vec!["device_alpha", "device_beta"])?;
assert_eq!(scope, TextEncodedScope::try_from("device_alpha device_beta")?);
assert!(scope.elements().eq(vec!["device_alpha", "device_beta"]));
assert!(TextEncodedScope::try_from(vec!["device alpha", "device beta"]).is_err());
§

BinaryEncoded(BinaryEncodedScope)

Scope encoded using custom binary encoding.

For details, see the documentation of BinaryEncodedScope.

Example

Creating a scope containing 0xDCAF and 0xAFDC with a separator of 0x00:

let scope = BinaryEncodedScope::try_from(vec![0xDC, 0xAF, 0x00, 0xAF, 0xDC].as_slice())?;
assert!(scope.elements(Some(0x00))?.eq(&vec![vec![0xDC, 0xAF], vec![0xAF, 0xDC]]));
assert!(scope.elements(None)?.eq(&vec![vec![0xDC, 0xAF, 0x00, 0xAF, 0xDC]]));
assert!(scope.elements(Some(0xDC)).is_err());  // no separators at the beginning or end
§

AifEncoded(AifEncodedScope)

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

For details, see the documentation of AifEncodedScope.

Example

Creating a scope containing ["/s/temp", 1] (1 representing GET) and ["/a/led", 5] (5 representing GET and FETCH):

let scope = AifEncodedScope::from(vec![
   ("/s/temp", AifRestMethod::Get.into()),
   ("/a/led", AifRestMethod::Get | AifRestMethod::Fetch)
]);
§

LibdcafEncoded(LibdcafEncodedScope)

libdcaf-specific variant of AifEncoded which consists of only a single AifEncodedScopeElement.

Use only if trying to maintain compatibility to libdcaf.

For details, see the documentation of LibdcafEncodedScope.

Example

Creating a scope containing ["/s/temp", 1] (1 representing GET):

let scope = LibdcafEncodedScope::new("/s/temp", AifRestMethod::Get.into());

Trait Implementations§

source§

impl Clone for Scope

source§

fn clone(&self) -> Scope

Returns a copy 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 Scope

source§

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

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

impl<'de> Deserialize<'de> for Scope

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<'_derivative_strum> From<&'_derivative_strum Scope> for &'static str

source§

fn from(x: &'_derivative_strum Scope) -> &'static str

Converts to this type from the input type.
source§

impl From<AifEncodedScope> for Scope

source§

fn from(value: AifEncodedScope) -> Self

Converts to this type from the input type.
source§

impl From<BinaryEncodedScope> for Scope

source§

fn from(value: BinaryEncodedScope) -> Self

Converts to this type from the input type.
source§

impl From<LibdcafEncodedScope> for Scope

source§

fn from(value: LibdcafEncodedScope) -> Self

Converts to this type from the input type.
source§

impl From<Scope> for &'static str

source§

fn from(x: Scope) -> &'static str

Converts to this type from the input type.
source§

impl From<Scope> for Value

source§

fn from(scope: Scope) -> Self

Converts to this type from the input type.
source§

impl From<TextEncodedScope> for Scope

source§

fn from(value: TextEncodedScope) -> Self

Converts to this type from the input type.
source§

impl Hash for Scope

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

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Scope

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<&[u8]> for Scope

§

type Error = InvalidBinaryEncodedScopeError

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

fn try_from(value: &[u8]) -> Result<Self, InvalidBinaryEncodedScopeError>

Performs the conversion.
source§

impl TryFrom<Scope> for AifEncodedScope

§

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

§

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

§

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

§

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

§

type Error = ScopeFromValueError

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

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

Performs the conversion.
source§

impl TryFrom<Vec<&str, Global>> for Scope

§

type Error = InvalidTextEncodedScopeError

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

fn try_from(value: Vec<&str>) -> Result<Self, InvalidTextEncodedScopeError>

Performs the conversion.
source§

impl TryFrom<Vec<(String, u64), Global>> for Scope

§

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 Scope

source§

impl StructuralEq for Scope

source§

impl StructuralPartialEq for Scope

Auto Trait Implementations§

§

impl RefUnwindSafe for Scope

§

impl Send for Scope

§

impl Sync for Scope

§

impl Unpin for Scope

§

impl UnwindSafe for Scope

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere T: Serialize + ?Sized,

source§

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

source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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