stellar_xdr/generated/
signer_key.rs1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
30#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
31#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
32#[cfg_attr(
33 all(feature = "serde", feature = "alloc"),
34 derive(serde_with::SerializeDisplay, serde_with::DeserializeFromStr)
35)]
36#[allow(clippy::large_enum_variant)]
37pub enum SignerKey {
38 Ed25519(Uint256),
39 PreAuthTx(Uint256),
40 HashX(Uint256),
41 Ed25519SignedPayload(SignerKeyEd25519SignedPayload),
42}
43
44#[cfg(feature = "alloc")]
45impl Default for SignerKey {
46 fn default() -> Self {
47 Self::Ed25519(Uint256::default())
48 }
49}
50
51impl SignerKey {
52 const _VARIANTS: &[SignerKeyType] = &[
53 SignerKeyType::Ed25519,
54 SignerKeyType::PreAuthTx,
55 SignerKeyType::HashX,
56 SignerKeyType::Ed25519SignedPayload,
57 ];
58 pub const VARIANTS: [SignerKeyType; Self::_VARIANTS.len()] = {
59 let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
60 let mut i = 1;
61 while i < Self::_VARIANTS.len() {
62 arr[i] = Self::_VARIANTS[i];
63 i += 1;
64 }
65 arr
66 };
67 const _VARIANTS_STR: &[&str] = &["Ed25519", "PreAuthTx", "HashX", "Ed25519SignedPayload"];
68 pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
69 let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
70 let mut i = 1;
71 while i < Self::_VARIANTS_STR.len() {
72 arr[i] = Self::_VARIANTS_STR[i];
73 i += 1;
74 }
75 arr
76 };
77
78 #[must_use]
79 pub const fn name(&self) -> &'static str {
80 match self {
81 Self::Ed25519(_) => "Ed25519",
82 Self::PreAuthTx(_) => "PreAuthTx",
83 Self::HashX(_) => "HashX",
84 Self::Ed25519SignedPayload(_) => "Ed25519SignedPayload",
85 }
86 }
87
88 #[must_use]
89 pub const fn discriminant(&self) -> SignerKeyType {
90 #[allow(clippy::match_same_arms)]
91 match self {
92 Self::Ed25519(_) => SignerKeyType::Ed25519,
93 Self::PreAuthTx(_) => SignerKeyType::PreAuthTx,
94 Self::HashX(_) => SignerKeyType::HashX,
95 Self::Ed25519SignedPayload(_) => SignerKeyType::Ed25519SignedPayload,
96 }
97 }
98
99 #[must_use]
100 pub const fn variants() -> [SignerKeyType; Self::_VARIANTS.len()] {
101 Self::VARIANTS
102 }
103}
104
105impl Name for SignerKey {
106 #[must_use]
107 fn name(&self) -> &'static str {
108 Self::name(self)
109 }
110}
111
112impl Discriminant<SignerKeyType> for SignerKey {
113 #[must_use]
114 fn discriminant(&self) -> SignerKeyType {
115 Self::discriminant(self)
116 }
117}
118
119impl Variants<SignerKeyType> for SignerKey {
120 fn variants() -> slice::Iter<'static, SignerKeyType> {
121 Self::VARIANTS.iter()
122 }
123}
124
125impl Union<SignerKeyType> for SignerKey {}
126
127impl ReadXdr for SignerKey {
128 #[cfg(feature = "std")]
129 fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
130 r.with_limited_depth(|r| {
131 let dv: SignerKeyType = <SignerKeyType as ReadXdr>::read_xdr(r)?;
132 #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
133 let v = match dv {
134 SignerKeyType::Ed25519 => Self::Ed25519(Uint256::read_xdr(r)?),
135 SignerKeyType::PreAuthTx => Self::PreAuthTx(Uint256::read_xdr(r)?),
136 SignerKeyType::HashX => Self::HashX(Uint256::read_xdr(r)?),
137 SignerKeyType::Ed25519SignedPayload => {
138 Self::Ed25519SignedPayload(SignerKeyEd25519SignedPayload::read_xdr(r)?)
139 }
140 #[allow(unreachable_patterns)]
141 _ => return Err(Error::Invalid),
142 };
143 Ok(v)
144 })
145 }
146}
147
148impl WriteXdr for SignerKey {
149 #[cfg(feature = "std")]
150 fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
151 w.with_limited_depth(|w| {
152 self.discriminant().write_xdr(w)?;
153 #[allow(clippy::match_same_arms)]
154 match self {
155 Self::Ed25519(v) => v.write_xdr(w)?,
156 Self::PreAuthTx(v) => v.write_xdr(w)?,
157 Self::HashX(v) => v.write_xdr(w)?,
158 Self::Ed25519SignedPayload(v) => v.write_xdr(w)?,
159 };
160 Ok(())
161 })
162 }
163}