identity_verification/verification_method/
method_scope.rs1use core::fmt;
5use core::fmt::Display;
6use core::str::FromStr;
7
8use identity_core::convert::FmtJson;
9
10use crate::error::Error;
11use crate::error::Result;
12use crate::verification_method::MethodRelationship;
13
14#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
19pub enum MethodScope {
20 VerificationMethod,
22 VerificationRelationship(MethodRelationship),
24}
25
26impl MethodScope {
27 pub fn as_str(&self) -> &'static str {
29 match self {
30 Self::VerificationMethod => "VerificationMethod",
31 Self::VerificationRelationship(relationship) => relationship.into(),
32 }
33 }
34
35 pub const fn authentication() -> Self {
37 Self::VerificationRelationship(MethodRelationship::Authentication)
38 }
39
40 pub const fn capability_delegation() -> Self {
42 Self::VerificationRelationship(MethodRelationship::CapabilityDelegation)
43 }
44
45 pub const fn capability_invocation() -> Self {
47 Self::VerificationRelationship(MethodRelationship::CapabilityInvocation)
48 }
49
50 pub const fn assertion_method() -> Self {
52 Self::VerificationRelationship(MethodRelationship::AssertionMethod)
53 }
54
55 pub const fn key_agreement() -> Self {
57 Self::VerificationRelationship(MethodRelationship::KeyAgreement)
58 }
59}
60
61impl Default for MethodScope {
62 fn default() -> Self {
63 Self::VerificationMethod
64 }
65}
66
67impl FromStr for MethodScope {
68 type Err = Error;
69
70 fn from_str(string: &str) -> Result<Self, Self::Err> {
71 match string {
72 "VerificationMethod" => Ok(Self::VerificationMethod),
73 "Authentication" => Ok(Self::VerificationRelationship(MethodRelationship::Authentication)),
74 "AssertionMethod" => Ok(Self::VerificationRelationship(MethodRelationship::AssertionMethod)),
75 "KeyAgreement" => Ok(Self::VerificationRelationship(MethodRelationship::KeyAgreement)),
76 "CapabilityDelegation" => Ok(Self::VerificationRelationship(MethodRelationship::CapabilityDelegation)),
77 "CapabilityInvocation" => Ok(Self::VerificationRelationship(MethodRelationship::CapabilityInvocation)),
78 _ => Err(Error::UnknownMethodScope),
79 }
80 }
81}
82
83impl From<MethodRelationship> for MethodScope {
84 fn from(relationship: MethodRelationship) -> Self {
85 Self::VerificationRelationship(relationship)
86 }
87}
88
89impl Display for MethodScope {
90 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91 self.fmt_json(f)
92 }
93}