Removed utils.py, added decrypt_multiple function in other_accounts.py
This commit is contained in:
		| @@ -2,14 +2,7 @@ import os | ||||
|  | ||||
| from dotenv import load_dotenv | ||||
|  | ||||
| from . import ( | ||||
|     account_checks, | ||||
|     account_parsing, | ||||
|     bot, | ||||
|     cryptography, | ||||
|     database, | ||||
|     gen_password, | ||||
| ) | ||||
| from . import account_checks, account_parsing, bot, cryptography, database, gen_password | ||||
|  | ||||
| __all__ = [ | ||||
|     "account_checks", | ||||
|   | ||||
| @@ -3,10 +3,9 @@ import functools | ||||
| import telebot | ||||
| from sqlalchemy.future import Engine | ||||
|  | ||||
| from .. import utils | ||||
| from . import handlers | ||||
|  | ||||
| __all__ = ["handlers", "utils"] | ||||
| __all__ = ["handlers"] | ||||
|  | ||||
|  | ||||
| def create_bot(token: str, engine: Engine) -> telebot.TeleBot: | ||||
|   | ||||
| @@ -14,7 +14,6 @@ from ..account_checks import ( | ||||
| ) | ||||
| from ..account_parsing import accounts_to_json, json_to_accounts | ||||
| from ..gen_password import gen_password | ||||
| from ..utils import get_all_accounts | ||||
|  | ||||
| Message = telebot.types.Message | ||||
|  | ||||
| @@ -399,7 +398,8 @@ def _export2( | ||||
|     if not cryptography.master_pass.check_master_pass(text, hash_pass, master_salt): | ||||
|         return _send_tmp_message(bot, mes.chat.id, "Не подходит мастер пароль") | ||||
|  | ||||
|     accounts = get_all_accounts(engine, mes.from_user.id, text) | ||||
|     accounts = database.get.get_all_accounts(engine, mes.from_user.id) | ||||
|     accounts = cryptography.other_accounts.decrypt_multiple(accounts, text) | ||||
|     json_io = accounts_to_json(accounts) | ||||
|     bot_mes = bot.send_document(mes.chat.id, json_io) | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| import base64 | ||||
| import os | ||||
| from typing import Iterator | ||||
|  | ||||
| from cryptography.fernet import Fernet | ||||
| from cryptography.hazmat.backends import default_backend | ||||
| @@ -47,3 +48,15 @@ def decrypt_account_info( | ||||
|     login = f.decrypt(base64.urlsafe_b64encode(enc_login)).decode("utf-8") | ||||
|     password = f.decrypt(base64.urlsafe_b64encode(enc_pass)).decode("utf-8") | ||||
|     return (login, password) | ||||
|  | ||||
|  | ||||
| def decrypt_multiple( | ||||
|     accounts: Iterator[tuple[str, bytes, bytes, bytes]], master_pass: str | ||||
| ) -> Iterator[tuple[str, str, str]]: | ||||
|     """Gets an iterator of tuples, where values represent account's name, salt, | ||||
|     encrypted login and encrypted password. | ||||
|     Return an iterator of names, logins and passwords as a tuple""" | ||||
|     for account in accounts: | ||||
|         name, salt, enc_login, enc_passwd = account | ||||
|         login, passwd = decrypt_account_info(enc_login, enc_passwd, master_pass, salt) | ||||
|         yield (name, login, passwd) | ||||
|   | ||||
							
								
								
									
										16
									
								
								src/utils.py
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								src/utils.py
									
									
									
									
									
								
							| @@ -1,16 +0,0 @@ | ||||
| from typing import Iterator | ||||
|  | ||||
| from sqlalchemy.future import Engine | ||||
|  | ||||
| from . import cryptography, database | ||||
|  | ||||
|  | ||||
| def get_all_accounts( | ||||
|     engine: Engine, user_id: int, master_pass: str | ||||
| ) -> Iterator[tuple[str, str, str]]: | ||||
|     for account in database.get.get_all_accounts(engine, user_id): | ||||
|         name, salt, enc_login, enc_passwd = account | ||||
|         login, passwd = cryptography.other_accounts.decrypt_account_info( | ||||
|             enc_login, enc_passwd, master_pass, salt | ||||
|         ) | ||||
|         yield (name, login, passwd) | ||||
		Reference in New Issue
	
	Block a user