Struct miniotp::HOTP[][src]

pub struct HOTP<A> where
    A: Array
{ /* fields omitted */ }

A counter-based one-time passcode implementation

Implementations

impl<A: Array> HOTP<A>[src]

pub fn base32_secret(&self) -> String[src]

Returns the base32 encoded equivalent of the internal secret.

use miniotp::HOTP;
let sec_human = HOTP::new(b"HUMAN").base32_secret();
assert_eq!(sec_human, "JBKU2QKO");

pub fn base32_segs(&self, chunk_size: usize) -> Segs

Notable traits for Segs

impl Iterator for Segs type Item = String;
[src]

Returns an iterator over base32 segments of chunk size.

pub fn to_uri<S: AsRef<str>>(&self, label: S, issuer: S, counter: u64) -> String[src]

Generates a URI for this HOTP authenticator, given a label and issuer.

impl HOTP<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::HOTP;
let otp = HOTP::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::HOTP;
use std::ffi::CString;
let cs = CString::new("AAAAAAAA").expect("cstr");
let otp = HOTP::from_base32c(cs)?.generate(3);

pub fn from_base32b<'a, I: IntoIterator<Item = &'a u8>>(
    i: I
) -> Result<Self, Error>
[src]

Method to take a base32 cstr-like and use it as an inital vector.

use miniotp::HOTP;
let otp = HOTP::from_base32b(b"AAAAAAAA\0")?.generate(3);

impl<A: Array> HOTP<A>[src]

pub fn new(sec: A) -> Self[src]

Creates a new HOTP algorithm verifier.

use miniotp::HOTP;
let hotp = HOTP::new(b"secret A");
let hotp_other = HOTP::new(b"secret B");

pub fn verify_range_default(self, counter: u64, input: u32) -> bool[src]

Verifies a HOTP counter range from -1 to +1.

This function consumes self.

pub fn generate(&self, counter: u64) -> u32[src]

Generates a HOTP value.

use miniotp::{HOTP};
let hotp = HOTP::new(b"12345678901234567890");
let otp = hotp.generate(1);
assert_eq!(otp, 287_082);

pub fn verify(&self, counter: u64, input: u32) -> bool[src]

Verifies a HOTP value.

use miniotp::{HOTP};
let hotp = HOTP::new(b"12345678901234567890");
let otp = hotp.verify(349495, 000_000);
assert_eq!(otp, true);

pub fn verify_range<I>(self, counter: u64, input: u32, diffs: I) -> bool where
    I: IntoIterator<Item = i64>, 
[src]

Verifies a HOTP counter range.

This function consumes self.

impl<A: Array> HOTP<A>[src]

pub fn set_alg(self, alg: Algorithm) -> Self[src]

Sets the algorithm.

use miniotp::{HOTP, SHA1, SHA256, SHA512};
let hotp_default = HOTP::new(b"secret");
let hotp_sha1 = HOTP::new(b"secret").set_alg(SHA1);
let hotp_sha256 = HOTP::new(b"secret").set_alg(SHA256);
let hotp_sha512 = HOTP::new(b"secret").set_alg(SHA512);

pub fn set_len(self, len: u8) -> Self[src]

Sets the output length.

use miniotp::{HOTP};
let hotp_default = HOTP::new(b"secret");
let hotp_len_6 = HOTP::new(b"secret").set_len(6);
let hotp_len_7 = HOTP::new(b"secret").set_len(7);
let hotp_len_8 = HOTP::new(b"secret").set_len(8);

impl<A: Array> HOTP<A>[src]

pub fn generate_str(&self, counter: u64) -> String[src]

Generates the value as a string.

use miniotp::HOTP;
let s = HOTP::new(b"12345678901234567890").generate_str(349495);
assert_eq!(s, "000000");

Trait Implementations

impl<A: Clone> Clone for HOTP<A> where
    A: Array
[src]

impl<A: Copy> Copy for HOTP<A> where
    A: Array
[src]

impl<A: Debug> Debug for HOTP<A> where
    A: Array
[src]

impl<'de, A> Deserialize<'de> for HOTP<A> where
    A: Array,
    A: Deserialize<'de>, 
[src]

impl<A: Array> From<HOTP<A>> for TOTP<A>[src]

impl<A> Serialize for HOTP<A> where
    A: Array,
    A: Serialize
[src]

Auto Trait Implementations

impl<A> RefUnwindSafe for HOTP<A> where
    A: RefUnwindSafe

impl<A> Send for HOTP<A> where
    A: Send

impl<A> Sync for HOTP<A> where
    A: Sync

impl<A> Unpin for HOTP<A> where
    A: Unpin

impl<A> UnwindSafe for HOTP<A> where
    A: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.