[−][src]Struct miniotp::TOTP
A time-based one-time passcode implementation
Methods
impl<A: Array> TOTP<A>
[src]
pub fn base32_secret(&self) -> String
[src]
Returns the base32 encoded equivalent of the internal secret.
use miniotp::TOTP; let totp = TOTP::new(b"\0\x01\x02\x03\x04"); let b32 = totp.base32_secret(); assert_eq!(b32, "AAAQEAYE");
pub fn base32_segs(&self, chunk: usize) -> Segs
[src]
Returns an iterator over a the encoded secret of a string of chunk
size.
pub fn to_uri<S: AsRef<str>>(&self, label: S, issuer: S) -> String
[src]
Generates a URI for this TOTP authenticator, given a label and issuer.
impl TOTP<Vec<u8>>
[src]
pub fn from_base32<S: AsRef<str>>(s: S) -> Result<Self, Error>
[src]
Method to take a base32 string and use it as an inital vector.
use miniotp::{TOTP}; let otp = TOTP::from_base32("AAAAAAAA")?.generate(3);
pub fn from_base32c<C: AsRef<CStr>>(s: C) -> Result<Self, Error>
[src]
Method to take a base32 cstr and use it as an inital vector.
use miniotp::TOTP; use std::ffi::CString; let cs = CString::new("AAAAAAAA").expect("cstr"); let otp = TOTP::from_base32c(cs)?.generate(3);
pub fn from_base32b<'a, I: IntoIterator<Item = &'a u8>>(
iter: I
) -> Result<Self, Error>
[src]
iter: I
) -> Result<Self, Error>
Method to take a base32 cstr-like and use it as an inital vector.
use miniotp::TOTP; let otp = TOTP::from_base32b(b"AAAAAAAA\0")?.generate(3);
impl<A: Array> TOTP<A>
[src]
pub fn new(a: A) -> Self
[src]
Creates a new TOTP algorithm verifier.
use miniotp::TOTP; let totp = TOTP::new(b"secret A"); let totp_other = TOTP::new(b"secret B");
pub fn verify_range_default(self, time: u64, input: u32) -> bool
[src]
Verifies a TOTP range from -1 to +1.
This function consumes self
.
pub fn generate(&self, time: u64) -> u32
[src]
Generates a HOTP value.
use miniotp::{TOTP}; let totp = TOTP::new(b"12345678901234567890"); let gauthkey = totp.generate(30); assert_eq!(gauthkey, 287_082);
pub fn verify(&self, time: u64, input: u32) -> bool
[src]
Verifies a TOTP value.
use miniotp::{TOTP}; let totp = TOTP::new(b"12345678901234567890"); let otp = totp.verify(349495 * 30, 000_000); assert_eq!(otp, true);
pub fn verify_range<I>(self, time: u64, input: u32, diffs: I) -> bool where
I: IntoIterator<Item = i64>,
[src]
I: IntoIterator<Item = i64>,
Verifies a TOTP time range.
This function consumes self
.
impl<A: Array> TOTP<A>
[src]
pub fn verify_range_default_now(self, input: u32) -> bool
[src]
Verifies a TOTP range at the current time with a range of -1..=+1 period.
This function consumes self
.
use miniotp::TOTP; let totp = TOTP::new(b"AAAAAAAA").verify_range_default_now(123);
Panics
This function will panic if system time is less than the unix epoch.
pub fn generate_now(&self) -> u32
[src]
Generates a TOTP value at the current time.
Panics
This function will panic if system time is less than the unix epoch.
impl<A: Array> TOTP<A>
[src]
pub fn set_alg(self, alg: Algorithm) -> Self
[src]
Sets the algorithm.
This functions the same as HOTP::set_alg
;
see its documentation for more.
pub fn set_len(self, len: u8) -> Self
[src]
Sets the output length.
This functions the same as HOTP::set_len
;
see its documentation for more.
pub fn set_period(self, period: u64) -> Self
[src]
Sets the period, in seconds.
use miniotp::TOTP; // use a 53 second period for fairly unaligned intervals let otp = TOTP::new(b"secret") .set_period(53) .generate(3);
pub fn set_epoch(self, epoch: u64) -> Self
[src]
Sets the epoch, in seconds.
use miniotp::TOTP; // use 2000-01-01T00:00:00Z as your epoch let otp = TOTP::new(b"secret") .set_epoch(946_684_800) .generate(1_577_836_800);
Panics
This function can cause a panic if generate
or generate_now
is given a time before the
epoch.
impl<A: Array> TOTP<A>
[src]
pub fn generate_str(&self, time: u64) -> String
[src]
Generates the value as a string.
use miniotp::TOTP; let s = TOTP::new(b"12345678901234567890").generate_str(59); assert_eq!(s, "287082");
Trait Implementations
impl<A: Clone> Clone for TOTP<A> where
A: Array,
[src]
A: Array,
impl<A: Debug> Debug for TOTP<A> where
A: Array,
[src]
A: Array,
impl<A: Array> From<HOTP<A>> for TOTP<A>
[src]
impl<A: PartialEq> PartialEq<TOTP<A>> for TOTP<A> where
A: Array,
[src]
A: Array,
impl<A> StructuralPartialEq for TOTP<A> where
A: Array,
[src]
A: Array,
Auto Trait Implementations
impl<A> RefUnwindSafe for TOTP<A> where
A: RefUnwindSafe,
A: RefUnwindSafe,
impl<A> Send for TOTP<A> where
A: Send,
A: Send,
impl<A> Sync for TOTP<A> where
A: Sync,
A: Sync,
impl<A> Unpin for TOTP<A> where
A: Unpin,
A: Unpin,
impl<A> UnwindSafe for TOTP<A> where
A: UnwindSafe,
A: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,