/// Returns an error if the input network values are not valid or none if the values are valid.
/// For example it is an error if the network is Open (no password) but a password is supplied.
/// TODO(nmccracken) - Specific errors need to be added to the API and returned here
Returns an error if the input network values are not valid or none if the values are valid.
For example it is an error if the network is Open (no password) but a password is supplied.
TODO(nmccracken) - Specific errors need to be added to the API and returned here
Returns an error if the input network values are not valid or none if the values are valid . For example it is an error if the network is Open ( no password ) but a password is supplied . TODO ( nmccracken ) - Specific errors need to be added to the API and returned here
fn check_config_errors(
    ssid: impl AsRef<[u8]>,
    security_type: &SecurityType,
    credential: &Credential,
) -> Result<(), NetworkConfigError> {
    // Verify SSID has at most 32 characters
    if ssid.as_ref().len() > MAX_SSID_LEN {
        return Err(NetworkConfigError::SsidLen);
    }
    // Verify that credentials match security type
    match security_type {
        SecurityType::None => {
            if let Credential::Psk(_) | Credential::Password(_) = credential {
                return Err(NetworkConfigError::OpenNetworkPassword);
            }
        }
        SecurityType::Wpa | SecurityType::Wpa2 | SecurityType::Wpa3 => match credential {
            Credential::Password(pwd) => {
                if pwd.clone().len() < MIN_PASSWORD_LEN || pwd.clone().len() > MAX_PASSWORD_LEN {
                    return Err(NetworkConfigError::PasswordLen);
                }
            }
            Credential::Psk(psk) => {
                if psk.clone().len() != PSK_BYTE_LEN {
                    return Err(NetworkConfigError::PskLen);
                }
            }
            _ => {
                return Err(NetworkConfigError::MissingPasswordPsk);
            }
        },
        _ => {}
    }
    Ok(())
}
fn check_config_errors ( ssid : impl AsRef < [ u8 ] > , security_type : & SecurityType , credential : & Credential , ) -> Result < ( ) , NetworkConfigError > { // Verify SSID has at most 32 characters if ssid . as_ref ( ) . len ( ) > MAX_SSID_LEN { return Err ( NetworkConfigError :: SsidLen ) ; } // Verify that credentials match security type match security_type { SecurityType :: None => { if let Credential :: Psk ( _ ) | Credential :: Password ( _ ) = credential { return Err ( NetworkConfigError :: OpenNetworkPassword ) ; } } SecurityType :: Wpa | SecurityType :: Wpa2 | SecurityType :: Wpa3 => match credential { Credential :: Password ( pwd ) => { if pwd . clone ( ) . len ( ) < MIN_PASSWORD_LEN || pwd . clone ( ) . len ( ) > MAX_PASSWORD_LEN { return Err ( NetworkConfigError :: PasswordLen ) ; } } Credential :: Psk ( psk ) => { if psk . clone ( ) . len ( ) != PSK_BYTE_LEN { return Err ( NetworkConfigError :: PskLen ) ; } } _ => { return Err ( NetworkConfigError :: MissingPasswordPsk ) ; } } , _ => { } } Ok ( ( ) ) }
Returns an error if the input network values are not valid or none if the values are valid.
Returns an error if the input network values are not valid or none if the values are valid .
ssid
impl AsRef<[u8]>
security_type
&SecurityType
credential
&Credential