Skip to main content

Format

Enum Format 

Source
#[non_exhaustive]
pub enum Format { Text, Digits, Alphanumeric, Hex, Base64, Paper32, Bip39, }
Expand description

What kind of value a person types.

Each format has one canonical representation, which is what an entry step keeps: the text as typed for a text format, the decoded bytes for an encoding. An encoding is forgiving of the grouping a person types it in, so whitespace is dropped before decoding, except between the words of a bip39 phrase, where it separates them.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Text

Anything the person can type.

§

Digits

0 to 9.

§

Alphanumeric

ASCII letters and digits.

§

Hex

Bytes as hexadecimal, in either case, two digits per byte.

§

Base64

Bytes as standard base64 with padding, as openssl base64 writes it.

§

Paper32

Bytes as paper32 rows, as reveal shows them and a sheet holds them; typed a row at a time, a wrong character in a row corrected. See crate::paper32.

§

Bip39

A BIP-39 recovery phrase in the English list, typed a word at a time; the value is the entropy it encodes, and a length counts words. See crate::bip39.

Implementations§

Source§

impl Format

Source

pub fn is_encoding(self) -> bool

Whether the value stands for bytes, which is what the step then keeps.

Source

pub fn rows(self) -> Option<RevealFormat>

The encoding a value in this format is typed in a row at a time, from a sheet or a device’s screen; None for a value typed on one line. Such a value is a secret, and only enter_secret takes it.

Source

pub fn length_of(self, bytes: usize) -> usize

A decoded value of bytes bytes in the format’s unit: the words of a phrase for bip39, the bytes for another encoding.

Source

pub fn decode(self, value: &str) -> Result<Vec<u8>, String>

Decode a typed value of an encoding.

§Errors

Returns why the value is not this encoding, or that the format is not one, worded for the person who typed it and naming nothing of what they typed.

Source

pub fn describe(self) -> &'static str

The unit a length counts, as a person reads it in a hint.

Source

pub fn placeholder(self, length: usize) -> Option<String>

A stand-in of length units that satisfies the format, for a run with no one at the keyboard. Never a real value.

None above PLACEHOLDER_LIMIT: a length a ceremony declares is not bounded, and a stand-in that size would be allocated for nothing. The caller then declines to answer rather than answering with something the rule refuses, which would be asked again without end.

Trait Implementations§

Source§

impl Clone for Format

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Format

Source§

impl Debug for Format

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Format

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Format

Source§

impl FromStr for Format

Source§

type Err = String

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for Format

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Format

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Format

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.