pub struct Username { /* private fields */ }
Expand description
The username Attribute
Implementations§
source§impl Username
impl Username
sourcepub fn new(user: &str) -> Result<Self, StunParseError>
pub fn new(user: &str) -> Result<Self, StunParseError>
Create a new Username
Attribute
Errors
- When the length of the username is longer than allowed in a STUN
Message
- TODO: If converting through SASLPrep fails
Examples
let username = Username::new ("user").unwrap();
assert_eq!(username.username(), "user");
Examples found in repository?
src/conncheck.rs (line 173)
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
fn generate_stun_request(
conncheck: Arc<ConnCheck>,
username: String,
controlling: bool,
tie_breaker: u64,
) -> Result<StunRequest, StunError> {
let mut msg = Message::new_request(BINDING);
// XXX: this needs to be the priority as if the candidate was peer-reflexive
msg.add_attribute(Priority::new(conncheck.pair.local.priority))?;
if controlling {
msg.add_attribute(IceControlling::new(tie_breaker))?;
} else {
msg.add_attribute(IceControlled::new(tie_breaker))?;
}
if conncheck.nominate {
msg.add_attribute(UseCandidate::new())?;
}
msg.add_attribute(Username::new(&username)?)?;
msg.add_message_integrity(&conncheck.agent.local_credentials().unwrap())?;
msg.add_fingerprint()?;
let to = conncheck.pair.remote.address;
conncheck.agent.stun_request_transaction(&msg, to)?.build()
}
sourcepub fn username(&self) -> &str
pub fn username(&self) -> &str
The username stored in a Username
Attribute
Examples
let username = Username::new ("user").unwrap();
assert_eq!(username.username(), "user");
Examples found in repository?
src/conncheck.rs (line 1927)
1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941
fn validate_username(username: Username, local_credentials: &Credentials) -> bool {
let username = username.username().as_bytes();
let local_user = local_credentials.ufrag.as_bytes();
if local_user.len()
== local_user
.iter()
.zip(username)
.take_while(|(l, r)| l == r)
.count()
{
true
} else {
debug!("binding request failed username validation");
false
}
}
Trait Implementations§
source§impl Attribute for Username
impl Attribute for Username
source§fn get_type(&self) -> AttributeType
fn get_type(&self) -> AttributeType
Retrieve the
AttributeType
of an Attribute
source§fn length(&self) -> u16
fn length(&self) -> u16
Retrieve the length of an
Attribute
. This is not the padded length as stored in a
Message
source§fn to_raw(&self) -> RawAttribute
fn to_raw(&self) -> RawAttribute
Convert an
Attribute
to a RawAttribute
source§fn from_raw(raw: &RawAttribute) -> Result<Self, StunParseError>
fn from_raw(raw: &RawAttribute) -> Result<Self, StunParseError>
Convert an
Attribute
from a RawAttribute
source§impl From<Username> for RawAttribute
impl From<Username> for RawAttribute
source§impl TryFrom<&RawAttribute> for Username
impl TryFrom<&RawAttribute> for Username
§type Error = StunParseError
type Error = StunParseError
The type returned in the event of a conversion error.