fidl_fuchsia_wlan_common_security__common/
fidl_fuchsia_wlan_common_security__common.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11/// WLAN security protocols.
12///
13/// WPA protocols are additionally enumerated by their authentication suite
14/// (i.e., Personal vs. Enterprise).
15#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
16pub enum Protocol {
17    /// Open network security.
18    ///
19    /// This indicates that no security protocol or suite is used by a WLAN; it
20    /// is not to be confused with "open authentication".
21    Open,
22    Wep,
23    Wpa1,
24    Wpa2Personal,
25    Wpa2Enterprise,
26    Wpa3Personal,
27    Wpa3Enterprise,
28    Owe,
29    #[doc(hidden)]
30    __SourceBreaking {
31        unknown_ordinal: u32,
32    },
33}
34
35/// Pattern that matches an unknown `Protocol` member.
36#[macro_export]
37macro_rules! ProtocolUnknown {
38    () => {
39        _
40    };
41}
42
43impl Protocol {
44    #[inline]
45    pub fn from_primitive(prim: u32) -> Option<Self> {
46        match prim {
47            1 => Some(Self::Open),
48            2 => Some(Self::Wep),
49            3 => Some(Self::Wpa1),
50            4 => Some(Self::Wpa2Personal),
51            5 => Some(Self::Wpa2Enterprise),
52            6 => Some(Self::Wpa3Personal),
53            7 => Some(Self::Wpa3Enterprise),
54            8 => Some(Self::Owe),
55            _ => None,
56        }
57    }
58
59    #[inline]
60    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
61        match prim {
62            1 => Self::Open,
63            2 => Self::Wep,
64            3 => Self::Wpa1,
65            4 => Self::Wpa2Personal,
66            5 => Self::Wpa2Enterprise,
67            6 => Self::Wpa3Personal,
68            7 => Self::Wpa3Enterprise,
69            8 => Self::Owe,
70            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
71        }
72    }
73
74    #[inline]
75    pub fn unknown() -> Self {
76        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
77    }
78
79    #[inline]
80    pub const fn into_primitive(self) -> u32 {
81        match self {
82            Self::Open => 1,
83            Self::Wep => 2,
84            Self::Wpa1 => 3,
85            Self::Wpa2Personal => 4,
86            Self::Wpa2Enterprise => 5,
87            Self::Wpa3Personal => 6,
88            Self::Wpa3Enterprise => 7,
89            Self::Owe => 8,
90            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
91        }
92    }
93
94    #[inline]
95    pub fn is_unknown(&self) -> bool {
96        match self {
97            Self::__SourceBreaking { unknown_ordinal: _ } => true,
98            _ => false,
99        }
100    }
101}
102
103/// Pairs credentials with a particular security protocol. This type requires
104/// validation, as `Protocol` and `Credentials` may disagree. FIDL APIs that use
105/// this type generally restrict authentication to `protocol`.
106#[derive(Clone, Debug, PartialEq)]
107pub struct Authentication {
108    pub protocol: Protocol,
109    pub credentials: Option<Box<Credentials>>,
110}
111
112impl fidl::Persistable for Authentication {}
113
114/// WEP credentials.
115#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
116pub struct WepCredentials {
117    /// Unencoded WEP key.
118    ///
119    /// This field is always a binary key; ASCII hexadecimal encoding should not
120    /// be used here.
121    pub key: Vec<u8>,
122}
123
124impl fidl::Persistable for WepCredentials {}
125
126/// Credentials used to authenticate with a WLAN.
127///
128/// The variants of this union describe the credentials supported by a protocol
129/// or protocol suite (i.e., WEP and WPA).
130#[derive(Clone, Debug)]
131pub enum Credentials {
132    Wep(WepCredentials),
133    Wpa(WpaCredentials),
134    #[doc(hidden)]
135    __SourceBreaking {
136        unknown_ordinal: u64,
137    },
138}
139
140/// Pattern that matches an unknown `Credentials` member.
141#[macro_export]
142macro_rules! CredentialsUnknown {
143    () => {
144        _
145    };
146}
147
148// Custom PartialEq so that unknown variants are not equal to themselves.
149impl PartialEq for Credentials {
150    fn eq(&self, other: &Self) -> bool {
151        match (self, other) {
152            (Self::Wep(x), Self::Wep(y)) => *x == *y,
153            (Self::Wpa(x), Self::Wpa(y)) => *x == *y,
154            _ => false,
155        }
156    }
157}
158
159impl Credentials {
160    #[inline]
161    pub fn ordinal(&self) -> u64 {
162        match *self {
163            Self::Wep(_) => 1,
164            Self::Wpa(_) => 2,
165            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
166        }
167    }
168
169    #[inline]
170    pub fn unknown_variant_for_testing() -> Self {
171        Self::__SourceBreaking { unknown_ordinal: 0 }
172    }
173
174    #[inline]
175    pub fn is_unknown(&self) -> bool {
176        match self {
177            Self::__SourceBreaking { .. } => true,
178            _ => false,
179        }
180    }
181}
182
183impl fidl::Persistable for Credentials {}
184
185/// WPA credentials.
186#[derive(Clone, Debug)]
187pub enum WpaCredentials {
188    /// Unencoded pre-shared key (PSK).
189    ///
190    /// This field is always a binary PSK; ASCII hexadecimal encoding should not
191    /// be used here.
192    Psk([u8; 32]),
193    /// UTF-8 encoded passphrase.
194    ///
195    /// This field is expected to use UTF-8 or compatible encoding. This is more
196    /// permissive than the passphrase to PSK mapping specified in IEEE Std
197    /// 802.11-2016 Appendix J.4, but UTF-8 is typically used in practice.
198    Passphrase(Vec<u8>),
199    #[doc(hidden)]
200    __SourceBreaking { unknown_ordinal: u64 },
201}
202
203/// Pattern that matches an unknown `WpaCredentials` member.
204#[macro_export]
205macro_rules! WpaCredentialsUnknown {
206    () => {
207        _
208    };
209}
210
211// Custom PartialEq so that unknown variants are not equal to themselves.
212impl PartialEq for WpaCredentials {
213    fn eq(&self, other: &Self) -> bool {
214        match (self, other) {
215            (Self::Psk(x), Self::Psk(y)) => *x == *y,
216            (Self::Passphrase(x), Self::Passphrase(y)) => *x == *y,
217            _ => false,
218        }
219    }
220}
221
222impl WpaCredentials {
223    #[inline]
224    pub fn ordinal(&self) -> u64 {
225        match *self {
226            Self::Psk(_) => 1,
227            Self::Passphrase(_) => 2,
228            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
229        }
230    }
231
232    #[inline]
233    pub fn unknown_variant_for_testing() -> Self {
234        Self::__SourceBreaking { unknown_ordinal: 0 }
235    }
236
237    #[inline]
238    pub fn is_unknown(&self) -> bool {
239        match self {
240            Self::__SourceBreaking { .. } => true,
241            _ => false,
242        }
243    }
244}
245
246impl fidl::Persistable for WpaCredentials {}
247
248mod internal {
249    use super::*;
250    unsafe impl fidl::encoding::TypeMarker for Protocol {
251        type Owned = Self;
252
253        #[inline(always)]
254        fn inline_align(_context: fidl::encoding::Context) -> usize {
255            std::mem::align_of::<u32>()
256        }
257
258        #[inline(always)]
259        fn inline_size(_context: fidl::encoding::Context) -> usize {
260            std::mem::size_of::<u32>()
261        }
262
263        #[inline(always)]
264        fn encode_is_copy() -> bool {
265            false
266        }
267
268        #[inline(always)]
269        fn decode_is_copy() -> bool {
270            false
271        }
272    }
273
274    impl fidl::encoding::ValueTypeMarker for Protocol {
275        type Borrowed<'a> = Self;
276        #[inline(always)]
277        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
278            *value
279        }
280    }
281
282    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Protocol {
283        #[inline]
284        unsafe fn encode(
285            self,
286            encoder: &mut fidl::encoding::Encoder<'_, D>,
287            offset: usize,
288            _depth: fidl::encoding::Depth,
289        ) -> fidl::Result<()> {
290            encoder.debug_check_bounds::<Self>(offset);
291            encoder.write_num(self.into_primitive(), offset);
292            Ok(())
293        }
294    }
295
296    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Protocol {
297        #[inline(always)]
298        fn new_empty() -> Self {
299            Self::unknown()
300        }
301
302        #[inline]
303        unsafe fn decode(
304            &mut self,
305            decoder: &mut fidl::encoding::Decoder<'_, D>,
306            offset: usize,
307            _depth: fidl::encoding::Depth,
308        ) -> fidl::Result<()> {
309            decoder.debug_check_bounds::<Self>(offset);
310            let prim = decoder.read_num::<u32>(offset);
311
312            *self = Self::from_primitive_allow_unknown(prim);
313            Ok(())
314        }
315    }
316
317    impl fidl::encoding::ValueTypeMarker for Authentication {
318        type Borrowed<'a> = &'a Self;
319        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
320            value
321        }
322    }
323
324    unsafe impl fidl::encoding::TypeMarker for Authentication {
325        type Owned = Self;
326
327        #[inline(always)]
328        fn inline_align(_context: fidl::encoding::Context) -> usize {
329            8
330        }
331
332        #[inline(always)]
333        fn inline_size(_context: fidl::encoding::Context) -> usize {
334            24
335        }
336    }
337
338    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Authentication, D>
339        for &Authentication
340    {
341        #[inline]
342        unsafe fn encode(
343            self,
344            encoder: &mut fidl::encoding::Encoder<'_, D>,
345            offset: usize,
346            _depth: fidl::encoding::Depth,
347        ) -> fidl::Result<()> {
348            encoder.debug_check_bounds::<Authentication>(offset);
349            // Delegate to tuple encoding.
350            fidl::encoding::Encode::<Authentication, D>::encode(
351                (
352                    <Protocol as fidl::encoding::ValueTypeMarker>::borrow(&self.protocol),
353                    <fidl::encoding::OptionalUnion<Credentials> as fidl::encoding::ValueTypeMarker>::borrow(&self.credentials),
354                ),
355                encoder, offset, _depth
356            )
357        }
358    }
359    unsafe impl<
360        D: fidl::encoding::ResourceDialect,
361        T0: fidl::encoding::Encode<Protocol, D>,
362        T1: fidl::encoding::Encode<fidl::encoding::OptionalUnion<Credentials>, D>,
363    > fidl::encoding::Encode<Authentication, D> for (T0, T1)
364    {
365        #[inline]
366        unsafe fn encode(
367            self,
368            encoder: &mut fidl::encoding::Encoder<'_, D>,
369            offset: usize,
370            depth: fidl::encoding::Depth,
371        ) -> fidl::Result<()> {
372            encoder.debug_check_bounds::<Authentication>(offset);
373            // Zero out padding regions. There's no need to apply masks
374            // because the unmasked parts will be overwritten by fields.
375            unsafe {
376                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
377                (ptr as *mut u64).write_unaligned(0);
378            }
379            // Write the fields.
380            self.0.encode(encoder, offset + 0, depth)?;
381            self.1.encode(encoder, offset + 8, depth)?;
382            Ok(())
383        }
384    }
385
386    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Authentication {
387        #[inline(always)]
388        fn new_empty() -> Self {
389            Self {
390                protocol: fidl::new_empty!(Protocol, D),
391                credentials: fidl::new_empty!(fidl::encoding::OptionalUnion<Credentials>, D),
392            }
393        }
394
395        #[inline]
396        unsafe fn decode(
397            &mut self,
398            decoder: &mut fidl::encoding::Decoder<'_, D>,
399            offset: usize,
400            _depth: fidl::encoding::Depth,
401        ) -> fidl::Result<()> {
402            decoder.debug_check_bounds::<Self>(offset);
403            // Verify that padding bytes are zero.
404            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
405            let padval = unsafe { (ptr as *const u64).read_unaligned() };
406            let mask = 0xffffffff00000000u64;
407            let maskedval = padval & mask;
408            if maskedval != 0 {
409                return Err(fidl::Error::NonZeroPadding {
410                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
411                });
412            }
413            fidl::decode!(Protocol, D, &mut self.protocol, decoder, offset + 0, _depth)?;
414            fidl::decode!(
415                fidl::encoding::OptionalUnion<Credentials>,
416                D,
417                &mut self.credentials,
418                decoder,
419                offset + 8,
420                _depth
421            )?;
422            Ok(())
423        }
424    }
425
426    impl fidl::encoding::ValueTypeMarker for WepCredentials {
427        type Borrowed<'a> = &'a Self;
428        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
429            value
430        }
431    }
432
433    unsafe impl fidl::encoding::TypeMarker for WepCredentials {
434        type Owned = Self;
435
436        #[inline(always)]
437        fn inline_align(_context: fidl::encoding::Context) -> usize {
438            8
439        }
440
441        #[inline(always)]
442        fn inline_size(_context: fidl::encoding::Context) -> usize {
443            16
444        }
445    }
446
447    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<WepCredentials, D>
448        for &WepCredentials
449    {
450        #[inline]
451        unsafe fn encode(
452            self,
453            encoder: &mut fidl::encoding::Encoder<'_, D>,
454            offset: usize,
455            _depth: fidl::encoding::Depth,
456        ) -> fidl::Result<()> {
457            encoder.debug_check_bounds::<WepCredentials>(offset);
458            // Delegate to tuple encoding.
459            fidl::encoding::Encode::<WepCredentials, D>::encode(
460                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
461                    &self.key,
462                ),),
463                encoder,
464                offset,
465                _depth,
466            )
467        }
468    }
469    unsafe impl<
470        D: fidl::encoding::ResourceDialect,
471        T0: fidl::encoding::Encode<fidl::encoding::UnboundedVector<u8>, D>,
472    > fidl::encoding::Encode<WepCredentials, D> for (T0,)
473    {
474        #[inline]
475        unsafe fn encode(
476            self,
477            encoder: &mut fidl::encoding::Encoder<'_, D>,
478            offset: usize,
479            depth: fidl::encoding::Depth,
480        ) -> fidl::Result<()> {
481            encoder.debug_check_bounds::<WepCredentials>(offset);
482            // Zero out padding regions. There's no need to apply masks
483            // because the unmasked parts will be overwritten by fields.
484            // Write the fields.
485            self.0.encode(encoder, offset + 0, depth)?;
486            Ok(())
487        }
488    }
489
490    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WepCredentials {
491        #[inline(always)]
492        fn new_empty() -> Self {
493            Self { key: fidl::new_empty!(fidl::encoding::UnboundedVector<u8>, D) }
494        }
495
496        #[inline]
497        unsafe fn decode(
498            &mut self,
499            decoder: &mut fidl::encoding::Decoder<'_, D>,
500            offset: usize,
501            _depth: fidl::encoding::Depth,
502        ) -> fidl::Result<()> {
503            decoder.debug_check_bounds::<Self>(offset);
504            // Verify that padding bytes are zero.
505            fidl::decode!(
506                fidl::encoding::UnboundedVector<u8>,
507                D,
508                &mut self.key,
509                decoder,
510                offset + 0,
511                _depth
512            )?;
513            Ok(())
514        }
515    }
516
517    impl fidl::encoding::ValueTypeMarker for Credentials {
518        type Borrowed<'a> = &'a Self;
519        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
520            value
521        }
522    }
523
524    unsafe impl fidl::encoding::TypeMarker for Credentials {
525        type Owned = Self;
526
527        #[inline(always)]
528        fn inline_align(_context: fidl::encoding::Context) -> usize {
529            8
530        }
531
532        #[inline(always)]
533        fn inline_size(_context: fidl::encoding::Context) -> usize {
534            16
535        }
536    }
537
538    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Credentials, D>
539        for &Credentials
540    {
541        #[inline]
542        unsafe fn encode(
543            self,
544            encoder: &mut fidl::encoding::Encoder<'_, D>,
545            offset: usize,
546            _depth: fidl::encoding::Depth,
547        ) -> fidl::Result<()> {
548            encoder.debug_check_bounds::<Credentials>(offset);
549            encoder.write_num::<u64>(self.ordinal(), offset);
550            match self {
551                Credentials::Wep(ref val) => {
552                    fidl::encoding::encode_in_envelope::<WepCredentials, D>(
553                        <WepCredentials as fidl::encoding::ValueTypeMarker>::borrow(val),
554                        encoder,
555                        offset + 8,
556                        _depth,
557                    )
558                }
559                Credentials::Wpa(ref val) => {
560                    fidl::encoding::encode_in_envelope::<WpaCredentials, D>(
561                        <WpaCredentials as fidl::encoding::ValueTypeMarker>::borrow(val),
562                        encoder,
563                        offset + 8,
564                        _depth,
565                    )
566                }
567                Credentials::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
568            }
569        }
570    }
571
572    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Credentials {
573        #[inline(always)]
574        fn new_empty() -> Self {
575            Self::__SourceBreaking { unknown_ordinal: 0 }
576        }
577
578        #[inline]
579        unsafe fn decode(
580            &mut self,
581            decoder: &mut fidl::encoding::Decoder<'_, D>,
582            offset: usize,
583            mut depth: fidl::encoding::Depth,
584        ) -> fidl::Result<()> {
585            decoder.debug_check_bounds::<Self>(offset);
586            #[allow(unused_variables)]
587            let next_out_of_line = decoder.next_out_of_line();
588            let handles_before = decoder.remaining_handles();
589            let (ordinal, inlined, num_bytes, num_handles) =
590                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
591
592            let member_inline_size = match ordinal {
593                1 => <WepCredentials as fidl::encoding::TypeMarker>::inline_size(decoder.context),
594                2 => <WpaCredentials as fidl::encoding::TypeMarker>::inline_size(decoder.context),
595                0 => return Err(fidl::Error::UnknownUnionTag),
596                _ => num_bytes as usize,
597            };
598
599            if inlined != (member_inline_size <= 4) {
600                return Err(fidl::Error::InvalidInlineBitInEnvelope);
601            }
602            let _inner_offset;
603            if inlined {
604                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
605                _inner_offset = offset + 8;
606            } else {
607                depth.increment()?;
608                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
609            }
610            match ordinal {
611                1 => {
612                    #[allow(irrefutable_let_patterns)]
613                    if let Credentials::Wep(_) = self {
614                        // Do nothing, read the value into the object
615                    } else {
616                        // Initialize `self` to the right variant
617                        *self = Credentials::Wep(fidl::new_empty!(WepCredentials, D));
618                    }
619                    #[allow(irrefutable_let_patterns)]
620                    if let Credentials::Wep(ref mut val) = self {
621                        fidl::decode!(WepCredentials, D, val, decoder, _inner_offset, depth)?;
622                    } else {
623                        unreachable!()
624                    }
625                }
626                2 => {
627                    #[allow(irrefutable_let_patterns)]
628                    if let Credentials::Wpa(_) = self {
629                        // Do nothing, read the value into the object
630                    } else {
631                        // Initialize `self` to the right variant
632                        *self = Credentials::Wpa(fidl::new_empty!(WpaCredentials, D));
633                    }
634                    #[allow(irrefutable_let_patterns)]
635                    if let Credentials::Wpa(ref mut val) = self {
636                        fidl::decode!(WpaCredentials, D, val, decoder, _inner_offset, depth)?;
637                    } else {
638                        unreachable!()
639                    }
640                }
641                #[allow(deprecated)]
642                ordinal => {
643                    for _ in 0..num_handles {
644                        decoder.drop_next_handle()?;
645                    }
646                    *self = Credentials::__SourceBreaking { unknown_ordinal: ordinal };
647                }
648            }
649            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
650                return Err(fidl::Error::InvalidNumBytesInEnvelope);
651            }
652            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
653                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
654            }
655            Ok(())
656        }
657    }
658
659    impl fidl::encoding::ValueTypeMarker for WpaCredentials {
660        type Borrowed<'a> = &'a Self;
661        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
662            value
663        }
664    }
665
666    unsafe impl fidl::encoding::TypeMarker for WpaCredentials {
667        type Owned = Self;
668
669        #[inline(always)]
670        fn inline_align(_context: fidl::encoding::Context) -> usize {
671            8
672        }
673
674        #[inline(always)]
675        fn inline_size(_context: fidl::encoding::Context) -> usize {
676            16
677        }
678    }
679
680    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<WpaCredentials, D>
681        for &WpaCredentials
682    {
683        #[inline]
684        unsafe fn encode(
685            self,
686            encoder: &mut fidl::encoding::Encoder<'_, D>,
687            offset: usize,
688            _depth: fidl::encoding::Depth,
689        ) -> fidl::Result<()> {
690            encoder.debug_check_bounds::<WpaCredentials>(offset);
691            encoder.write_num::<u64>(self.ordinal(), offset);
692            match self {
693                WpaCredentials::Psk(ref val) => fidl::encoding::encode_in_envelope::<
694                    fidl::encoding::Array<u8, 32>,
695                    D,
696                >(
697                    <fidl::encoding::Array<u8, 32> as fidl::encoding::ValueTypeMarker>::borrow(val),
698                    encoder,
699                    offset + 8,
700                    _depth,
701                ),
702                WpaCredentials::Passphrase(ref val) => {
703                    fidl::encoding::encode_in_envelope::<fidl::encoding::Vector<u8, 63>, D>(
704                        <fidl::encoding::Vector<u8, 63> as fidl::encoding::ValueTypeMarker>::borrow(
705                            val,
706                        ),
707                        encoder,
708                        offset + 8,
709                        _depth,
710                    )
711                }
712                WpaCredentials::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
713            }
714        }
715    }
716
717    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WpaCredentials {
718        #[inline(always)]
719        fn new_empty() -> Self {
720            Self::__SourceBreaking { unknown_ordinal: 0 }
721        }
722
723        #[inline]
724        unsafe fn decode(
725            &mut self,
726            decoder: &mut fidl::encoding::Decoder<'_, D>,
727            offset: usize,
728            mut depth: fidl::encoding::Depth,
729        ) -> fidl::Result<()> {
730            decoder.debug_check_bounds::<Self>(offset);
731            #[allow(unused_variables)]
732            let next_out_of_line = decoder.next_out_of_line();
733            let handles_before = decoder.remaining_handles();
734            let (ordinal, inlined, num_bytes, num_handles) =
735                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
736
737            let member_inline_size = match ordinal {
738                1 => <fidl::encoding::Array<u8, 32> as fidl::encoding::TypeMarker>::inline_size(
739                    decoder.context,
740                ),
741                2 => <fidl::encoding::Vector<u8, 63> as fidl::encoding::TypeMarker>::inline_size(
742                    decoder.context,
743                ),
744                0 => return Err(fidl::Error::UnknownUnionTag),
745                _ => num_bytes as usize,
746            };
747
748            if inlined != (member_inline_size <= 4) {
749                return Err(fidl::Error::InvalidInlineBitInEnvelope);
750            }
751            let _inner_offset;
752            if inlined {
753                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
754                _inner_offset = offset + 8;
755            } else {
756                depth.increment()?;
757                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
758            }
759            match ordinal {
760                1 => {
761                    #[allow(irrefutable_let_patterns)]
762                    if let WpaCredentials::Psk(_) = self {
763                        // Do nothing, read the value into the object
764                    } else {
765                        // Initialize `self` to the right variant
766                        *self =
767                            WpaCredentials::Psk(fidl::new_empty!(fidl::encoding::Array<u8, 32>, D));
768                    }
769                    #[allow(irrefutable_let_patterns)]
770                    if let WpaCredentials::Psk(ref mut val) = self {
771                        fidl::decode!(fidl::encoding::Array<u8, 32>, D, val, decoder, _inner_offset, depth)?;
772                    } else {
773                        unreachable!()
774                    }
775                }
776                2 => {
777                    #[allow(irrefutable_let_patterns)]
778                    if let WpaCredentials::Passphrase(_) = self {
779                        // Do nothing, read the value into the object
780                    } else {
781                        // Initialize `self` to the right variant
782                        *self = WpaCredentials::Passphrase(
783                            fidl::new_empty!(fidl::encoding::Vector<u8, 63>, D),
784                        );
785                    }
786                    #[allow(irrefutable_let_patterns)]
787                    if let WpaCredentials::Passphrase(ref mut val) = self {
788                        fidl::decode!(fidl::encoding::Vector<u8, 63>, D, val, decoder, _inner_offset, depth)?;
789                    } else {
790                        unreachable!()
791                    }
792                }
793                #[allow(deprecated)]
794                ordinal => {
795                    for _ in 0..num_handles {
796                        decoder.drop_next_handle()?;
797                    }
798                    *self = WpaCredentials::__SourceBreaking { unknown_ordinal: ordinal };
799                }
800            }
801            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
802                return Err(fidl::Error::InvalidNumBytesInEnvelope);
803            }
804            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
805                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
806            }
807            Ok(())
808        }
809    }
810}