# Path: knox/crypto.py
# def create_token_string():
# def hash_token(token):
# 
# Path: knox/settings.py
# USER_SETTINGS = getattr(settings, 'REST_KNOX', None)
# DEFAULTS = {
#     'SECURE_HASH_ALGORITHM': 'cryptography.hazmat.primitives.hashes.SHA512',
#     'AUTH_TOKEN_CHARACTER_LENGTH': 64,
#     'TOKEN_TTL': timedelta(hours=10),
#     'USER_SERIALIZER': None,
#     'TOKEN_LIMIT_PER_USER': None,
#     'AUTO_REFRESH': False,
#     'MIN_REFRESH_INTERVAL': 60,
#     'AUTH_HEADER_PREFIX': 'Token',
#     'EXPIRY_DATETIME_FORMAT': api_settings.DATETIME_FORMAT,
# }
# IMPORT_STRINGS = {
#     'SECURE_HASH_ALGORITHM',
#     'USER_SERIALIZER',
# }
#     TOKEN_KEY_LENGTH = 8
#     DIGEST_LENGTH = 128
# CONSTANTS = CONSTANTS()
# def reload_api_settings(*args, **kwargs):
#     def __setattr__(self, *args, **kwargs):
# class CONSTANTS:


from django.conf import settings
from django.db import models
from django.utils import timezone
from knox import crypto
from knox.settings import CONSTANTS, knox_settings


User = settings.AUTH_USER_MODEL


class AuthTokenManager(models.Manager):
    def create(self, user, expiry=knox_settings.TOKEN_TTL):
        token = crypto.create_token_string()
        digest = crypto.hash_token(token)

        if expiry is not None:
            expiry = timezone.now() + expiry

        instance = super(AuthTokenManager, self).create(
            token_key=token[:CONSTANTS.TOKEN_KEY_LENGTH], digest=digest,
            user=user, expiry=expiry)
        return instance, token


class AuthToken(models.Model):

    objects = AuthTokenManager()

    digest = models.CharField(

# Path: knox/crypto.py
# def create_token_string():
# def hash_token(token):
# 
# Path: knox/settings.py
# USER_SETTINGS = getattr(settings, 'REST_KNOX', None)
# DEFAULTS = {
#     'SECURE_HASH_ALGORITHM': 'cryptography.hazmat.primitives.hashes.SHA512',
#     'AUTH_TOKEN_CHARACTER_LENGTH': 64,
#     'TOKEN_TTL': timedelta(hours=10),
#     'USER_SERIALIZER': None,
#     'TOKEN_LIMIT_PER_USER': None,
#     'AUTO_REFRESH': False,
#     'MIN_REFRESH_INTERVAL': 60,
#     'AUTH_HEADER_PREFIX': 'Token',
#     'EXPIRY_DATETIME_FORMAT': api_settings.DATETIME_FORMAT,
# }
# IMPORT_STRINGS = {
#     'SECURE_HASH_ALGORITHM',
#     'USER_SERIALIZER',
# }
#     TOKEN_KEY_LENGTH = 8
#     DIGEST_LENGTH = 128
# CONSTANTS = CONSTANTS()
# def reload_api_settings(*args, **kwargs):
#     def __setattr__(self, *args, **kwargs):
# class CONSTANTS:


# Path: knox/models.py
from django.conf import settings
from django.db import models
from django.utils import timezone
from knox import crypto
from knox.settings import CONSTANTS, knox_settings



User = settings.AUTH_USER_MODEL


class AuthTokenManager(models.Manager):
    def create(self, user, expiry=knox_settings.TOKEN_TTL):
        token = crypto.create_token_string()
        digest = crypto.hash_token(token)

        if expiry is not None:
            expiry = timezone.now() + expiry

        instance = super(AuthTokenManager, self).create(
            token_key=token[:CONSTANTS.TOKEN_KEY_LENGTH], digest=digest,
            user=user, expiry=expiry)
        return instance, token


class AuthToken(models.Model):

    objects = AuthTokenManager()

    digest = models.CharField(

        max_length=CONSTANTS.DIGEST_LENGTH, primary_key=True)