[][src]Struct boringauth::oath::TOTPBuilder

pub struct TOTPBuilder { /* fields omitted */ }

Examples

The following examples uses the same shared secret passed in various forms.

 let key = vec![49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48];
 let mut totp = boringauth::oath::TOTPBuilder::new()
     .key(&key)
     .finalize()
     .unwrap();
 let key_ascii = "12345678901234567890".to_owned();
 let mut totp = boringauth::oath::TOTPBuilder::new()
     .ascii_key(&key_ascii)
     .period(42)
     .finalize();
 let key_hex = "3132333435363738393031323334353637383930".to_owned();
 let mut totp = boringauth::oath::TOTPBuilder::new()
     .hex_key(&key_hex)
     .timestamp(1234567890)
     .finalize();
 let key_base32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ".to_owned();
 let mut totp = boringauth::oath::TOTPBuilder::new()
     .base32_key(&key_base32)
     .output_len(8)
     .hash_function(boringauth::oath::HashFunction::Sha256)
     .finalize();

Methods

impl TOTPBuilder[src]

pub fn new() -> TOTPBuilder[src]

Generates the base configuration for TOTP code generation.

pub fn key(&mut self, key: &[u8]) -> &mut TOTPBuilder[src]

Sets the shared secret.

pub fn ascii_key(&mut self, key: &str) -> &mut TOTPBuilder[src]

Sets the shared secret. This secret is passed as an ASCII string.

pub fn hex_key(&mut self, key: &str) -> &mut TOTPBuilder[src]

Sets the shared secret. This secret is passed as an hexadecimal encoded string.

pub fn base32_key(&mut self, key: &str) -> &mut TOTPBuilder[src]

Sets the shared secret. This secret is passed as a base32 encoded string.

pub fn output_len(&mut self, output_len: usize) -> &mut TOTPBuilder[src]

Sets the number of characters for the code. The minimum and maximum values depends the base. Default is 6.

pub fn output_base(&mut self, base: &[u8]) -> &mut TOTPBuilder[src]

Sets the base used to represents the output code. Default is "0123456789".to_owned().into_bytes().

pub fn hash_function(&mut self, hash_function: HashFunction) -> &mut TOTPBuilder[src]

Sets the hash function. Default is Sha1.

pub fn timestamp(&mut self, timestamp: i64) -> &mut TOTPBuilder[src]

Sets a custom value for the current Unix time instead of the real one.

pub fn tolerance(&mut self, tolerance: u64) -> &mut TOTPBuilder[src]

Sets the number of periods ahead or behind the current one for which the user code will still be considered valid. You should not set a value higher than 2. Default is 0.

pub fn positive_tolerance(&mut self, tolerance: u64) -> &mut TOTPBuilder[src]

Sets the number of periods ahead the current one for which the user code will still be considered valid. You should not set a value higher than 2. Default is 0.

pub fn negative_tolerance(&mut self, tolerance: u64) -> &mut TOTPBuilder[src]

Sets the number of periods behind the current one for which the user code will still be considered valid. You should not set a value higher than 2. Default is 0.

pub fn period(&mut self, period: u32) -> &mut TOTPBuilder[src]

Sets the time step in seconds (X). May not be zero. Default is 30.

pub fn initial_time(&mut self, initial_time: u64) -> &mut TOTPBuilder[src]

Sets the Unix time to start counting time steps (T0). Default is 0.

pub fn finalize(&self) -> Result<TOTP, ErrorCode>[src]

Returns the finalized TOTP object.

Auto Trait Implementations

Blanket Implementations

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

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

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.

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

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

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

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