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 159c11a + 5cebcc7 commit 9b5afba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/heckbot/cogs/picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import csv
import os
import random
from datetime import datetime, timedelta
from datetime import datetime
from datetime import timedelta
from pathlib import Path
from urllib.parse import quote

Expand Down Expand Up @@ -143,7 +144,7 @@ async def set_picks(self, ctx: Context):
await ctx.author.send(
"Here's your custom link to edit your picks.\n"
"Don't share this with anyone!\n" +
get_pick_link(self._bot.get_user(ctx.author.id).name)
get_pick_link(self._bot.get_user(ctx.author.id).name),
)


Expand Down
23 changes: 14 additions & 9 deletions src/heckbot/utils/auth.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
from __future__ import annotations

import os
from datetime import datetime, timedelta
from datetime import datetime
from datetime import timedelta
from typing import Optional

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives.ciphers import algorithms
from cryptography.hazmat.primitives.ciphers import Cipher
from cryptography.hazmat.primitives.ciphers import modes

SECRET_KEY = os.getenv('HECKBOT_SECRET_KEY')


def encrypt(username: str, expiry: str) -> tuple[bytes, bytes]:
message = f"{username}:{expiry}".encode()
message = f'{username}:{expiry}'.encode()
iv = os.urandom(16)
cipher = Cipher(
algorithms.AES(
SECRET_KEY.encode()
), modes.CFB(iv), backend=default_backend()
SECRET_KEY.encode(),
), modes.CFB(iv), backend=default_backend(),
)
encryptor = cipher.encryptor()
ciphertext = encryptor.update(message) + encryptor.finalize()
return ciphertext, iv


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

0 comments on commit 9b5afba

Please sign in to comment.