#[non_exhaustive]pub struct CodeAlphabet {
pub chars: String,
pub len: usize,
}Expand description
The characters and length of a short code a person reads and types: a PIN or a device-flow user code.
The crate matches codes exactly over chars: it ignores no case, dash or space. Normalising
what a person typed, and grouping a code for display, is the caller’s. Any alphabet and
length with a meaning is accepted; combinations says how many
codes there are, which is what an attacker’s one guess is against.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.chars: StringThe characters a code is made of, each once.
len: usizeHow many characters a code has.
Implementations§
Source§impl CodeAlphabet
impl CodeAlphabet
Sourcepub fn new(chars: impl Into<String>, len: usize) -> Self
pub fn new(chars: impl Into<String>, len: usize) -> Self
An alphabet of the characters chars, each once, and codes of len of them.
Sourcepub fn user_code() -> Self
pub fn user_code() -> Self
The default user-code alphabet of RFC 8628 section 6.1: BCDFGHJKLMNPQRSTVWXZ, 8
characters (about 2.6 × 10^10 codes).
Sourcepub fn combinations(&self) -> u128
pub fn combinations(&self) -> u128
How many distinct codes there are, saturating at u128::MAX.
Trait Implementations§
Source§impl Clone for CodeAlphabet
impl Clone for CodeAlphabet
Source§impl Debug for CodeAlphabet
impl Debug for CodeAlphabet
Source§impl Describe for CodeAlphabet
impl Describe for CodeAlphabet
impl Eq for CodeAlphabet
impl Fields for CodeAlphabet
Source§impl Inspect for CodeAlphabet
impl Inspect for CodeAlphabet
Source§impl PartialEq for CodeAlphabet
impl PartialEq for CodeAlphabet
impl StructuralPartialEq for CodeAlphabet
Auto Trait Implementations§
impl Freeze for CodeAlphabet
impl RefUnwindSafe for CodeAlphabet
impl Send for CodeAlphabet
impl Sync for CodeAlphabet
impl Unpin for CodeAlphabet
impl UnsafeUnpin for CodeAlphabet
impl UnwindSafe for CodeAlphabet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more