Remove working code
This commit is contained in:
parent
7d988186a0
commit
c781734141
|
@ -18,6 +18,8 @@ class SubRosaUI:
|
|||
self.public_key = self.private_key.get_public_key()
|
||||
|
||||
def run(self, username):
|
||||
"""Runs the client UI.
|
||||
"""
|
||||
self.username = username
|
||||
self.user = self.get_or_create_user(username)
|
||||
print("Welcome to SubRosa.")
|
||||
|
@ -56,38 +58,30 @@ class SubRosaUI:
|
|||
return 'SEND'
|
||||
|
||||
def show_messages(self):
|
||||
"""Fetches all messages and displays them.
|
||||
Note: The messages arrive from the server encrypted.
|
||||
"""
|
||||
messages = self.api.get_messages(self.username)['messages']
|
||||
if messages:
|
||||
for i, message in enumerate(messages):
|
||||
cleartext = self.private_key.decrypt(message['ciphertext'])
|
||||
print('-' * 80)
|
||||
print(f"{i}. From {message['sender']}:")
|
||||
print(cleartext)
|
||||
print(message['ciphertext'])
|
||||
else:
|
||||
print(f"No messages for {self.username}.")
|
||||
|
||||
def send_message(self):
|
||||
"""Sends a message.
|
||||
"""
|
||||
try:
|
||||
recipient_name = input("Username of recipient: ").strip()
|
||||
recipient = self.api.get_user(recipient_name)
|
||||
except APIError:
|
||||
print(f"No user named {recipient_name}.")
|
||||
return
|
||||
recipient_public_key = PublicKey.load(recipient['public_key'])
|
||||
plaintext = input("Message: ")
|
||||
ciphertext = recipient_public_key.encrypt(plaintext)
|
||||
time_sent = self.get_current_time()
|
||||
time_sent_signature = self.private_key.sign(time_sent)
|
||||
self.api.send_message(
|
||||
self.username,
|
||||
recipient_name,
|
||||
ciphertext,
|
||||
time_sent,
|
||||
time_sent_signature,
|
||||
)
|
||||
print('-' * 80)
|
||||
print(f"Message sent to {recipient_name}")
|
||||
|
||||
print(f"Sorry, couldn't send a message to {recipient_name}; this method isn't implemented yet.")
|
||||
|
||||
def get_current_time(self):
|
||||
return datetime.utcnow().isoformat()
|
||||
|
|
Loading…
Reference in New Issue