Skip to content

Commit

Permalink
feat: add typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Rotzbua committed Dec 17, 2023
1 parent ffd9171 commit 22d787e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions knox/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def authenticate_credentials(self, token):
return self.validate_user(auth_token)
raise exceptions.AuthenticationFailed(msg)

def renew_token(self, auth_token):
def renew_token(self, auth_token) -> None:
current_expiry = auth_token.expiry
new_expiry = timezone.now() + knox_settings.TOKEN_TTL
auth_token.expiry = new_expiry
Expand All @@ -89,7 +89,7 @@ def validate_user(self, auth_token):
def authenticate_header(self, request):
return knox_settings.AUTH_HEADER_PREFIX

def _cleanup_token(self, auth_token):
def _cleanup_token(self, auth_token) -> bool:
for other_token in auth_token.user.auth_token_set.all():
if other_token.digest != auth_token.digest and other_token.expiry:
if other_token.expiry < timezone.now():
Expand Down
4 changes: 2 additions & 2 deletions knox/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
hash_func = knox_settings.SECURE_HASH_ALGORITHM


def create_token_string():
def create_token_string() -> str:
return binascii.hexlify(
generate_bytes(int(knox_settings.AUTH_TOKEN_CHARACTER_LENGTH / 2))
).decode()


def make_hex_compatible(token: str) -> str:
def make_hex_compatible(token: str) -> bytes:
"""
We need to make sure that the token, that is send is hex-compatible.
When a token prefix is used, we cannot guarantee that.
Expand Down
2 changes: 1 addition & 1 deletion knox/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AbstractAuthToken(models.Model):
class Meta:
abstract = True

def __str__(self):
def __str__(self) -> str:
return '%s : %s' % (self.digest, self.user)


Expand Down
2 changes: 1 addition & 1 deletion knox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ def __setattr__(self, *args, **kwargs):
''')


CONSTANTS = CONSTANTS()
CONSTANTS = CONSTANTS() # type: ignore

0 comments on commit 22d787e

Please sign in to comment.