# Path: oath_toolkit/_compat.py
# def bytify(chunk):
# 
# Path: oath_toolkit/exc.py
# class OATHError(Exception):
# 
#     """Generic error class."""
# 
# Path: oath_toolkit/types.py



from ._compat import integer_types, to_bytes
from .exc import OATHError
from .types import OTPPosition
from cffi import FFI
import atexit
import os
    return _ffi.string(generated, digits)


def totp_validate(secret, now, time_step_size, start_offset, window, otp):
    """
    Validate a one-time password generated using the TOTP algorithm
    (:rfc:`6238`).

    :param bytes secret: The secret used to generate the one-time password.
    :param int now: The UNIX timestamp (usually the current one)
    :param int time_step_size: Unsigned, the time step system parameter. If
                               set to a negative value, defaults to ``30``.
    :param int start_offset: The UNIX timestamp of when to start counting time
                             steps (usually should be ``0``).
    :param int window: The number of OTPs before and after the start OTP
                       to test.
    :param bytes otp: The one-time password to validate.
    :return: The absolute and relative positions in the OTP window, where ``0``
             is the first position.
    :rtype: :class:`oath_toolkit.types.OTPPosition`
    :raise: :class:`OATHError` if invalid
    """
    if time_step_size < 0:
        time_step_size = 30  # c.OATH_TOTP_DEFAULT_TIME_STEP_SIZE
    addr_otp_pos = _ffi.new('int *')
    if not isinstance(now, integer_types):
        now = int(now)
    retval = c.oath_totp_validate2(secret, len(secret), now, time_step_size,
                                   start_offset, window, addr_otp_pos, otp)
    _handle_retval(retval, True)

# Path: oath_toolkit/_compat.py
# def bytify(chunk):
# 
# Path: oath_toolkit/exc.py
# class OATHError(Exception):
# 
#     """Generic error class."""
# 
# Path: oath_toolkit/types.py



# Path: oath_toolkit/impl_cffi.py
from ._compat import integer_types, to_bytes
from .exc import OATHError
from .types import OTPPosition
from cffi import FFI
import atexit
import os

    return _ffi.string(generated, digits)


def totp_validate(secret, now, time_step_size, start_offset, window, otp):
    """
    Validate a one-time password generated using the TOTP algorithm
    (:rfc:`6238`).

    :param bytes secret: The secret used to generate the one-time password.
    :param int now: The UNIX timestamp (usually the current one)
    :param int time_step_size: Unsigned, the time step system parameter. If
                               set to a negative value, defaults to ``30``.
    :param int start_offset: The UNIX timestamp of when to start counting time
                             steps (usually should be ``0``).
    :param int window: The number of OTPs before and after the start OTP
                       to test.
    :param bytes otp: The one-time password to validate.
    :return: The absolute and relative positions in the OTP window, where ``0``
             is the first position.
    :rtype: :class:`oath_toolkit.types.OTPPosition`
    :raise: :class:`OATHError` if invalid
    """
    if time_step_size < 0:
        time_step_size = 30  # c.OATH_TOTP_DEFAULT_TIME_STEP_SIZE
    addr_otp_pos = _ffi.new('int *')
    if not isinstance(now, integer_types):
        now = int(now)
    retval = c.oath_totp_validate2(secret, len(secret), now, time_step_size,
                                   start_offset, window, addr_otp_pos, otp)
    _handle_retval(retval, True)

    return OTPPosition(absolute=retval, relative=addr_otp_pos[0])