Skip to content

Commit

Permalink
Remove feature and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MatMaul committed Sep 5, 2024
1 parent 9d4558d commit d564768
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ edition = "2021"
name = "vodozemac"
crate-type = ["cdylib"]

[features]
default = ["insecure-pk-encryption"]
insecure-pk-encryption = ["vodozemac/insecure-pk-encryption"]

[dependencies]
paste = "1.0.15"
thiserror = "1.0.63"
vodozemac = { git = "https://github.com/matrix-org/vodozemac.git", branch = "poljar/pk-dekurcina" }
vodozemac = { git = "https://github.com/matrix-org/vodozemac.git", branch = "poljar/pk-dekurcina", features = ["insecure-pk-encryption"] }

[package.metadata.maturin]
name = "vodozemac"
Expand Down
3 changes: 0 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ impl From<PickleError> for PyErr {
}
}

#[cfg(feature = "insecure-pk-encryption")]
#[derive(Debug, Error)]
pub enum PkEncryptionError {
#[error("The key doesn't have the correct size, got {0}, expected 32 bytes")]
Expand All @@ -155,11 +154,9 @@ pub enum PkEncryptionError {
Decode(#[from] vodozemac::pk_encryption::Error),
}

#[cfg(feature = "insecure-pk-encryption")]
pyo3::create_exception!(module, PkInvalidKeySizeException, pyo3::exceptions::PyValueError);
pyo3::create_exception!(module, PkDecodeException, pyo3::exceptions::PyValueError);

#[cfg(feature = "insecure-pk-encryption")]
impl From<PkEncryptionError> for PyErr {
fn from(e: PkEncryptionError) -> Self {
match e {
Expand Down
6 changes: 0 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod account;
mod error;
mod group_sessions;
#[cfg(feature = "insecure-pk-encryption")]
mod pk_encryption;
mod sas;
mod session;
Expand Down Expand Up @@ -37,11 +36,8 @@ fn my_module(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<sas::Sas>()?;
m.add_class::<group_sessions::GroupSession>()?;
m.add_class::<group_sessions::InboundGroupSession>()?;
#[cfg(feature = "insecure-pk-encryption")]
m.add_class::<pk_encryption::PkDecryption>()?;
#[cfg(feature = "insecure-pk-encryption")]
m.add_class::<pk_encryption::PkEncryption>()?;
#[cfg(feature = "insecure-pk-encryption")]
m.add_class::<pk_encryption::Message>()?;

m.add_class::<types::Ed25519PublicKey>()?;
Expand Down Expand Up @@ -71,12 +67,10 @@ fn my_module(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
"MegolmDecryptionException",
py.get_type_bound::<MegolmDecryptionException>(),
)?;
#[cfg(feature = "insecure-pk-encryption")]
m.add(
"PkInvalidKeySizeException",
py.get_type_bound::<PkInvalidKeySizeException>(),
)?;
#[cfg(feature = "insecure-pk-encryption")]
m.add(
"PkDecodeException",
py.get_type_bound::<PkDecodeException>(),
Expand Down
23 changes: 21 additions & 2 deletions src/pk_encryption.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
//! ☣️ Compat support for libolm's PkEncryption and PkDecryption
//!
//! This implements the `m.megolm_backup.v1.curve25519-aes-sha2` described in
//! the Matrix [spec]. This is a asymmetric encryption scheme based on
//! Curve25519.
//!
//! **Warning**: Please note the algorithm contains a critical flaw and does not
//! provide authentication of the ciphertext.
//!
//! [spec]: https://spec.matrix.org/v1.11/client-server-api/#backup-algorithm-mmegolm_backupv1curve25519-aes-sha2
use pyo3::{
pyclass, pymethods,
types::{PyBytes, PyType},
Expand All @@ -7,10 +18,18 @@ use vodozemac::Curve25519PublicKey;

use crate::PkEncryptionError;

/// A message that was encrypted using a PkEncryption object.
#[pyclass]
pub struct Message {
/// The ciphertext of the message.
ciphertext: Vec<u8>,
/// The message authentication code of the message.
///
/// *Warning*: As stated in the module description, this does not
/// authenticate the message.
mac: Vec<u8>,
/// The ephemeral Curve25519PublicKey of the message which was used to
/// derive the individual message key.
ephemeral_key: Vec<u8>,
}

Expand Down Expand Up @@ -42,13 +61,13 @@ impl PkDecryption {
})
}

// The secret key used to decrypt messages.
/// The secret key used to decrypt messages.
#[getter]
pub fn key(&self) -> Py<PyBytes> {
Python::with_gil(|py| PyBytes::new_bound(py, self.inner.to_bytes().as_slice()).into())
}

// The public key used to encrypt messages for this decryption object.
/// The public key used to encrypt messages for this decryption object.
#[getter]
pub fn public_key(&self) -> Py<PyBytes> {
Python::with_gil(|py| PyBytes::new_bound(py, self.inner.public_key().as_bytes()).into())
Expand Down

0 comments on commit d564768

Please sign in to comment.