pub struct Username { /* private fields */ }Expand description
A normalized username claim: NFC, lowercase, bounded, never address-shaped.
Construct with Username::from_str. The stored form is the normalized
form, so Username::as_str is what gets hashed into a discovery tag,
signed into a record, and compared against a queried name.
§Ordering
Ord compares the normalized bytes. Nothing in the protocol breaks a tie
on usernames — a resolution returns an unordered set of claims and the
user arbitrates — so this exists for deterministic test fixtures and
BTreeMap keys, not for consensus.
Implementations§
Source§impl Username
impl Username
Sourcepub const MAX_BYTES: usize = 64
pub const MAX_BYTES: usize = 64
Maximum length of the normalized form, in bytes.
Bytes rather than characters because the bound exists to cap what goes
on the wire and through a hash, and a character count says nothing
about either. Matches the design record’s ≤ 64 bytes, which is far
above every username policy this SDK’s apps enforce (user-service caps
at 20 characters) — the ceiling is a wire bound, not a policy.
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the normalized username.
This is the form that is hashed, signed and published. A caller that wants the string the user typed must keep it themselves; the protocol only ever sees this one.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consumes the username, returning the normalized string.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Username
impl<'de> Deserialize<'de> for Username
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Re-validates on the way in.
A username arriving in a deserialized record is wire input: it has been normalized by somebody, and that somebody may be an attacker who normalized it differently on purpose. Parsing rather than accepting means a record whose username is not in canonical form fails to deserialize, instead of being compared against a queried name it can never equal.