Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python Attribute Accessors and Cross-Library Compatibility for PkEncryption #15

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

TrevisGordan
Copy link

This PR adds missing Python attribute accessors and improves compatibility with python-olm by enabling cross-library encryption and decryption tests.

Details:

  • Adds #[pyo3(get)] annotations to the Message struct fields (ciphertext, mac, ephemeral_key), making these attributes accessible from Python.
  • Implements a Message constructor in Rust (via #[new]), allowing Python code to create Message instances directly.
  • Introduces tests to verify that attribute access works as intended.
  • Adds integration tests to ensure PkEncryption is compatible with python-olm. Specifically:
    • Encrypt with Olm and decrypt with Vodozemac.
    • Encrypt with Vodozemac and decrypt with Olm.

Next Steps:

To achieve seamless compatibility, the user will need to Base64-encode Vodozemac message attributes (ciphertext, mac, ephemeral_key) before passing them to Olm. For example:

vodo_encryption = PkEncryption.from_key(public_key)
vodo_message = vodo_encryption.encrypt(PLAINTEXT).encode())

vodo_mac = base64.b64encode(vodo_message.mac).decode('ascii')
vodo_ciphertext = base64.b64encode(vodo_message.ciphertext).decode('ascii')
vodo_ephemeral_key = base64.b64encode(vodo_message.ephemeral_key).decode('ascii')

A future enhancement could add a Rust helper function to handle this encoding automatically, such as:

(ciphertext, mac, ephemeral_key) = encryption.encrypt(json.dumps(media_body).encode()).to_base64()

Also unpad_base64_encode and pad_base64_decode functions.
This would streamline the process and reduce the amount of Python-side encoding logic required.

Adds python-olm Dependencie (at 3.2.16).
Adds PkEncryption (python-olm) compatibility tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant