Skip to content

Commit

Permalink
Move Entry subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
pilartomas committed Dec 21, 2022
1 parent 8485560 commit 8fd9050
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
18 changes: 16 additions & 2 deletions src/trezorpass/store/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class Tag:
def __init__(self, *, title: str) -> None:
def __init__(self, *, title: str):
self.title = title


Expand All @@ -15,8 +15,22 @@ def __init__(self, *, url: str, title: str, username: str, nonce: str, tags: Lis
self.tags: List[Tag] = tags


class EncryptedEntry(Entry):
def __init__(self, *, encrypted_password: str, encrypted_safe_note: str, **kwargs):
super().__init__(**kwargs)
self.encrypted_password = encrypted_password
self.encrypted_safe_note = encrypted_safe_note


class DecryptedEntry(Entry):
def __init__(self, *, password: str, safe_note: str, **kwargs):
super().__init__(**kwargs)
self.password = password
self.safe_note = safe_note


class Store:
def __init__(self, name: str, entries: List[Entry], tags: List[Tag]):
def __init__(self, *, name: str, entries: List[Entry], tags: List[Tag]):
self.name = name
self.entries = entries
self.tags = tags
30 changes: 1 addition & 29 deletions src/trezorpass/store/entry.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,8 @@
import json
from typing import List

from trezorpass.crypto import decrypt
from trezorpass.store.containers import EncryptedEntry, DecryptedEntry
from trezorpass.store.keychain import Keychain
from trezorpass.store.tag import Tag


class Entry:
def __init__(self, *, url: str, title: str, username: str, nonce: str, tags: List[Tag]):
self.url = url
self.title = title
self.username = username
self.nonce = nonce
self.tags: List[Tag] = tags

@property
def label(self) -> str:
return self.note if self.note is not None else self.title


class EncryptedEntry(Entry):
def __init__(self, *, encrypted_password: str, encrypted_safe_note: str, **kwargs):
super().__init__(**kwargs)
self.encrypted_password = encrypted_password
self.encrypted_safe_note = encrypted_safe_note


class DecryptedEntry(Entry):
def __init__(self, *, password: str, safe_note: str, **kwargs):
super().__init__(**kwargs)
self.password = password
self.safe_note = safe_note


class EntryDecoder:
Expand Down
6 changes: 5 additions & 1 deletion src/trezorpass/store/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ def decode(self, encoded_store: bytes) -> Store:
entries_dict = store_dict['entries']
tags = [self.tag_decoder.decode(tags_dict[key]) for key in tags_dict]
entries = [self.entry_decoder.decode(entries_dict[key]) for key in entries_dict]
return Store(self.keychain.store_name, entries, tags)
return Store(
name=self.keychain.store_name,
entries=entries,
tags=tags
)
except Exception as e:
raise StoreDecodeError() from e

Expand Down

0 comments on commit 8fd9050

Please sign in to comment.