def verify(window: 'TxWindow', contact_list: 'ContactList') -> None: """Verify fingerprints with contact.""" if window.type == WIN_TYPE_GROUP or window.contact is None: raise SoftError("Error: A group is selected.", head_clear=True) if window.contact.uses_psk(): raise SoftError("Pre-shared keys have no fingerprints.", head_clear=True) try: verified = verify_fingerprints(window.contact.tx_fingerprint, window.contact.rx_fingerprint) except (EOFError, KeyboardInterrupt): raise SoftError("Fingerprint verification aborted.", delay=1, head=2, tail_clear=True) status_hr, status = { True: ("Verified", KEX_STATUS_VERIFIED), False: ("Unverified", KEX_STATUS_UNVERIFIED) }[verified] window.contact.kex_status = status contact_list.store_contacts() m_print(f"Marked fingerprints with {window.name} as '{status_hr}'.", bold=True, tail_clear=True, delay=1, tail=1)
def test_incorrect_fingerprint(self, _): self.assertFalse( verify_fingerprints(bytes(FINGERPRINT_LENGTH), bytes(FINGERPRINT_LENGTH)))
def test_correct_fingerprint(self, _: Any) -> None: self.assertTrue(verify_fingerprints(bytes(FINGERPRINT_LENGTH), bytes(FINGERPRINT_LENGTH)))