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: KindTime-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: u64The 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
impl Params
Sourcepub fn from_fields(
kind: Option<&str>,
algorithm: Option<&str>,
digits: Option<u64>,
period: Option<u64>,
counter: Option<u64>,
) -> Self
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.
Sourcepub fn validate(&self) -> Result<(), String>
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.
Sourcepub fn is_default(&self) -> bool
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§
impl Copy for Params
Source§impl<'de> Deserialize<'de> for Params
impl<'de> Deserialize<'de> for Params
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Params
impl StructuralPartialEq for Params
Auto Trait Implementations§
impl Freeze for Params
impl RefUnwindSafe for Params
impl Send for Params
impl Sync for Params
impl Unpin for Params
impl UnsafeUnpin for Params
impl UnwindSafe for Params
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.