Skip to main content

Params

Struct Params 

Source
pub struct Params {
    pub kind: Kind,
    pub algorithm: Algorithm,
    pub digits: u32,
    pub period: u64,
    pub counter: u64,
}
Expand description

The three numbers a stored seed is generated under.

Defaults are what an otpauth:// URI means when it omits the parameter, and therefore what an entry that stores only a bare base32 seed means too.

Fields§

§kind: Kind

Time-based, counter-based or Steam. #[serde(default)] because every entry written before Phase 22.2 has no such field and means Totp.

§algorithm: Algorithm§digits: u32§period: u64§counter: u64

The next counter value an Hotp seed will use. Meaningless for the other two kinds, and zero for them.

It is state, not configuration — the only number in this struct that a correct implementation writes back — which is why advancing it is an explicit action rather than a side effect of reading a code. See advance in unv-cli/src/totp_cmd.rs.

Implementations§

Source§

impl Params

Source

pub fn from_fields( kind: Option<&str>, algorithm: Option<&str>, digits: Option<u64>, period: Option<u64>, counter: Option<u64>, ) -> Self

The parameters an entry’s four stored fields mean, with anything unusable falling back to the otpauth:// default.

This is the only place a vault’s TOTP fields become Params. They were read three separate ways before — unv totp code clamped, unv totp ls did not, and the IPC command did neither — so one entry carrying totp_digits: 99 listed as a 99-digit credential, produced six digits when asked for a code, and returned an error rather than a code to any caller of entry_totp_code that had not clamped first. Three readings of one field is three answers.

A vault is untrusted input (invariant 4): these fields arrive from an imported backup or a remote server as readily as from this CLI, and the unions are not enforced at rest. Falling back rather than refusing is what an omitted otpauth:// parameter already means, and it keeps a single mistyped number from making the whole entry unreadable.

The twin is totpParamsOf in src/ts/totp.ts — the form needs these before anything is saved — and the two are pinned by the params section of tests/fixtures/parity/totp-seeds.json.

Source

pub fn validate(&self) -> Result<(), String>

Refuses a combination that cannot produce a code, naming the field.

Called at every boundary a number can enter through — the URI parser, the CLI flags, the IPC command — rather than at the generator, so that a period of zero is a message about the value the user typed instead of a division by zero three frames deeper.

Source

pub fn is_default(&self) -> bool

True when these are the values an otpauth:// URI may omit.

Used to keep the stored entry honest: writing algorithm: "SHA1" onto every entry would make the field look chosen when it was defaulted, and the UI would then have to distinguish “the issuer said SHA-1” from “we wrote SHA-1 because nobody said anything”. They are the same thing, so the field is simply absent.

Trait Implementations§

Source§

impl Clone for Params

Source§

fn clone(&self) -> Params

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 Params

Source§

impl Debug for Params

Source§

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

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

impl Default for Params

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Params

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 Params

Source§

impl PartialEq for Params

Source§

fn eq(&self, other: &Params) -> 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 Params

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 Params

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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>,

§

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

§

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

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

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

§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more