feat: add multiple, remote recipients support

This commit is contained in:
cătălin 2023-05-09 09:11:36 +02:00
commit c6ac0d6043
Signed by: catalin
GPG key ID: 0178DF42F43E5FD2
10 changed files with 220 additions and 90 deletions

View file

@ -5,29 +5,40 @@ from halig.settings import Settings
def test_instance_encryptor_from_age_keys(halig_path, notebooks_path):
identity = x25519.Identity.generate()
identity_path = halig_path / "identity.key"
identity_path.touch()
recipient_path = halig_path / "recipient.key"
recipient_path.touch()
with identity_path.open("w") as f:
f.write(str(identity))
identity_paths = []
recipient_paths = []
identities = []
for i in range(5):
identity = x25519.Identity.generate()
identities.append(identity)
identity_path = halig_path / f"identity_{i}.key"
identity_path.touch()
with identity_path.open("w") as f:
f.write(str(identity))
identity_paths.append(identity_path)
with recipient_path.open("w") as f:
f.write(str(identity.to_public()))
recipient_path = halig_path / f"recipient_{i}.key"
recipient_path.touch()
with recipient_path.open("w") as f:
f.write(str(identity.to_public()))
recipient_paths.append(recipient_path)
settings = Settings(
notebooks_root_path=notebooks_path,
identity_path=identity_path,
recipient_path=recipient_path,
identity_paths=identity_paths,
recipient_paths=recipient_paths,
)
assert Encryptor(settings)
encryptor = Encryptor(settings)
for identity in identities:
assert str(identity) in [str(identity) for identity in encryptor.identities]
assert str(identity.to_public()) in [str(recipient) for recipient in encryptor.recipients]
def test_encrypt(encryptor: Encryptor, ssh_identity):
unencrypted_data = "foo"
encrypted_data = encryptor.encrypt(unencrypted_data)
assert isinstance(encrypted_data, bytes)
assert unencrypted_data == decrypt(encrypted_data, [ssh_identity]).decode()