From 2ee30526b4a11ae6be60acce5eb554d3fb0c9999 Mon Sep 17 00:00:00 2001 From: Gordan Trevis Date: Tue, 10 Dec 2024 15:01:03 +0100 Subject: [PATCH 01/14] Adds missing rust message attribute accessibility and test --- src/pk_encryption.rs | 3 +++ tests/pk_encryption_test.py | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/pk_encryption.rs b/src/pk_encryption.rs index f93f862..2291f3f 100644 --- a/src/pk_encryption.rs +++ b/src/pk_encryption.rs @@ -13,14 +13,17 @@ use crate::{ #[pyclass] pub struct Message { /// The ciphertext of the message. + #[pyo3(get)] ciphertext: Vec, /// The message authentication code of the message. /// /// *Warning*: As stated in the module description, this does not /// authenticate the message. + #[pyo3(get)] mac: Vec, /// The ephemeral Curve25519PublicKey of the message which was used to /// derive the individual message key. + #[pyo3(get)] ephemeral_key: Vec, } diff --git a/tests/pk_encryption_test.py b/tests/pk_encryption_test.py index 39a093d..3b5c436 100644 --- a/tests/pk_encryption_test.py +++ b/tests/pk_encryption_test.py @@ -1,10 +1,17 @@ import importlib import pytest -from vodozemac import Curve25519SecretKey, Curve25519PublicKey, PkEncryption, PkDecryption, PkDecodeException +from vodozemac import ( + Curve25519SecretKey, + Curve25519PublicKey, + PkEncryption, + PkDecryption, + PkDecodeException, +) CLEARTEXT = b"test" + class TestClass(object): def test_encrypt_decrypt(self): d = PkDecryption() @@ -28,3 +35,14 @@ def test_encrypt_decrypt_with_serialized_keys(self): decoded = d.decrypt(e.encrypt(CLEARTEXT)) assert decoded == CLEARTEXT + + def test_encrypt_message_attr(self): + """Test that the Message object has accessible Python attributes (mac, ciphertext, ephemeral_key).""" + decryption = PkDecryption() + encryption = PkEncryption.from_key(decryption.public_key) + + message = encryption.encrypt(CLEARTEXT) + + assert message.mac is not None + assert message.ciphertext is not None + assert message.ephemeral_key is not None From 2f309c594b8d0e7df0cab211bb4e1e487d067145 Mon Sep 17 00:00:00 2001 From: Gordan Trevis Date: Tue, 10 Dec 2024 15:12:35 +0100 Subject: [PATCH 02/14] =?UTF-8?q?Adds=20Message=20impl=20(pymethods)=20to?= =?UTF-8?q?=20enable=20object=20creation=20from=20python.=20Adds=20python-?= =?UTF-8?q?olm=20Dependencie=20(at=C2=A03.2.16).=20Adds=20PkEncryption=20(?= =?UTF-8?q?python-olm)=C2=A0compatibility=20tests.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements-dev.txt | 1 + src/pk_encryption.rs | 12 ++++++++++ tests/pk_encryption_test.py | 47 +++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index 20faf86..d84aa7e 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1,3 @@ maturin pytest>=4.0 +python-olm==3.2.16 \ No newline at end of file diff --git a/src/pk_encryption.rs b/src/pk_encryption.rs index 2291f3f..60dba92 100644 --- a/src/pk_encryption.rs +++ b/src/pk_encryption.rs @@ -27,6 +27,18 @@ pub struct Message { ephemeral_key: Vec, } +#[pymethods] +impl Message { + #[new] + fn new(ciphertext: Vec, mac: Vec, ephemeral_key: Vec) -> Self { + Message { + ciphertext, + mac, + ephemeral_key, + } + } +} + /// ☣️ Compat support for libolm's PkDecryption. /// /// This implements the `m.megolm_backup.v1.curve25519-aes-sha2` described in diff --git a/tests/pk_encryption_test.py b/tests/pk_encryption_test.py index 3b5c436..7df2a3a 100644 --- a/tests/pk_encryption_test.py +++ b/tests/pk_encryption_test.py @@ -1,5 +1,7 @@ import importlib import pytest +import olm +import base64 from vodozemac import ( Curve25519SecretKey, @@ -7,6 +9,7 @@ PkEncryption, PkDecryption, PkDecodeException, + Message, ) CLEARTEXT = b"test" @@ -46,3 +49,47 @@ def test_encrypt_message_attr(self): assert message.mac is not None assert message.ciphertext is not None assert message.ephemeral_key is not None + + def test_olm_encrypt_vodo_decrypt(self): + """Test encrypting with Olm and decrypting with Vodo.""" + vodo_decryption = PkDecryption() + olm_encrypts = olm.pk.PkEncryption(vodo_decryption.public_key.to_base64()) + olm_msg = olm_encrypts.encrypt(CLEARTEXT) + + # Convert the Olm message into a Vodo message structure. + def pad_base64_decode(b64_str: str) -> bytes: + """Add the required number of '=' padding to make the length a multiple of 4, then Base64 decode.""" + return base64.b64decode(b64_str + "=" * ((4 - len(b64_str) % 4) % 4)) + + vodo_msg = Message( + pad_base64_decode(olm_msg.ciphertext), + pad_base64_decode(olm_msg.mac), + pad_base64_decode(olm_msg.ephemeral_key), + ) + + # Decrypt the message with Vodo + decrypted_plaintext = vodo_decryption.decrypt(vodo_msg) + assert decrypted_plaintext == CLEARTEXT + + def test_vodo_encrypt_olm_decrypt(self): + """Test encrypting with Vodo and decrypting with Olm.""" + olm_decryption = olm.pk.PkDecryption() + + public_key = Curve25519PublicKey.from_base64(olm_decryption.public_key) + vodo_encryption = PkEncryption.from_key(public_key) + vodo_msg = vodo_encryption.encrypt(CLEARTEXT) + + # Convert the Vodo message into an Olm message structure + def unpad_base64_encode(vodo_bytes: bytes) -> str: + """Base64 encode the given bytes and remove trailing '=' padding.""" + return base64.b64encode(vodo_bytes).decode("utf-8").rstrip("=") + + olm_msg = olm.pk.PkMessage( + unpad_base64_encode(vodo_msg.ephemeral_key), + unpad_base64_encode(vodo_msg.mac), + unpad_base64_encode(vodo_msg.ciphertext), + ) + + # Decrypt the message with Olm + decrypted_plaintext = olm_decryption.decrypt(olm_msg) + assert decrypted_plaintext.encode("utf-8") == CLEARTEXT From beee99fc2260f1e4ca57022d457fffcc889e47f8 Mon Sep 17 00:00:00 2001 From: Gordan Trevis Date: Wed, 11 Dec 2024 11:24:46 +0100 Subject: [PATCH 03/14] cargo fmt --- src/pk_encryption.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pk_encryption.rs b/src/pk_encryption.rs index 60dba92..1dc34ef 100644 --- a/src/pk_encryption.rs +++ b/src/pk_encryption.rs @@ -31,11 +31,7 @@ pub struct Message { impl Message { #[new] fn new(ciphertext: Vec, mac: Vec, ephemeral_key: Vec) -> Self { - Message { - ciphertext, - mac, - ephemeral_key, - } + Message { ciphertext, mac, ephemeral_key } } } From 461673fc375443e0b59bacabf3b3710c4420622e Mon Sep 17 00:00:00 2001 From: Gordan Trevis Date: Thu, 9 Jan 2025 11:28:43 +0100 Subject: [PATCH 04/14] Adds missing newline. --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index d84aa7e..0846534 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,3 @@ maturin pytest>=4.0 -python-olm==3.2.16 \ No newline at end of file +python-olm==3.2.16 From 6ab4c2800e9290f6f50281ccc5cfe741948ec390 Mon Sep 17 00:00:00 2001 From: Gordan Trevis Date: Thu, 9 Jan 2025 11:29:24 +0100 Subject: [PATCH 05/14] Adds Missing Message Object Documentation --- src/pk_encryption.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pk_encryption.rs b/src/pk_encryption.rs index 1dc34ef..596cc7a 100644 --- a/src/pk_encryption.rs +++ b/src/pk_encryption.rs @@ -29,6 +29,15 @@ pub struct Message { #[pymethods] impl Message { + /// Create a new Message object from its components. + /// + /// This constructor creates a Message object that represents an encrypted message + /// using the `m.megolm_backup.v1.curve25519-aes-sha2` algorithm. + /// + /// # Arguments + /// * `ciphertext` - The encrypted content of the message + /// * `mac` - The message authentication code + /// * `ephemeral_key` - The ephemeral public key used during encryption #[new] fn new(ciphertext: Vec, mac: Vec, ephemeral_key: Vec) -> Self { Message { ciphertext, mac, ephemeral_key } From 9258ede94e26341a06eaf48ceaa64e0146f05896 Mon Sep 17 00:00:00 2001 From: Gordan Trevis Date: Thu, 9 Jan 2025 14:51:55 +0100 Subject: [PATCH 06/14] Adds a from_base64 message classmethod. Adds a to_base64 conversion message method. --- src/pk_encryption.rs | 58 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/src/pk_encryption.rs b/src/pk_encryption.rs index 596cc7a..9b69e67 100644 --- a/src/pk_encryption.rs +++ b/src/pk_encryption.rs @@ -1,7 +1,12 @@ use pyo3::{ - pyclass, pymethods, - types::{PyBytes, PyType}, - Bound, Py, Python, + pyclass, + pymethods, + types::{PyBytes, PyString, PyType}, + Bound, + IntoPyObject, + Py, + PyResult, + Python, }; use crate::{ @@ -42,6 +47,53 @@ impl Message { fn new(ciphertext: Vec, mac: Vec, ephemeral_key: Vec) -> Self { Message { ciphertext, mac, ephemeral_key } } + + /// Create a new Message object from unpadded Base64-encoded components. + /// + /// This function decodes the given Base64 strings and returns a `Message` + /// with the resulting byte vectors. + /// + /// # Arguments + /// * `ciphertext` - Unpadded Base64-encoded ciphertext + /// * `mac` - Unpadded Base64-encoded message authentication code + /// * `ephemeral_key` - Unpadded Base64-encoded ephemeral key + #[classmethod] + fn from_base64( + _cls: &Bound<'_, PyType>, + ciphertext: &str, + mac: &str, + ephemeral_key: &str, + ) -> Self { + let decoded_ciphertext = + vodozemac::base64_decode(ciphertext).expect("Failed to decode ciphertext"); + let decoded_mac = vodozemac::base64_decode(mac).expect("Failed to decode mac"); + let decoded_ephemeral_key = + vodozemac::base64_decode(ephemeral_key).expect("Failed to decode ephemeral_key"); + + Self { + ciphertext: decoded_ciphertext, + mac: decoded_mac, + ephemeral_key: decoded_ephemeral_key, + } + } + + /// Convert the message components to unpadded Base64-encoded strings. + /// + /// Returns a tuple of (ciphertext, mac, ephemeral_key) as unpadded Base64 strings. + fn to_base64<'py>( + &self, + py: Python<'py>, + ) -> PyResult<(Bound<'py, PyString>, Bound<'py, PyString>, Bound<'py, PyString>)> { + let ciphertext_b64 = vodozemac::base64_encode(&self.ciphertext); + let mac_b64 = vodozemac::base64_encode(&self.mac); + let ephemeral_key_b64 = vodozemac::base64_encode(&self.ephemeral_key); + + Ok(( + ephemeral_key_b64.into_pyobject(py)?, + mac_b64.into_pyobject(py)?, + ciphertext_b64.into_pyobject(py)?, + )) + } } /// ☣️ Compat support for libolm's PkDecryption. From 81fa80980140605c3d323ad326eb2ac062e2bc9c Mon Sep 17 00:00:00 2001 From: Gordan Trevis Date: Thu, 9 Jan 2025 14:53:25 +0100 Subject: [PATCH 07/14] =?UTF-8?q?Adds=C2=A0from=5Fbase64=20and=C2=A0to=5Fb?= =?UTF-8?q?ase64=20message=20functions=20to=20test.=20Removes=20base64=20p?= =?UTF-8?q?adding=20conversion=20helper=20functions=20from=20tests.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/pk_encryption_test.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/tests/pk_encryption_test.py b/tests/pk_encryption_test.py index 7df2a3a..974e922 100644 --- a/tests/pk_encryption_test.py +++ b/tests/pk_encryption_test.py @@ -56,15 +56,10 @@ def test_olm_encrypt_vodo_decrypt(self): olm_encrypts = olm.pk.PkEncryption(vodo_decryption.public_key.to_base64()) olm_msg = olm_encrypts.encrypt(CLEARTEXT) - # Convert the Olm message into a Vodo message structure. - def pad_base64_decode(b64_str: str) -> bytes: - """Add the required number of '=' padding to make the length a multiple of 4, then Base64 decode.""" - return base64.b64decode(b64_str + "=" * ((4 - len(b64_str) % 4) % 4)) - - vodo_msg = Message( - pad_base64_decode(olm_msg.ciphertext), - pad_base64_decode(olm_msg.mac), - pad_base64_decode(olm_msg.ephemeral_key), + vodo_msg = Message.from_base64( + olm_msg.ciphertext, + olm_msg.mac, + olm_msg.ephemeral_key, ) # Decrypt the message with Vodo @@ -79,15 +74,12 @@ def test_vodo_encrypt_olm_decrypt(self): vodo_encryption = PkEncryption.from_key(public_key) vodo_msg = vodo_encryption.encrypt(CLEARTEXT) - # Convert the Vodo message into an Olm message structure - def unpad_base64_encode(vodo_bytes: bytes) -> str: - """Base64 encode the given bytes and remove trailing '=' padding.""" - return base64.b64encode(vodo_bytes).decode("utf-8").rstrip("=") - + ephemeral_key_b64, mac_b64, ciphertext_b64 = vodo_msg.to_base64() + olm_msg = olm.pk.PkMessage( - unpad_base64_encode(vodo_msg.ephemeral_key), - unpad_base64_encode(vodo_msg.mac), - unpad_base64_encode(vodo_msg.ciphertext), + ephemeral_key_b64, + mac_b64, + ciphertext_b64 ) # Decrypt the message with Olm From de4d64bac24279119a69c9a12ae49c2260188ff5 Mon Sep 17 00:00:00 2001 From: Gordan Trevis Date: Fri, 10 Jan 2025 13:19:52 +0100 Subject: [PATCH 08/14] re cargo fmt --- src/pk_encryption.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/pk_encryption.rs b/src/pk_encryption.rs index 9b69e67..3ffa37f 100644 --- a/src/pk_encryption.rs +++ b/src/pk_encryption.rs @@ -1,12 +1,7 @@ use pyo3::{ - pyclass, - pymethods, + pyclass, pymethods, types::{PyBytes, PyString, PyType}, - Bound, - IntoPyObject, - Py, - PyResult, - Python, + Bound, IntoPyObject, Py, PyResult, Python, }; use crate::{ From 6502da9f84efefbacc101e4959415bd4e55bddc4 Mon Sep 17 00:00:00 2001 From: Gordan Trevis Date: Mon, 13 Jan 2025 13:47:42 +0100 Subject: [PATCH 09/14] removes explicit pyo3 conversion. --- src/pk_encryption.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/pk_encryption.rs b/src/pk_encryption.rs index 3ffa37f..b551399 100644 --- a/src/pk_encryption.rs +++ b/src/pk_encryption.rs @@ -1,7 +1,7 @@ use pyo3::{ pyclass, pymethods, - types::{PyBytes, PyString, PyType}, - Bound, IntoPyObject, Py, PyResult, Python, + types::{PyBytes, PyType}, + Bound, Py, PyResult, Python, }; use crate::{ @@ -75,19 +75,12 @@ impl Message { /// Convert the message components to unpadded Base64-encoded strings. /// /// Returns a tuple of (ciphertext, mac, ephemeral_key) as unpadded Base64 strings. - fn to_base64<'py>( - &self, - py: Python<'py>, - ) -> PyResult<(Bound<'py, PyString>, Bound<'py, PyString>, Bound<'py, PyString>)> { + fn to_base64(&self) -> PyResult<(String, String, String)> { let ciphertext_b64 = vodozemac::base64_encode(&self.ciphertext); let mac_b64 = vodozemac::base64_encode(&self.mac); let ephemeral_key_b64 = vodozemac::base64_encode(&self.ephemeral_key); - Ok(( - ephemeral_key_b64.into_pyobject(py)?, - mac_b64.into_pyobject(py)?, - ciphertext_b64.into_pyobject(py)?, - )) + Ok((ephemeral_key_b64, mac_b64, ciphertext_b64)) } } From 355f7d899780c82a4d2869d7b1a55d8913193715 Mon Sep 17 00:00:00 2001 From: Gordan Trevis Date: Mon, 13 Jan 2025 14:06:58 +0100 Subject: [PATCH 10/14] Adds proper error return PkDecodeException to from_base64, Adds PkDecodeException test case --- src/error.rs | 3 +++ src/pk_encryption.rs | 16 +++++++--------- tests/pk_encryption_test.py | 27 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/error.rs b/src/error.rs index c91c256..8bcf59b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -136,6 +136,8 @@ pub enum PkEncryptionError { InvalidKeySize(usize), #[error(transparent)] Decode(#[from] vodozemac::pk_encryption::Error), + #[error(transparent)] + Mac(#[from] vodozemac::Base64DecodeError), } pyo3::create_exception!(module, PkInvalidKeySizeException, pyo3::exceptions::PyValueError); @@ -148,6 +150,7 @@ impl From for PyErr { PkInvalidKeySizeException::new_err(e.to_string()) } PkEncryptionError::Decode(_) => PkDecodeException::new_err(e.to_string()), + PkEncryptionError::Mac(_) => PkDecodeException::new_err(e.to_string()) } } } diff --git a/src/pk_encryption.rs b/src/pk_encryption.rs index b551399..b6ec830 100644 --- a/src/pk_encryption.rs +++ b/src/pk_encryption.rs @@ -58,18 +58,16 @@ impl Message { ciphertext: &str, mac: &str, ephemeral_key: &str, - ) -> Self { - let decoded_ciphertext = - vodozemac::base64_decode(ciphertext).expect("Failed to decode ciphertext"); - let decoded_mac = vodozemac::base64_decode(mac).expect("Failed to decode mac"); - let decoded_ephemeral_key = - vodozemac::base64_decode(ephemeral_key).expect("Failed to decode ephemeral_key"); - - Self { + ) -> Result { + let decoded_ciphertext = vodozemac::base64_decode(ciphertext)?; + let decoded_mac = vodozemac::base64_decode(mac)?; + let decoded_ephemeral_key = vodozemac::base64_decode(ephemeral_key)?; + + Ok(Self { ciphertext: decoded_ciphertext, mac: decoded_mac, ephemeral_key: decoded_ephemeral_key, - } + }) } /// Convert the message components to unpadded Base64-encoded strings. diff --git a/tests/pk_encryption_test.py b/tests/pk_encryption_test.py index 974e922..e328d6e 100644 --- a/tests/pk_encryption_test.py +++ b/tests/pk_encryption_test.py @@ -85,3 +85,30 @@ def test_vodo_encrypt_olm_decrypt(self): # Decrypt the message with Olm decrypted_plaintext = olm_decryption.decrypt(olm_msg) assert decrypted_plaintext.encode("utf-8") == CLEARTEXT + + + def test_message_from_invalid_base64(self): + """Test that invalid base64 input raises PkDecodeException.""" + # Test invalid ciphertext + with pytest.raises(PkDecodeException, match="Invalid symbol"): + Message.from_base64( + "not-valid-base64!@#", # Invalid base64 for ciphertext + base64.b64encode(b"some_mac").decode(), # Valid base64 + base64.b64encode(b"some_key").decode() # Valid base64 + ) + + # Test invalid mac + with pytest.raises(PkDecodeException, match="Invalid symbol"): + Message.from_base64( + base64.b64encode(b"some_text").decode(), + "not-valid-base64!@#", # Invalid base64 for mac + base64.b64encode(b"some_key").decode() + ) + + # Test invalid ephemeral key + with pytest.raises(PkDecodeException, match="Invalid symbol"): + Message.from_base64( + base64.b64encode(b"some_text").decode(), + base64.b64encode(b"some_mac").decode(), + "not-valid-base64!@#" # Invalid base64 for ephemeral key + ) \ No newline at end of file From 4fc380e6fe2b07d6b91f250d4e74b61c6e656164 Mon Sep 17 00:00:00 2001 From: Gordan Trevis Date: Mon, 13 Jan 2025 14:10:28 +0100 Subject: [PATCH 11/14] cargo fmt --- src/error.rs | 2 +- src/pk_encryption.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index 8bcf59b..b26716e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -150,7 +150,7 @@ impl From for PyErr { PkInvalidKeySizeException::new_err(e.to_string()) } PkEncryptionError::Decode(_) => PkDecodeException::new_err(e.to_string()), - PkEncryptionError::Mac(_) => PkDecodeException::new_err(e.to_string()) + PkEncryptionError::Mac(_) => PkDecodeException::new_err(e.to_string()), } } } diff --git a/src/pk_encryption.rs b/src/pk_encryption.rs index b6ec830..8efe969 100644 --- a/src/pk_encryption.rs +++ b/src/pk_encryption.rs @@ -62,7 +62,7 @@ impl Message { let decoded_ciphertext = vodozemac::base64_decode(ciphertext)?; let decoded_mac = vodozemac::base64_decode(mac)?; let decoded_ephemeral_key = vodozemac::base64_decode(ephemeral_key)?; - + Ok(Self { ciphertext: decoded_ciphertext, mac: decoded_mac, From 036bd1114c2dc0c2c86f86878a36b08bed79f542 Mon Sep 17 00:00:00 2001 From: Gordan Trevis Date: Mon, 13 Jan 2025 15:12:21 +0100 Subject: [PATCH 12/14] cargo +nightly fmt --- src/pk_encryption.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pk_encryption.rs b/src/pk_encryption.rs index 8efe969..cb483ef 100644 --- a/src/pk_encryption.rs +++ b/src/pk_encryption.rs @@ -31,8 +31,9 @@ pub struct Message { impl Message { /// Create a new Message object from its components. /// - /// This constructor creates a Message object that represents an encrypted message - /// using the `m.megolm_backup.v1.curve25519-aes-sha2` algorithm. + /// This constructor creates a Message object that represents an encrypted + /// message using the `m.megolm_backup.v1.curve25519-aes-sha2` + /// algorithm. /// /// # Arguments /// * `ciphertext` - The encrypted content of the message @@ -72,7 +73,8 @@ impl Message { /// Convert the message components to unpadded Base64-encoded strings. /// - /// Returns a tuple of (ciphertext, mac, ephemeral_key) as unpadded Base64 strings. + /// Returns a tuple of (ciphertext, mac, ephemeral_key) as unpadded Base64 + /// strings. fn to_base64(&self) -> PyResult<(String, String, String)> { let ciphertext_b64 = vodozemac::base64_encode(&self.ciphertext); let mac_b64 = vodozemac::base64_encode(&self.mac); From 97e06c9eee1aabd5d3a24299dd0f748f7304fda6 Mon Sep 17 00:00:00 2001 From: Gordan Trevis Date: Mon, 13 Jan 2025 15:13:07 +0100 Subject: [PATCH 13/14] Update tests/pk_encryption_test.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Damir Jelić --- tests/pk_encryption_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pk_encryption_test.py b/tests/pk_encryption_test.py index e328d6e..4463b59 100644 --- a/tests/pk_encryption_test.py +++ b/tests/pk_encryption_test.py @@ -111,4 +111,4 @@ def test_message_from_invalid_base64(self): base64.b64encode(b"some_text").decode(), base64.b64encode(b"some_mac").decode(), "not-valid-base64!@#" # Invalid base64 for ephemeral key - ) \ No newline at end of file + ) From 4a1a91c45d389e2249353e383bb4742a25bdd9c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 17 Jan 2025 13:29:14 +0100 Subject: [PATCH 14/14] chore: Fix a clippy warning --- src/pk_encryption.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pk_encryption.rs b/src/pk_encryption.rs index cb483ef..31a2770 100644 --- a/src/pk_encryption.rs +++ b/src/pk_encryption.rs @@ -1,7 +1,7 @@ use pyo3::{ pyclass, pymethods, types::{PyBytes, PyType}, - Bound, Py, PyResult, Python, + Bound, Py, Python, }; use crate::{ @@ -75,7 +75,7 @@ impl Message { /// /// Returns a tuple of (ciphertext, mac, ephemeral_key) as unpadded Base64 /// strings. - fn to_base64(&self) -> PyResult<(String, String, String)> { + fn to_base64(&self) -> Result<(String, String, String), PkEncryptionError> { let ciphertext_b64 = vodozemac::base64_encode(&self.ciphertext); let mac_b64 = vodozemac::base64_encode(&self.mac); let ephemeral_key_b64 = vodozemac::base64_encode(&self.ephemeral_key);