wlan_common/security/wpa/
data.rs

1// Copyright 2021 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! WPA credential data mappings.
6//!
7//! This modules defines the types of credential data used by the [`Wpa`] type constructor. [`Wpa`]
8//! accepts a single type parameter that must implement the [`CredentialData`] trait. This trait
9//! defines associated types for each WPA suite (i.e., WPA Personal and WPA Enterprise) that in
10//! turn define associated types for each version of WPA. These types determine what, if any, data
11//! is contained in a [`Wpa`] instance.
12//!
13//! [`CredentialData`]: crate::security::wpa::data::CredentialData
14//! [`Wpa`]: crate::security::wpa::Wpa
15
16use std::fmt::Debug;
17
18use crate::security::wpa::{Wpa1Credentials, Wpa2PersonalCredentials, Wpa3PersonalCredentials};
19
20/// Defines the credential data used by [`WpaAuthenticator`].
21///
22/// This ZST specifies WPA Personal and WPA Enterprise types that contain credential data when used
23/// with the [`Wpa`] type constructor and is part of the [`WpaAuthenticator`] type definition. The
24/// conjugate type used for [`WpaDescriptor`] is the unit type `()`, which uses the unit type for
25/// all credential data (that is, no data at all).
26///
27/// [`WpaAuthenticator`]: crate::security::wpa::WpaAuthenticator
28/// [`WpaDescriptor`]: crate::security::wpa::WpaDescriptor
29pub enum AuthenticatorData {}
30
31/// Describes the data contained within a [`Wpa`] instance.
32pub trait CredentialData {
33    type Personal: PersonalData;
34    type Enterprise: EnterpriseData;
35}
36
37impl CredentialData for () {
38    type Personal = ();
39    type Enterprise = ();
40}
41
42impl CredentialData for AuthenticatorData {
43    type Personal = Self;
44    type Enterprise = Self;
45}
46
47// The additional type bounds on associated types limits the constraints required for `Wpa`'s
48// implementation of the same traits. See the `Copy` implementation for `Wpa` for an example where
49// these bounds cannot be applied to these associated types.
50pub trait PersonalData {
51    type Wpa1: Clone + Debug + Eq;
52    type Wpa2: Clone + Debug + Eq;
53    type Wpa3: Clone + Debug + Eq;
54}
55
56impl PersonalData for () {
57    type Wpa1 = ();
58    type Wpa2 = ();
59    type Wpa3 = ();
60}
61
62impl PersonalData for AuthenticatorData {
63    type Wpa1 = Wpa1Credentials;
64    type Wpa2 = Wpa2PersonalCredentials;
65    type Wpa3 = Wpa3PersonalCredentials;
66}
67
68pub trait EnterpriseData {
69    type Wpa2: Clone + Debug + Eq;
70    type Wpa3: Clone + Debug + Eq;
71}
72
73impl EnterpriseData for () {
74    type Wpa2 = ();
75    type Wpa3 = ();
76}
77
78impl EnterpriseData for AuthenticatorData {
79    type Wpa2 = ();
80    type Wpa3 = ();
81}