one-time-password-3.0.0.0: HMAC-Based and Time-Based One-Time Passwords
Safe HaskellSafe-Inferred
LanguageGHC2021

OTP.Commons

Contents

Synopsis

Auxiliary

data OTP Source #

Since: 3.0.0.0

Constructors

OTP 

Fields

Instances

Instances details
Show OTP Source #

Since: 3.0.0.0

Instance details

Defined in OTP.Commons

Methods

showsPrec :: Int -> OTP -> ShowS #

show :: OTP -> String #

showList :: [OTP] -> ShowS #

Eq OTP Source #

Since: 3.0.0.0

Instance details

Defined in OTP.Commons

Methods

(==) :: OTP -> OTP -> Bool #

(/=) :: OTP -> OTP -> Bool #

Ord OTP Source #

Since: 3.0.0.0

Instance details

Defined in OTP.Commons

Methods

compare :: OTP -> OTP -> Ordering #

(<) :: OTP -> OTP -> Bool #

(<=) :: OTP -> OTP -> Bool #

(>) :: OTP -> OTP -> Bool #

(>=) :: OTP -> OTP -> Bool #

max :: OTP -> OTP -> OTP #

min :: OTP -> OTP -> OTP #

Display OTP Source #

Since: 3.0.0.0

Instance details

Defined in OTP.Commons

data Digits Source #

Since: 3.0.0.0

Instances

Instances details
Show Digits Source # 
Instance details

Defined in OTP.Commons

Eq Digits Source # 
Instance details

Defined in OTP.Commons

Methods

(==) :: Digits -> Digits -> Bool #

(/=) :: Digits -> Digits -> Bool #

Ord Digits Source # 
Instance details

Defined in OTP.Commons

Display Digits Source # 
Instance details

Defined in OTP.Commons

data Algorithm Source #

Since: 3.0.0.0

Instances

Instances details
Show Algorithm Source #

Since: 3.0.0.0

Instance details

Defined in OTP.Commons

Eq Algorithm Source #

Since: 3.0.0.0

Instance details

Defined in OTP.Commons

Ord Algorithm Source #

Since: 3.0.0.0

Instance details

Defined in OTP.Commons

Display Algorithm Source #

Since: 3.0.0.0

Instance details

Defined in OTP.Commons

mkDigits :: Word32 -> Maybe Digits Source #

RFC 4226 §5.3 says "Implementations MUST extract a 6-digit code at a minimum and possibly 7 and 8-digit code".

This function validates that the number of desired digits is equal or greater than 6.

totpCounter Source #

Arguments

:: Time

Time of totp

-> Timespan

Time range in seconds

-> Word64

Resulting counter

Calculate HOTP counter using time. Starting time (T0 according to RFC6238) is 0 (begining of UNIX epoch) >>> let timestamp = decode "2010-10-10 00:00:30" >>> let timespan = Torsor.scale 30 Chronos.second >>> totpCounter timestamp timespan 42888961

>>> let timestamp2 = decode "2010-10-10 00:00:45"
>>> totpCounter timestamp2 timespan
42888961
>>> let timestamp3 = decode "2010-10-10 00:01:00"
>>> totpCounter timestamp3 timespan
42888962

Since: 3.0.0.0

counterRange Source #

Arguments

:: (Word64, Word64)

Number of counters before and after ideal

-> Word64

Ideal counter value

-> [Word64] 

Make a sequence of acceptable counters, protected from arithmetic overflow. Maximum range is limited to 1000 due to huge counter ranges being insecure.

>>> counterRange (0, 0) 9000
[9000]
>>> counterRange (1, 0) 9000
[8999,9000]
>>> length $ counterRange (5000, 0) 9000
501
>>> length $ counterRange (5000, 5000) 9000
1000
>>> counterRange (2, 2) maxBound
[18446744073709551613,18446744073709551614,18446744073709551615]
>>> counterRange (2, 2) minBound
[0,1,2]
>>> counterRange (2, 2) (maxBound `div` 2)
[9223372036854775805,9223372036854775806,9223372036854775807,9223372036854775808,9223372036854775809]
>>> counterRange (5, 5) 9000
[8995,8996,8997,8998,8999,9000,9001,9002,9003,9004,9005]

RFC recommends avoiding excessively large values for counter ranges.

Since: 3.0.0.0

totpCounterRange :: (Word64, Word64) -> Time -> Timespan -> [Word64] Source #

Make a sequence of acceptable periods.

>>> let time = decode "2010-10-10 00:00:30"
>>> let timespan = Torsor.scale 30 Chronos.second
>>> totpCounterRange (1, 1) time timespan
[42888960,42888961,42888962]

Since: 3.0.0.0