1#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15 buf::{ByteBuf, ByteBufMut},
16 compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17 Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct AlterUserScramCredentialsRequest {
24 pub deletions: Vec<ScramCredentialDeletion>,
28
29 pub upsertions: Vec<ScramCredentialUpsertion>,
33
34 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl AlterUserScramCredentialsRequest {
39 pub fn with_deletions(mut self, value: Vec<ScramCredentialDeletion>) -> Self {
45 self.deletions = value;
46 self
47 }
48 pub fn with_upsertions(mut self, value: Vec<ScramCredentialUpsertion>) -> Self {
54 self.upsertions = value;
55 self
56 }
57 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
59 self.unknown_tagged_fields = value;
60 self
61 }
62 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
64 self.unknown_tagged_fields.insert(key, value);
65 self
66 }
67}
68
69#[cfg(feature = "client")]
70impl Encodable for AlterUserScramCredentialsRequest {
71 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
72 types::CompactArray(types::Struct { version }).encode(buf, &self.deletions)?;
73 types::CompactArray(types::Struct { version }).encode(buf, &self.upsertions)?;
74 let num_tagged_fields = self.unknown_tagged_fields.len();
75 if num_tagged_fields > std::u32::MAX as usize {
76 bail!(
77 "Too many tagged fields to encode ({} fields)",
78 num_tagged_fields
79 );
80 }
81 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
82
83 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
84 Ok(())
85 }
86 fn compute_size(&self, version: i16) -> Result<usize> {
87 let mut total_size = 0;
88 total_size +=
89 types::CompactArray(types::Struct { version }).compute_size(&self.deletions)?;
90 total_size +=
91 types::CompactArray(types::Struct { version }).compute_size(&self.upsertions)?;
92 let num_tagged_fields = self.unknown_tagged_fields.len();
93 if num_tagged_fields > std::u32::MAX as usize {
94 bail!(
95 "Too many tagged fields to encode ({} fields)",
96 num_tagged_fields
97 );
98 }
99 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
100
101 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
102 Ok(total_size)
103 }
104}
105
106#[cfg(feature = "broker")]
107impl Decodable for AlterUserScramCredentialsRequest {
108 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
109 let deletions = types::CompactArray(types::Struct { version }).decode(buf)?;
110 let upsertions = types::CompactArray(types::Struct { version }).decode(buf)?;
111 let mut unknown_tagged_fields = BTreeMap::new();
112 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
113 for _ in 0..num_tagged_fields {
114 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
115 let size: u32 = types::UnsignedVarInt.decode(buf)?;
116 let unknown_value = buf.try_get_bytes(size as usize)?;
117 unknown_tagged_fields.insert(tag as i32, unknown_value);
118 }
119 Ok(Self {
120 deletions,
121 upsertions,
122 unknown_tagged_fields,
123 })
124 }
125}
126
127impl Default for AlterUserScramCredentialsRequest {
128 fn default() -> Self {
129 Self {
130 deletions: Default::default(),
131 upsertions: Default::default(),
132 unknown_tagged_fields: BTreeMap::new(),
133 }
134 }
135}
136
137impl Message for AlterUserScramCredentialsRequest {
138 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
139 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
140}
141
142#[non_exhaustive]
144#[derive(Debug, Clone, PartialEq)]
145pub struct ScramCredentialDeletion {
146 pub name: StrBytes,
150
151 pub mechanism: i8,
155
156 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
158}
159
160impl ScramCredentialDeletion {
161 pub fn with_name(mut self, value: StrBytes) -> Self {
167 self.name = value;
168 self
169 }
170 pub fn with_mechanism(mut self, value: i8) -> Self {
176 self.mechanism = value;
177 self
178 }
179 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
181 self.unknown_tagged_fields = value;
182 self
183 }
184 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
186 self.unknown_tagged_fields.insert(key, value);
187 self
188 }
189}
190
191#[cfg(feature = "client")]
192impl Encodable for ScramCredentialDeletion {
193 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
194 types::CompactString.encode(buf, &self.name)?;
195 types::Int8.encode(buf, &self.mechanism)?;
196 let num_tagged_fields = self.unknown_tagged_fields.len();
197 if num_tagged_fields > std::u32::MAX as usize {
198 bail!(
199 "Too many tagged fields to encode ({} fields)",
200 num_tagged_fields
201 );
202 }
203 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
204
205 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
206 Ok(())
207 }
208 fn compute_size(&self, version: i16) -> Result<usize> {
209 let mut total_size = 0;
210 total_size += types::CompactString.compute_size(&self.name)?;
211 total_size += types::Int8.compute_size(&self.mechanism)?;
212 let num_tagged_fields = self.unknown_tagged_fields.len();
213 if num_tagged_fields > std::u32::MAX as usize {
214 bail!(
215 "Too many tagged fields to encode ({} fields)",
216 num_tagged_fields
217 );
218 }
219 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
220
221 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
222 Ok(total_size)
223 }
224}
225
226#[cfg(feature = "broker")]
227impl Decodable for ScramCredentialDeletion {
228 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
229 let name = types::CompactString.decode(buf)?;
230 let mechanism = types::Int8.decode(buf)?;
231 let mut unknown_tagged_fields = BTreeMap::new();
232 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
233 for _ in 0..num_tagged_fields {
234 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
235 let size: u32 = types::UnsignedVarInt.decode(buf)?;
236 let unknown_value = buf.try_get_bytes(size as usize)?;
237 unknown_tagged_fields.insert(tag as i32, unknown_value);
238 }
239 Ok(Self {
240 name,
241 mechanism,
242 unknown_tagged_fields,
243 })
244 }
245}
246
247impl Default for ScramCredentialDeletion {
248 fn default() -> Self {
249 Self {
250 name: Default::default(),
251 mechanism: 0,
252 unknown_tagged_fields: BTreeMap::new(),
253 }
254 }
255}
256
257impl Message for ScramCredentialDeletion {
258 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
259 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
260}
261
262#[non_exhaustive]
264#[derive(Debug, Clone, PartialEq)]
265pub struct ScramCredentialUpsertion {
266 pub name: StrBytes,
270
271 pub mechanism: i8,
275
276 pub iterations: i32,
280
281 pub salt: Bytes,
285
286 pub salted_password: Bytes,
290
291 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
293}
294
295impl ScramCredentialUpsertion {
296 pub fn with_name(mut self, value: StrBytes) -> Self {
302 self.name = value;
303 self
304 }
305 pub fn with_mechanism(mut self, value: i8) -> Self {
311 self.mechanism = value;
312 self
313 }
314 pub fn with_iterations(mut self, value: i32) -> Self {
320 self.iterations = value;
321 self
322 }
323 pub fn with_salt(mut self, value: Bytes) -> Self {
329 self.salt = value;
330 self
331 }
332 pub fn with_salted_password(mut self, value: Bytes) -> Self {
338 self.salted_password = value;
339 self
340 }
341 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
343 self.unknown_tagged_fields = value;
344 self
345 }
346 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
348 self.unknown_tagged_fields.insert(key, value);
349 self
350 }
351}
352
353#[cfg(feature = "client")]
354impl Encodable for ScramCredentialUpsertion {
355 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
356 types::CompactString.encode(buf, &self.name)?;
357 types::Int8.encode(buf, &self.mechanism)?;
358 types::Int32.encode(buf, &self.iterations)?;
359 types::CompactBytes.encode(buf, &self.salt)?;
360 types::CompactBytes.encode(buf, &self.salted_password)?;
361 let num_tagged_fields = self.unknown_tagged_fields.len();
362 if num_tagged_fields > std::u32::MAX as usize {
363 bail!(
364 "Too many tagged fields to encode ({} fields)",
365 num_tagged_fields
366 );
367 }
368 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
369
370 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
371 Ok(())
372 }
373 fn compute_size(&self, version: i16) -> Result<usize> {
374 let mut total_size = 0;
375 total_size += types::CompactString.compute_size(&self.name)?;
376 total_size += types::Int8.compute_size(&self.mechanism)?;
377 total_size += types::Int32.compute_size(&self.iterations)?;
378 total_size += types::CompactBytes.compute_size(&self.salt)?;
379 total_size += types::CompactBytes.compute_size(&self.salted_password)?;
380 let num_tagged_fields = self.unknown_tagged_fields.len();
381 if num_tagged_fields > std::u32::MAX as usize {
382 bail!(
383 "Too many tagged fields to encode ({} fields)",
384 num_tagged_fields
385 );
386 }
387 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
388
389 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
390 Ok(total_size)
391 }
392}
393
394#[cfg(feature = "broker")]
395impl Decodable for ScramCredentialUpsertion {
396 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
397 let name = types::CompactString.decode(buf)?;
398 let mechanism = types::Int8.decode(buf)?;
399 let iterations = types::Int32.decode(buf)?;
400 let salt = types::CompactBytes.decode(buf)?;
401 let salted_password = types::CompactBytes.decode(buf)?;
402 let mut unknown_tagged_fields = BTreeMap::new();
403 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
404 for _ in 0..num_tagged_fields {
405 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
406 let size: u32 = types::UnsignedVarInt.decode(buf)?;
407 let unknown_value = buf.try_get_bytes(size as usize)?;
408 unknown_tagged_fields.insert(tag as i32, unknown_value);
409 }
410 Ok(Self {
411 name,
412 mechanism,
413 iterations,
414 salt,
415 salted_password,
416 unknown_tagged_fields,
417 })
418 }
419}
420
421impl Default for ScramCredentialUpsertion {
422 fn default() -> Self {
423 Self {
424 name: Default::default(),
425 mechanism: 0,
426 iterations: 0,
427 salt: Default::default(),
428 salted_password: Default::default(),
429 unknown_tagged_fields: BTreeMap::new(),
430 }
431 }
432}
433
434impl Message for ScramCredentialUpsertion {
435 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
436 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
437}
438
439impl HeaderVersion for AlterUserScramCredentialsRequest {
440 fn header_version(version: i16) -> i16 {
441 2
442 }
443}