Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ mod types;
use error::*;
use pyo3::{prelude::*, types::PyBytes};

/// A Rust implementation of Olm and Megolm
///
/// vodozemac is a Rust reimplementation of [libolm](https://gitlab.matrix.org/matrix-org/olm), a
/// cryptographic library used for end-to-end encryption in [Matrix](https://matrix.org). At its
/// core, it is an implementation of the Olm and Megolm cryptographic ratchets,
/// along with a high-level API to easily establish cryptographic communication
/// channels employing those ratchets with other parties. It also implements
/// some other miscellaneous cryptographic functionality which is useful for
/// building Matrix clients, such as [SAS][sas].
///
/// [sas]:
/// <https://spec.matrix.org/v1.2/client-server-api/#short-authentication-string-sas-verification>
#[pymodule(name = "vodozemac")]
fn my_module(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<account::Account>()?;
Expand Down
19 changes: 19 additions & 0 deletions src/sas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use pyo3::prelude::*;

use crate::{error::SasError, types::Curve25519PublicKey};

/// A class representing a short auth string verification object.
///
/// This object can be used to establish a shared secret to perform the short
/// auth string based key verification.
#[pyclass]
pub struct Sas {
inner: Option<vodozemac::sas::Sas>,
Expand All @@ -10,6 +14,10 @@ pub struct Sas {

#[pymethods]
impl Sas {
/// Create a new random verification object
///
/// This creates an ephemeral Curve25519 keypair that can be used to
/// establish a shared secret.
#[new]
fn new() -> Self {
let sas = vodozemac::sas::Sas::new();
Expand All @@ -18,11 +26,17 @@ impl Sas {
Self { inner: Some(sas), public_key }
}

/// The public key that can be used to establish a shared secret.
#[getter]
fn public_key(&self) -> Curve25519PublicKey {
self.public_key.into()
}

/// Establishes a SAS secret by performing a DH handshake with another
/// public key.
///
/// Returns an [`EstablishedSas`] object which can be used to generate
/// [`SasBytes`] if the given public key was valid, otherwise `None`.
fn diffie_hellman(&mut self, key: Curve25519PublicKey) -> Result<EstablishedSas, SasError> {
if let Some(sas) = self.inner.take() {
let sas = sas.diffie_hellman(key.inner)?;
Expand All @@ -34,6 +48,11 @@ impl Sas {
}
}

/// A class representing a short auth string verification object where the
/// shared secret has been established.
///
/// This object can be used to generate the short auth string and calculate and
/// verify a MAC that protects information about the keys being verified.
#[pyclass]
pub struct EstablishedSas {
inner: vodozemac::sas::EstablishedSas,
Expand Down
Loading