-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathtest_hap_crypto.py
More file actions
33 lines (22 loc) · 794 Bytes
/
test_hap_crypto.py
File metadata and controls
33 lines (22 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Tests for the HAPCrypto."""
from pyhap import hap_crypto
def test_round_trip():
"""Test we can roundtrip data by using the same cipher info."""
plaintext = b"bobdata1232" * 1000
key = b"mykeydsfdsfdsfsdfdsfsdf"
crypto = hap_crypto.HAPCrypto(key)
# Switch the cipher info to the same to allow
# round trip
crypto.OUT_CIPHER_INFO = crypto.IN_CIPHER_INFO
crypto.reset(key)
encrypted = bytearray(crypto.encrypt(plaintext))
# Receive no data
assert crypto.decrypt() == b""
# Receive not a whole block
crypto.receive_data(encrypted[:50])
assert crypto.decrypt() == b""
del encrypted[:50]
# Receive the rest of the block
crypto.receive_data(encrypted)
decrypted = crypto.decrypt()
assert decrypted == plaintext