# 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
    output = _ffi.new('char **')
    output_len = _ffi.new('size_t *')
    _handle_retval(c.oath_base32_decode(to_bytes(data), len(data), output,
                                        output_len))
    return _ffi.string(output[0], output_len[0])


def hotp_generate(secret, moving_factor, digits, add_checksum=False,
                  truncation_offset=None):
    """
    Generate a one-time password using the HOTP algorithm (:rfc:`4226`).

    :param bytes secret: The secret string used to generate the one-time
                         password.
    :param int moving_factor: unsigned, can be :func:`long`, in theory. A
                              counter indicating where in OTP stream to
                              generate an OTP.
    :param int digits: unsigned, the number of digits of the one-time
                       password.
    :param bool add_checksum: Whether to add a checksum digit (depending on the
                              version of ``liboath`` used, this may be
                              ignored).
    :param int truncation_offset: A truncation offset to use, if not set to a
                                  negative value (which means ``2^32 - 1``).
    :return: one-time password
    :rtype: :func:`bytes`
    """
    if truncation_offset < 0:
        truncation_offset = (2 ** 32) - 1
    generated = _ffi.new('char *')

# 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

    output = _ffi.new('char **')
    output_len = _ffi.new('size_t *')
    _handle_retval(c.oath_base32_decode(to_bytes(data), len(data), output,
                                        output_len))
    return _ffi.string(output[0], output_len[0])


def hotp_generate(secret, moving_factor, digits, add_checksum=False,
                  truncation_offset=None):
    """
    Generate a one-time password using the HOTP algorithm (:rfc:`4226`).

    :param bytes secret: The secret string used to generate the one-time
                         password.
    :param int moving_factor: unsigned, can be :func:`long`, in theory. A
                              counter indicating where in OTP stream to
                              generate an OTP.
    :param int digits: unsigned, the number of digits of the one-time
                       password.
    :param bool add_checksum: Whether to add a checksum digit (depending on the
                              version of ``liboath`` used, this may be
                              ignored).
    :param int truncation_offset: A truncation offset to use, if not set to a
                                  negative value (which means ``2^32 - 1``).
    :return: one-time password
    :rtype: :func:`bytes`
    """
    if truncation_offset < 0:
        truncation_offset = (2 ** 32) - 1
    generated = _ffi.new('char *')

    secret = to_bytes(secret)