1use std::{fmt, str::FromStr};
16
17use serde::{Deserialize, Serialize};
18
19#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
20#[allow(non_camel_case_types)]
21pub enum ProofAlgorithm {
24 #[serde(rename = "BBS")]
26 BBS,
27 #[serde(rename = "BBS-SHAKE256")]
29 BBS_SHAKE256,
30 #[serde(rename = "SU-ES256")]
32 SU_ES256,
33 #[serde(rename = "SU-ES384")]
35 SU_ES384,
36 #[serde(rename = "SU-ES512")]
38 SU_ES512,
39 #[serde(rename = "MAC-H256")]
41 MAC_H256,
42 #[serde(rename = "MAC-H384")]
44 MAC_H384,
45 #[serde(rename = "MAC-H512")]
47 MAC_H512,
48 #[serde(rename = "MAC-K25519")]
50 MAC_K25519,
51 #[serde(rename = "MAC-K448")]
53 MAC_K448,
54 #[serde(rename = "MAC-H256K")]
56 MAC_H256K,
57}
58
59impl Into<PresentationProofAlgorithm> for ProofAlgorithm {
60 fn into(self) -> PresentationProofAlgorithm {
61 match self {
62 ProofAlgorithm::BBS => PresentationProofAlgorithm::BBS,
63 ProofAlgorithm::BBS_SHAKE256 => PresentationProofAlgorithm::BBS_SHAKE256,
64 ProofAlgorithm::SU_ES256 => PresentationProofAlgorithm::SU_ES256,
65 ProofAlgorithm::SU_ES384 => PresentationProofAlgorithm::SU_ES384,
66 ProofAlgorithm::SU_ES512 => PresentationProofAlgorithm::SU_ES512,
67 ProofAlgorithm::MAC_H256 => PresentationProofAlgorithm::MAC_H256,
68 ProofAlgorithm::MAC_H384 => PresentationProofAlgorithm::MAC_H384,
69 ProofAlgorithm::MAC_H512 => PresentationProofAlgorithm::MAC_H512,
70 ProofAlgorithm::MAC_K25519 => PresentationProofAlgorithm::MAC_K25519,
71 ProofAlgorithm::MAC_K448 => PresentationProofAlgorithm::MAC_K448,
72 ProofAlgorithm::MAC_H256K => PresentationProofAlgorithm::MAC_H256K,
73 }
74 }
75}
76
77impl fmt::Display for ProofAlgorithm {
78 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
79 let variant_str = match self {
80 ProofAlgorithm::BBS => "BBS",
81 ProofAlgorithm::BBS_SHAKE256 => "BBS-SHAKE256",
82 ProofAlgorithm::SU_ES256 => "SU-ES256",
83 ProofAlgorithm::SU_ES384 => "SU-ES384",
84 ProofAlgorithm::SU_ES512 => "SU-ES512",
85 ProofAlgorithm::MAC_H256 => "MAC-H256",
86 ProofAlgorithm::MAC_H384 => "MAC-H384",
87 ProofAlgorithm::MAC_H512 => "MAC-H512",
88 ProofAlgorithm::MAC_K25519 => "MAC-K25519",
89 ProofAlgorithm::MAC_K448 => "MAC-K448",
90 ProofAlgorithm::MAC_H256K => "MAC-H256K",
91
92 };
93 write!(f, "{}", variant_str)
94 }
95}
96
97impl FromStr for ProofAlgorithm {
98 type Err = &'static str;
99
100 fn from_str(s: &str) -> Result<Self, Self::Err> {
101 match s {
102 "BBS" => Ok(ProofAlgorithm::BBS),
103 "BBS-SHAKE256" => Ok(ProofAlgorithm::BBS_SHAKE256),
104 "SU-ES256" => Ok(ProofAlgorithm::SU_ES256),
105 "SU-ES384" => Ok(ProofAlgorithm::SU_ES384),
106 "MAC-H256" => Ok(ProofAlgorithm::MAC_H256),
107 "MAC-H384" => Ok(ProofAlgorithm::MAC_H384),
108 "MAC-H512" => Ok(ProofAlgorithm::MAC_H512),
109 "MAC-K25519" => Ok(ProofAlgorithm::MAC_K25519),
110 "MAC-K448" => Ok(ProofAlgorithm::MAC_K448),
111 "MAC-H256K" => Ok(ProofAlgorithm::MAC_H256K),
112 _ => Err("Invalid proof algorithm"),
113 }
114 }
115}
116
117#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
118#[allow(non_camel_case_types)]
119pub enum PresentationProofAlgorithm {
122 #[serde(rename = "BBS")]
124 BBS,
125 #[serde(rename = "BBS-SHAKE256")]
127 BBS_SHAKE256,
128 #[serde(rename = "SU-ES256")]
130 SU_ES256,
131 #[serde(rename = "SU-ES384")]
133 SU_ES384,
134 #[serde(rename = "SU-ES512")]
136 SU_ES512,
137 #[serde(rename = "MAC-H256")]
139 MAC_H256,
140 #[serde(rename = "MAC-H384")]
142 MAC_H384,
143 #[serde(rename = "MAC-H512")]
145 MAC_H512,
146 #[serde(rename = "MAC-K25519")]
148 MAC_K25519,
149 #[serde(rename = "MAC-K448")]
151 MAC_K448,
152 #[serde(rename = "MAC-H256K")]
154 MAC_H256K,
155}
156
157impl fmt::Display for PresentationProofAlgorithm {
158 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
159 let variant_str = match self {
160 PresentationProofAlgorithm::BBS => "BBS",
161 PresentationProofAlgorithm::BBS_SHAKE256 => "BBS-SHAKE256",
162 PresentationProofAlgorithm::SU_ES256 => "SU-ES256",
163 PresentationProofAlgorithm::SU_ES384 => "SU-ES384",
164 PresentationProofAlgorithm::SU_ES512 => "SU-ES512",
165 PresentationProofAlgorithm::MAC_H256 => "MAC-H256",
166 PresentationProofAlgorithm::MAC_H384 => "MAC-H384",
167 PresentationProofAlgorithm::MAC_H512 => "MAC-H512",
168 PresentationProofAlgorithm::MAC_K25519 => "MAC-K25519",
169 PresentationProofAlgorithm::MAC_K448 => "MAC-K448",
170 PresentationProofAlgorithm::MAC_H256K => "MAC-H256K",
171 };
172 write!(f, "{}", variant_str)
173 }
174}
175
176impl FromStr for PresentationProofAlgorithm {
177 type Err = &'static str;
178
179 fn from_str(s: &str) -> Result<Self, Self::Err> {
180 match s {
181 "BBS-PROOF" => Ok(PresentationProofAlgorithm::BBS),
182 "BBS-SHAKE256-PROOF" => Ok(PresentationProofAlgorithm::BBS_SHAKE256),
183 "SU-ES256" => Ok(PresentationProofAlgorithm::SU_ES256),
184 "SU-ES384" => Ok(PresentationProofAlgorithm::SU_ES384),
185 "MAC-H256" => Ok(PresentationProofAlgorithm::MAC_H256),
186 "MAC-H384" => Ok(PresentationProofAlgorithm::MAC_H384),
187 "MAC-H512" => Ok(PresentationProofAlgorithm::MAC_H512),
188 "MAC-K25519" => Ok(PresentationProofAlgorithm::MAC_K25519),
189 "MAC-K448" => Ok(PresentationProofAlgorithm::MAC_K448),
190 "MAC-H256K" => Ok(PresentationProofAlgorithm::MAC_H256K),
191 _ => Err("Invalid proof algorithm"),
192 }
193 }
194}