Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/pick_game' into feature/…
Browse files Browse the repository at this point in the history
…pick_game

# Conflicts:
#	src/heckbot/cogs/picker.py
  • Loading branch information
BuildTools committed Nov 12, 2023
2 parents 0958ea0 + 4b64b4a commit bd7b14e
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 @@ -7,7 +7,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 @@ -95,9 +96,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(b64encode(token))}'
f'&iv={quote(b64encode(iv))}')
return (
PICK_SERVER_URL +
f'/form?token={quote(b64encode(token))}'
f'&iv={quote(b64encode(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 bd7b14e

Please sign in to comment.