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 Base64 Helper Functions for Vodozemac-Olm Interoperability #16

Open
TrevisGordan opened this issue Dec 10, 2024 · 1 comment
Open

Comments

@TrevisGordan
Copy link

To streamline interoperability between Vodozemac and python-olm, introduce helper functions that handle Base64 encoding and decoding of message attributes (ciphertext, mac, ephemeral_key) directly in Rust. This will remove the need for manual encoding on the Python side and improve usability.

Current example:

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

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()

This would provide a clearer API, as different message encodings in use can be unclear to the user.

See: #15

@TrevisGordan
Copy link
Author

With the help of the compatible base64_decode and base64_encode functions in Vodozemac, which handle base64 padding, I was able to directly implement this functionality in #15 .

The PR introduces a from_base64 class method and a to_base64 method, enabling straightforward usage as follows:

# Converting from base64
vodo_msg = Message.from_base64(
    olm_msg.ciphertext,
    olm_msg.mac,
    olm_msg.ephemeral_key,
)
# Converting to base64
ephemeral_key_b64, mac_b64, ciphertext_b64 = vodo_msg.to_base64()

Merging #15 would resolve this issue.

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

No branches or pull requests

1 participant