[−][src]Struct totp_rs::TOTP
TOTP holds informations as to how to generate an auth code and validate it. Its secret field is sensitive data, treat it accordingly
Fields
algorithm: Algorithm
SHA-1 is the most widespread algorithm used, and for totp pursposes, SHA-1 hash collisions are not a problem as HMAC-SHA-1 is not impacted. It's also the main one cited in rfc-6238 even though the reference implementation permits the use of SHA-1, SHA-256 and SHA-512. Not all clients support other algorithms then SHA-1
digits: usize
The number of digits composing the auth code. Per rfc-4226, this can oscilate between 6 and 8 digits
skew: u8
Number of steps allowed as network delay. 1 would mean one step before current step and one step after are valids. The recommended value per rfc-6238 is 1. Anything more is sketchy, and anyone recommending more is, by definition, ugly and stupid
step: u64
Duration in seconds of a step. The recommended value per rfc-6238 is 30 seconds
secret: T
As per rfc-4226 the secret should come from a strong source, most likely a CSPRNG. It should be at least 128 bits, but 160 are recommended
Implementations
impl<T: AsRef<[u8]>> TOTP<T>
[src]
pub fn new(
algorithm: Algorithm,
digits: usize,
skew: u8,
step: u64,
secret: T
) -> TOTP<T>
[src]
algorithm: Algorithm,
digits: usize,
skew: u8,
step: u64,
secret: T
) -> TOTP<T>
Will create a new instance of TOTP with given parameters. See the doc for reference as to how to choose those values
pub fn sign(&self, time: u64) -> Vec<u8>
[src]
Will sign the given timestamp
pub fn generate(&self, time: u64) -> String
[src]
Will generate a token according to the provided timestamp in seconds
pub fn check(&self, token: &str, time: u64) -> bool
[src]
Will check if token is valid by current time, accounting skew
pub fn get_secret_base32(&self) -> String
[src]
Will return the base32 representation of the secret, which might be useful when users want to manually add the secret to their authenticator
pub fn get_url(&self, label: &str, issuer: &str) -> String
[src]
Will generate a standard URL used to automatically add TOTP auths. Usually used with qr codes
pub fn get_qr(
&self,
label: &str,
issuer: &str
) -> Result<String, Box<dyn Error>>
[src]
&self,
label: &str,
issuer: &str
) -> Result<String, Box<dyn Error>>
Will return a qrcode to automatically add a TOTP as a base64 string. Needs feature qr
to be enabled!
Errors
This will return an error in case the URL gets too long to encode into a QR code
It will also return an error in case it can't encode the qr into a png. This shouldn't happen unless either the qrcode library returns malformed data, or the image library doesn't encode the data correctly
Trait Implementations
impl<T: Clone> Clone for TOTP<T>
[src]
impl<T: Debug> Debug for TOTP<T>
[src]
impl<'de, T> Deserialize<'de> for TOTP<T> where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<T> Serialize for TOTP<T> where
T: Serialize,
[src]
T: Serialize,
Auto Trait Implementations
impl<T> RefUnwindSafe for TOTP<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for TOTP<T> where
T: Send,
T: Send,
impl<T> Sync for TOTP<T> where
T: Sync,
T: Sync,
impl<T> Unpin for TOTP<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for TOTP<T> where
T: UnwindSafe,
T: 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,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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>,