Copyright | (c) Justin Le 2017 |
---|---|
License | MIT |
Maintainer | justin@jle.im |
Stability | unstable |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Types for storing, serializing, accessing OTP keys. Gratuitous type-level programming here for no reason because I have issues.
Based off of https://github.com/google/google-authenticator.
- data Mode
- data family Sing k (a :: k) :: *
- type SMode = (Sing :: Mode -> Type)
- type HOTPSym0 = HOTP
- type TOTPSym0 = TOTP
- data HashAlgo
- parseAlgo :: String -> Maybe HashAlgo
- data Secret :: Mode -> Type where
- data family ModeState :: Mode -> Type
- type SomeSecretState = DSum SMode (Secret :&: ModeState)
- data Vault = Vault {
- vaultList :: [SomeSecretState]
- _Vault :: Functor f => ([SomeSecretState] -> f [SomeSecretState]) -> Vault -> f Vault
- hotp :: Secret HOTP -> ModeState HOTP -> (Text, ModeState HOTP)
- totp :: Secret TOTP -> IO Text
- totp_ :: Secret TOTP -> UTCTime -> Text
- otp :: forall m. SingI m => Secret m -> ModeState m -> IO (Text, ModeState m)
- someSecret :: Functor f => (forall m. SingI m => Secret m -> ModeState m -> f (ModeState m)) -> SomeSecretState -> f SomeSecretState
- vaultSecrets :: Applicative f => (forall m. SingI m => Secret m -> ModeState m -> f (ModeState m)) -> Vault -> f Vault
- describeSecret :: Secret m -> Text
- secretURI :: Parser SomeSecretState
- parseSecretURI :: String -> Either String SomeSecretState
Documentation
OTP generation mode
data family Sing k (a :: k) :: * #
The singleton kind-indexed data family.
ToJSON SomeSecretState # | |
Binary SomeSecretState # | |
data Sing Bool | |
data Sing Ordering | |
data Sing Nat | |
data Sing Symbol | |
data Sing () | |
data Sing Mode # | |
data Sing [a0] | |
data Sing (Maybe a0) | |
data Sing (NonEmpty a0) | |
data Sing (Either a0 b0) | |
data Sing (a0, b0) | |
data Sing ((~>) k1 k2) | |
data Sing (a0, b0, c0) | |
data Sing (a0, b0, c0, d0) | |
data Sing (a0, b0, c0, d0, e0) | |
data Sing (a0, b0, c0, d0, e0, f0) | |
data Sing (a0, b0, c0, d0, e0, f0, g0) | |
Which OTP-approved hash algorithm to use?
parseAlgo :: String -> Maybe HashAlgo Source #
Parse a hash algorithm string into the appropriate HashAlgo
.
data Secret :: Mode -> Type where Source #
A standards-compliant secret key type. Well, almost. It doesn't include configuration for the time period if it's time-based.
data family ModeState :: Mode -> Type Source #
A data family consisting of the state required by each mode.
ToJSON SomeSecretState Source # | |
Binary SomeSecretState Source # | |
Show (ModeState HOTP) Source # | |
Show (ModeState TOTP) Source # | |
Generic (ModeState HOTP) Source # | |
Generic (ModeState TOTP) Source # | |
ToJSON (ModeState HOTP) Source # | |
ToJSON (ModeState TOTP) Source # | |
Binary (ModeState HOTP) Source # | |
Binary (ModeState TOTP) Source # | |
data ModeState HOTP Source # | For |
data ModeState TOTP Source # | For |
type Rep (ModeState HOTP) Source # | |
type Rep (ModeState TOTP) Source # | |
A list of secrets and their states, of various modes.
_Vault :: Functor f => ([SomeSecretState] -> f [SomeSecretState]) -> Vault -> f Vault Source #
A lens into the list of SomeSecretState
s in a Vault
. Should be an
Iso but we don't want a lens dependency now, do we.
hotp :: Secret HOTP -> ModeState HOTP -> (Text, ModeState HOTP) Source #
Generate an HTOP (counter-based) code, returning a modified state.
totp :: Secret TOTP -> IO Text Source #
Generate a TOTP (time-based) code in IO for the current time.
totp_ :: Secret TOTP -> UTCTime -> Text Source #
(Purely) generate a TOTP (time-based) code, for a given time.
someSecret :: Functor f => (forall m. SingI m => Secret m -> ModeState m -> f (ModeState m)) -> SomeSecretState -> f SomeSecretState Source #
Some sort of RankN lens and traversal over a SomeSecret
. Allows you
to traverse (effectfully map) over the ModeState
in
a SomeSecretState
, with access to the Secret
as well.
With this you can implement getters and setters. It's also used by the
library to update the ModeState
in IO.
vaultSecrets :: Applicative f => (forall m. SingI m => Secret m -> ModeState m -> f (ModeState m)) -> Vault -> f Vault Source #
describeSecret :: Secret m -> Text Source #
Print out the metadata (account name and issuer) of a Secret
.
secretURI :: Parser SomeSecretState Source #
A parser for a otpauth URI.
parseSecretURI :: String -> Either String SomeSecretState Source #
Parse a valid otpauth URI and initialize its state.
See https://github.com/google/google-authenticator/wiki/Key-Uri-Format