Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 12, 2023
1 parent da7b0b4 commit 4b64b4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/heckbot/cogs/picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from datetime import datetime
from datetime import timedelta
from pathlib import Path
from urllib.parse import quote, quote_from_bytes
from urllib.parse import quote
from urllib.parse import quote_from_bytes

from discord.ext import commands
from discord.ext.commands import Bot
Expand Down Expand Up @@ -94,9 +95,11 @@ def get_pick_link(user_name: str) -> str:
datetime.utcnow() + timedelta(seconds=TTL)
).isoformat()
token, iv = encrypt(user_name, expiry)
return (PICK_SERVER_URL +
f'/form?token={quote_from_bytes(token)}'
f'&iv={quote_from_bytes(iv)}')
return (
PICK_SERVER_URL +
f'/form?token={quote_from_bytes(token)}'
f'&iv={quote_from_bytes(iv)}'
)


class Picker(commands.Cog):
Expand Down
10 changes: 6 additions & 4 deletions src/heckbot/utils/auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
from datetime import datetime
from datetime import timedelta
Expand All @@ -24,15 +26,15 @@ def encrypt(username: str, expiry: str) -> tuple[bytes, bytes]:
return ciphertext, iv


def decrypt(ciphertext: bytes, iv: bytes) -> Optional[str]:
def decrypt(ciphertext: bytes, iv: bytes) -> str | None:
cipher = Cipher(
algorithms.AES(
SECRET_KEY
), modes.CFB(iv), backend=default_backend()
SECRET_KEY,
), modes.CFB(iv), backend=default_backend(),
)
decryptor = cipher.decryptor()
decrypted_data = decryptor.update(
ciphertext
ciphertext,
) + decryptor.finalize()
decoded_data = decrypted_data.decode()
username, timestamp = decoded_data.split(':')
Expand Down

0 comments on commit 4b64b4a

Please sign in to comment.