View Source ExOtp.Behaviour behaviour (ExOtp v0.0.1)

This module implements the behaviour OTP classes.

Link to this section Summary

Callbacks

Function to generate the OTP for the given timestamp value, and an optional integer value whic could be the interval(for Totp) or counter(for Hotp).

This function accepts an integer and secret, and returns either a TOTP or HOTP struct

Function to generate the URI which can be used to generate QR codes, which can be read by 2FA apps such as Google Authenticator.

Function to check if the input otp is valid for the given algorithm(Totp or Hotp) and the timestamp. Returns true if the otp is valid and false otherwise.

Function to validate the attributes of the input struct, which can be either a Totp or Hotp object. Returns the struct if all attributes are valid and raises an error otherwise.

Link to this section Callbacks

@callback at(ExOtp.Totp.t() | ExOtp.Hotp.t(), integer()) :: String.t()

Function to generate the OTP for the given timestamp value, and an optional integer value whic could be the interval(for Totp) or counter(for Hotp).

@callback new(integer(), String.t()) :: ExOtp.Hotp.t() | ExOtp.Totp.t()

This function accepts an integer and secret, and returns either a TOTP or HOTP struct

Link to this callback

provision_uri(arg1, t, keyword)

View Source
@callback provision_uri(ExOtp.Totp.t() | ExOtp.Hotp.t(), String.t(), keyword()) ::
  String.t()

Function to generate the URI which can be used to generate QR codes, which can be read by 2FA apps such as Google Authenticator.

@callback valid?(ExOtp.Totp.t() | ExOtp.Hotp.t(), String.t(), DateTime.t()) :: boolean()

Function to check if the input otp is valid for the given algorithm(Totp or Hotp) and the timestamp. Returns true if the otp is valid and false otherwise.

@callback validate(ExOtp.Totp.t() | ExOtp.Hotp.t()) ::
  no_return() | ExOtp.Totp.t() | ExOtp.Hotp.t()

Function to validate the attributes of the input struct, which can be either a Totp or Hotp object. Returns the struct if all attributes are valid and raises an error otherwise.