~cyborg/yoshi

ecd7973e5e26ed6da0b57b862d65bd6cd44a3590 — christian-cleberg 2 months ago daac06a
update type hints
3 files changed, 14 insertions(+), 14 deletions(-)

M Account.py
M crypto.py
M process.py
M Account.py => Account.py +5 -5
@@ 2,23 2,23 @@ import database


class Account:
    def __init__(self, id: str, application: str, username: str, password: str, url: str) -> None:
        self.id = id
    def __init__(self, uuid: str, application: str, username: str, password: str, url: str) -> None:
        self.uuid = uuid
        self.application = application
        self.username = username
        self.password = password
        self.url = url

    def display_account(self) -> None:
        print('ID:', self.id)
        print('ID:', self.uuid)
        print('Application:', self.application)
        print('Username:', self.username)
        print('Password:', self.password)
        print('URL:', self.url)

    def save_account(self) -> None:
        database.create_account(self.id, self.application, self.username, self.password, self.url)
        database.create_account(self.uuid, self.application, self.username, self.password, self.url)

    def delete_account(self) -> bool:
        database.delete_account(self.id)
        database.delete_account(self.uuid)
        return True

M crypto.py => crypto.py +4 -4
@@ 3,16 3,16 @@ from cryptography.fernet import Fernet
vault_file = 'vault.sqlite'


def generate_key():
def generate_key() -> bytes:
    new_key = Fernet.generate_key()
    return new_key


def load_key(key_file):
def load_key(key_file: str) -> bytes:
    return open(key_file, 'rb').read()


def encrypt(key, filename=vault_file):
def encrypt(key, filename=vault_file) -> None:
    f = Fernet(key)
    with open(filename, 'rb') as file:
        file_data = file.read()


@@ 21,7 21,7 @@ def encrypt(key, filename=vault_file):
        file.write(encrypted_data)


def decrypt(key, filename=vault_file):
def decrypt(key, filename=vault_file) -> None:
    f = Fernet(key)
    with open(filename, 'rb') as file:
        encrypted_data = file.read()

M process.py => process.py +5 -5
@@ 40,15 40,15 @@ def generate_passphrase(n: int, sep: str) -> str:
# List all saved accounts
def list_accounts() -> None:
    accounts = database.find_accounts()
    t = PrettyTable(['ID', 'Application', 'Username', 'Password', 'URL'])
    t = PrettyTable(['UUID', 'Application', 'Username', 'Password', 'URL'])
    for account in accounts:
        t.add_row([account[0], account[1], account[2], account[3], account[4]])
    print(t)


# Delete a single account by UUID
def delete_account(account_id: str) -> None:
    account_record = database.find_account(account_id)
def delete_account(uuid: str) -> None:
    account_record = database.find_account(uuid)
    account: Account = Account(account_record[0][0],
                               account_record[0][1],
                               account_record[0][2],


@@ 94,7 94,7 @@ def create_account() -> None:


# Allow users to edit any account info except the UUID
def edit_account(account_id: str, edit_parameter: int) -> None:
def edit_account(uuid: str, edit_parameter: int) -> None:
    if edit_parameter == 1:
        field_name = 'application'
        new_value = input('Please enter your desired Application name: ')


@@ 116,5 116,5 @@ def edit_account(account_id: str, edit_parameter: int) -> None:
    elif edit_parameter == 4:
        field_name = 'url'
        new_value = input('Please enter your desired URL: ')
    database.update_account(field_name, new_value, account_id)
    database.update_account(field_name, new_value, uuid)
    print('Account successfully updated.')