-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-suite.py
More file actions
44 lines (34 loc) · 1.26 KB
/
test-suite.py
File metadata and controls
44 lines (34 loc) · 1.26 KB
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
34
35
36
37
38
39
40
41
42
43
import pytest
from pathlib import Path
import unicodedata
from hdnotebook import CryptoManager
@pytest.mark.parametrize("passphrase_str", [
"pāsswörd", # accented Latin
"пароль", # Cyrillic
"密码", # Chinese
"🔑🔒", # emoji
"passwörd🔑密码", # mixed
"this is a pass",
])
def test_non_ascii_passphrase_roundtrip(passphrase_str):
cm = CryptoManager()
passphrase = bytearray(
unicodedata.normalize('NFC', passphrase_str).encode('utf-8')
)
salt = cm.generate_salt()
nonce = cm.generate_nonce()
master_key = cm.generate_master_key()
derived_key = cm.derive_key(passphrase, salt)
encrypted = cm.encrypt_master_key(master_key, derived_key, nonce)
decrypted = cm.decrypt_master_key(encrypted, derived_key, nonce)
assert decrypted == master_key
def test_file_encrypt_roundtrip():
cm = CryptoManager()
master_key = cm.generate_master_key()
message = "This is a secret message\n"
test_dir = Path("./test_dir")
test_file = test_dir / "test_file"
test_dir.mkdir(exist_ok=True)
cm.encrypt_file(message, master_key, test_file)
decrypted = cm.decrypt_file(test_file, master_key)
assert decrypted == message