pub struct Secret(/* private fields */);Implementations§
Source§impl Secret
impl Secret
Sourcepub fn from_base32(encoded: &str, digest: Digest) -> Result<Self>
pub fn from_base32(encoded: &str, digest: Digest) -> Result<Self>
Decode the secret from a base 32 representation.
Note: The secret is later used as an HMAC key.
It is a property of HMAC that a key that is longer than the digest block size is first shortened by applying the digest. For SHA-1 and SHA-2, the block size is 64 bytes (512 bits).
Therefore, applying the shortening in this implementation has no effect on the calculated OTP, but it does make communication with the OATH authenticator more efficient for oversized secrets.
Note: The secret is always padded to at least 14 bytes with zero bytes,
following ykman. This is a bit strange (?), as RFC 4226, section 4 says
“The algorithm MUST use a strong shared secret. The length of the shared secret MUST be least 128 bits. This document RECOMMENDs a shared secret length of 160 bits.”
But 14B = 112b < 128b.