Merge remote-tracking branch 'origin/master' into feature/qrcode-feature

This commit is contained in:
Alexander Sieg 2021-09-10 16:00:41 +02:00
commit 349e3cae06
16 changed files with 179 additions and 151 deletions

View file

@ -1,28 +1,16 @@
[![Build Status](https://img.shields.io/travis/matrix-org/matrix-rust-sdk.svg?style=flat-square)](https://travis-ci.org/matrix-org/matrix-rust-sdk)
[![codecov](https://img.shields.io/codecov/c/github/matrix-org/matrix-rust-sdk/master.svg?style=flat-square)](https://codecov.io/gh/matrix-org/matrix-rust-sdk)
[![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg?style=flat-square)](https://opensource.org/licenses/Apache-2.0)
[![#matrix-rust-sdk](https://img.shields.io/badge/matrix-%23matrix--rust--sdk-blue?style=flat-square)](https://matrix.to/#/#matrix-rust-sdk:matrix.org)
# matrix-qrcode
**matrix-qrcode** is a crate to easily generate and parse QR codes for
interactive verification using [QR codes] in Matrix.
[Matrix]: https://matrix.org/
[Rust]: https://www.rust-lang.org/
[QR codes]: https://spec.matrix.org/unstable/client-server-api/#qr-codes
## Usage
This is probably not the crate you are looking for, it's used internally in the
matrix-rust-sdk.
[matrix-sdk].
If you still want to play with QR codes, here are a couple of helpful examples.
### Decode an image
```rust
```rust,no_run
use image;
use matrix_qrcode::{QrVerificationData, DecodingError};
@ -36,7 +24,7 @@ fn main() -> Result<(), DecodingError> {
### Encode into a QR code
```rust
```rust,no_run
use matrix_qrcode::{QrVerificationData, DecodingError};
use image::Luma;
@ -56,7 +44,5 @@ fn main() -> Result<(), DecodingError> {
}
```
## License
[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)
[matrix-sdk]: https://github.com/matrix-org/matrix-rust-sdk/
[QR codes]: https://spec.matrix.org/unstable/client-server-api/#qr-codes

View file

@ -12,24 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! This crate implements methods to parse and generate QR codes that are used
//! for interactive verification in [Matrix](https://matrix.org/).
//!
//! It implements the QR format defined in the Matrix [spec].
//!
//! [spec]: https://spec.matrix.org/unstable/client-server-api/#qr-code-format
//!
//! ```no_run
//! # use matrix_qrcode::{QrVerificationData, DecodingError};
//! # fn main() -> Result<(), DecodingError> {
//! use image;
//!
//! let image = image::open("/path/to/my/image.png").unwrap();
//! let result = QrVerificationData::from_image(image)?;
//! # Ok(())
//! # }
//! ```
#![doc = include_str!("../README.md")]
#![cfg_attr(feature = "docs", feature(doc_cfg))]
#![deny(
missing_debug_implementations,

View file

@ -21,7 +21,7 @@ encryption = ["matrix-sdk-base/encryption"]
qrcode = ["encryption", "matrix-sdk-base/qrcode"]
sled_state_store = ["matrix-sdk-base/sled_state_store"]
sled_cryptostore = ["matrix-sdk-base/sled_cryptostore"]
markdown = ["matrix-sdk-base/markdown"]
markdown = ["ruma/markdown"]
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]
socks = ["reqwest/socks"]
@ -59,7 +59,7 @@ version = "0.11.3"
default_features = false
[dependencies.ruma]
version = "0.3.0"
version = "0.4.0"
features = ["client-api-c", "compat", "unstable-pre-spec"]
[dependencies.tokio-stream]

View file

@ -1,16 +1,82 @@
[![Build Status](https://img.shields.io/travis/matrix-org/matrix-rust-sdk.svg?style=flat-square)](https://travis-ci.org/matrix-org/matrix-rust-sdk)
[![codecov](https://img.shields.io/codecov/c/github/matrix-org/matrix-rust-sdk/master.svg?style=flat-square)](https://codecov.io/gh/matrix-org/matrix-rust-sdk)
[![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg?style=flat-square)](https://opensource.org/licenses/Apache-2.0)
[![#matrix-rust-sdk](https://img.shields.io/badge/matrix-%23matrix--rust--sdk-blue?style=flat-square)](https://matrix.to/#/#matrix-rust-sdk:matrix.org)
A [Matrix](https://matrix.org/) client library written in Rust.
# matrix-sdk
The matrix-sdk aims to be a general purpose client library for writing Matrix
clients, bots, and other Matrix related things that use the client-server API to
communicate with a Matrix homeserver.
**matrix-sdk** is an implementation of a [Matrix][] client-server library in [Rust][].
# Examples
Connecting and logging in to a homeserver is pretty starightforward:
[Matrix]: https://matrix.org/
[Rust]: https://www.rust-lang.org/
```rust,no_run
use std::convert::TryFrom;
use matrix_sdk::{
Client, SyncSettings, Result,
ruma::{UserId, events::{SyncMessageEvent, room::message::MessageEventContent}},
};
#[tokio::main]
async fn main() -> Result<()> {
let alice = UserId::try_from("@alice:example.org")?;
let client = Client::new_from_user_id(alice.clone()).await?;
## License
// First we need to log in.
client.login(alice.localpart(), "password", None, None).await?;
[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)
client
.register_event_handler(
|ev: SyncMessageEvent<MessageEventContent>| async move {
println!("Received a message {:?}", ev);
},
)
.await;
// Syncing is important to synchronize the client state with the server.
// This method will never return.
client.sync(SyncSettings::default()).await;
Ok(())
}
```
More examples can be found in the [examples] directory.
# Crate Feature Flags
The following crate feature flags are available:
* `encryption`: Enables end-to-end encryption support in the library.
* `sled_cryptostore`: Enables a Sled based store for the encryption keys. If
this is disabled and `encryption` support is enabled the keys will by
default be stored only in memory and thus lost after the client is
destroyed.
* `markdown`: Support for sending markdown formatted messages.
* `socks`: Enables SOCKS support in reqwest, the default HTTP client.
* `sso_login`: Enables SSO login with a local http server.
* `require_auth_for_profile_requests`: Whether to send the access token in
the authentication header when calling endpoints that retrieve profile
data. This matches the synapse configuration
`require_auth_for_profile_requests`. Enabled by default.
* `appservice`: Enables low-level appservice functionality. For an
high-level API there's the `matrix-sdk-appservice` crate
* `anyhow`: Support for returning `anyhow::Result<()>` from event handlers.
# Enabling logging
Users of the matrix-sdk crate can enable log output by depending on the
`tracing-subscriber` crate and including the following line in their
application (e.g. at the start of `main`):
```rust
tracing_subscriber::fmt::init();
```
The log output is controlled via the `RUST_LOG` environment variable by
setting it to one of the `error`, `warn`, `info`, `debug` or `trace` levels.
The output is printed to stdout.
The `RUST_LOG` variable also supports a more advanced syntax for filtering
log output more precisely, for instance with crate-level granularity. For
more information on this, check out the [tracing_subscriber documentation].
[examples]: https://github.com/matrix-org/matrix-rust-sdk/tree/master/matrix_sdk/examples
[tracing_subscriber documentation]: https://tracing.rs/tracing_subscriber/filter/struct.envfilter

View file

@ -922,8 +922,10 @@ impl Client {
///
/// # Examples
///
/// ```no_run
/// # let client: matrix_sdk::Client = unimplemented!();
/// ```
/// # use url::Url;
/// # let homeserver = Url::parse("http://localhost:8080").unwrap();
/// # let client = Client::new(homeserver).unwrap();
/// use matrix_sdk::{
/// room::Room,
/// ruma::{
@ -942,18 +944,21 @@ impl Client {
/// # let _ = async {
/// client
/// .register_event_handler(
/// |ev: SyncMessageEvent<MessageEventContent>, room: Room, client: Client| async move {
/// |ev: SyncMessageEvent<MessageEventContent>,
/// room: Room,
/// client: Client| async move {
/// // Common usage: Room event plus room and client.
/// },
/// )
/// .await
/// .register_event_handler(|ev: SyncStateEvent<TopicEventContent>| async move {
/// // Also possible: Omit any or all arguments after the first.
/// })
/// .await;
/// .register_event_handler(
/// |ev: SyncStateEvent<TopicEventContent>| async move {
/// // Also possible: Omit any or all arguments after the first.
/// }
/// ).await;
///
/// // Custom events work exactly the same way, you just need to declare the content struct and
/// // use the EventContent derive macro on it.
/// // Custom events work exactly the same way, you just need to declare
/// // the content struct and use the EventContent derive macro on it.
/// #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
/// #[ruma_event(type = "org.shiny_new_2fa.token", kind = Message)]
/// struct TokenEventContent {
@ -967,6 +972,19 @@ impl Client {
/// todo!("Display the token");
/// },
/// ).await;
///
/// // Adding your custom data to the handler can be done as well
/// let data = "MyCustomIdentifier".to_string();
///
/// client.register_event_handler({
/// let data = data.clone();
/// move |ev: SyncMessageEvent<MessageEventContent> | {
/// let data = data.clone();
/// async move {
/// println!("Calling the handler with identifier {}", data);
/// }
/// }
/// }).await;
/// # };
/// ```
pub async fn register_event_handler<Ev, Ctx, H>(&self, handler: H) -> &Self

View file

@ -13,47 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! This crate implements a [Matrix](https://matrix.org/) client library.
//!
//! # Enabling logging
//!
//! Users of the matrix-sdk crate can enable log output by depending on the
//! `tracing-subscriber` crate and including the following line in their
//! application (e.g. at the start of `main`):
//!
//! ```rust
//! tracing_subscriber::fmt::init();
//! ```
//!
//! The log output is controlled via the `RUST_LOG` environment variable by
//! setting it to one of the `error`, `warn`, `info`, `debug` or `trace` levels.
//! The output is printed to stdout.
//!
//! The `RUST_LOG` variable also supports a more advanced syntax for filtering
//! log output more precisely, for instance with crate-level granularity. For
//! more information on this, check out the [tracing_subscriber
//! documentation](https://tracing.rs/tracing_subscriber/filter/struct.envfilter).
//!
//! # Crate Feature Flags
//!
//! The following crate feature flags are available:
//!
//! * `encryption`: Enables end-to-end encryption support in the library.
//! * `sled_cryptostore`: Enables a Sled based store for the encryption keys. If
//! this is disabled and `encryption` support is enabled the keys will by
//! default be stored only in memory and thus lost after the client is
//! destroyed.
//! * `markdown`: Support for sending markdown formatted messages.
//! * `socks`: Enables SOCKS support in reqwest, the default HTTP client.
//! * `sso_login`: Enables SSO login with a local http server.
//! * `require_auth_for_profile_requests`: Whether to send the access token in
//! the authentication header when calling endpoints that retrieve profile
//! data. This matches the synapse configuration
//! `require_auth_for_profile_requests`. Enabled by default.
//! * `appservice`: Enables low-level appservice functionality. For an
//! high-level API there's the `matrix-sdk-appservice` crate
//! * `anyhow`: Support for returning `anyhow::Result<()>` from event handlers.
#![doc = include_str!("../README.md")]
#![deny(
missing_debug_implementations,
missing_docs,

View file

@ -39,7 +39,7 @@ warp = { git = "https://github.com/seanmonstar/warp.git", rev = "629405", option
matrix-sdk = { version = "0.3", path = "../matrix_sdk", default-features = false, features = ["appservice"] }
[dependencies.ruma]
version = "0.3.0"
version = "0.4.0"
features = ["client-api-c", "appservice-api-s", "unstable-pre-spec"]
[dev-dependencies]

View file

@ -20,14 +20,13 @@ encryption = ["matrix-sdk-crypto"]
qrcode = ["matrix-sdk-crypto/qrcode"]
sled_state_store = ["sled", "pbkdf2", "hmac", "sha2", "rand", "chacha20poly1305"]
sled_cryptostore = ["matrix-sdk-crypto/sled_cryptostore"]
markdown = ["ruma/markdown"]
docs = ["encryption", "sled_cryptostore"]
[dependencies]
dashmap = "4.0.2"
lru = "0.6.5"
ruma = { version = "0.3.0", features = ["client-api-c", "unstable-pre-spec"] }
ruma = { version = "0.4.0", features = ["client-api-c", "unstable-pre-spec"] }
serde = { version = "1.0.126", features = ["rc"] }
serde_json = "1.0.64"
tracing = "0.1.26"
@ -42,8 +41,8 @@ zeroize = { version = "1.3.0", features = ["zeroize_derive"] }
# Deps for the sled state store
sled = { version = "0.34.6", optional = true }
chacha20poly1305 = { version = "0.8.0", optional = true }
pbkdf2 = { version = "0.8.0", default-features = false, optional = true }
chacha20poly1305 = { version = "0.9.0", optional = true }
pbkdf2 = { version = "0.9.0", default-features = false, optional = true }
hmac = { version = "0.11.0", optional = true }
sha2 = { version = "0.9.5", optional = true }
rand = { version = "0.8.4", optional = true }
@ -60,8 +59,8 @@ http = "0.2.4"
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
tokio = { version = "1.7.1", default-features = false, features = ["rt-multi-thread", "macros"] }
tempfile = "3.2.0"
rustyline = "8.2.0"
rustyline-derive = "0.4.0"
rustyline = "9.0.0"
rustyline-derive = "0.5.0"
atty = "0.2.14"
clap = "2.33.3"
syntect = "4.5.0"

View file

@ -1,15 +1,14 @@
[![Build Status](https://img.shields.io/travis/matrix-org/matrix-rust-sdk.svg?style=flat-square)](https://travis-ci.org/matrix-org/matrix-rust-sdk)
[![codecov](https://img.shields.io/codecov/c/github/matrix-org/matrix-rust-sdk/master.svg?style=flat-square)](https://codecov.io/gh/matrix-org/matrix-rust-sdk)
[![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg?style=flat-square)](https://opensource.org/licenses/Apache-2.0)
[![#matrix-rust-sdk](https://img.shields.io/badge/matrix-%23matrix--rust--sdk-blue?style=flat-square)](https://matrix.to/#/#matrix-rust-sdk:matrix.org)
This crate implements the base to build a [Matrix](https://matrix.org/) client
library.
# matrix-sdk-base
## Crate Feature Flags
**matrix-rust-sdk** is an implementation of a [Matrix][] client-server library in [Rust][].
The following crate feature flags are available:
**NOTE:** This is the no IO client state machine, you're
probably interested in the main
[rust-sdk](https://github.com/matrix-org/matrix-rust-sdk/) crate.
[Matrix]: https://matrix.org/
[Rust]: https://www.rust-lang.org/
* `encryption`: Enables end-to-end encryption support in the library.
* `sled_cryptostore`: Enables a Sled based store for the encryption
keys. If this is disabled and `encryption` support is enabled the keys will
by default be stored only in memory and thus lost after the client is
destroyed.
* `sled_state_store`: Enables a Sled based store for the storage of the local
client state.

View file

@ -13,18 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! This crate implements a [Matrix](https://matrix.org/) client library.
//!
//! ## Crate Feature Flags
//!
//! The following crate feature flags are available:
//!
//! * `encryption`: Enables end-to-end encryption support in the library.
//! * `sled_cryptostore`: Enables a Sled based store for the encryption
//! keys. If this is disabled and `encryption` support is enabled the keys will
//! by default be stored only in memory and thus lost after the client is
//! destroyed.
//! * `markdown`: Support for sending markdown formatted messages.
#![doc = include_str!("../README.md")]
#![cfg_attr(feature = "docs", feature(doc_cfg))]
#![deny(
missing_debug_implementations,
missing_docs,
@ -34,7 +24,6 @@
unused_import_braces,
unused_qualifications
)]
#![cfg_attr(feature = "docs", feature(doc_cfg))]
pub use matrix_sdk_common::*;

View file

@ -13,7 +13,7 @@ version = "0.3.0"
[dependencies]
async-trait = "0.1.50"
instant = { version = "0.1.9", features = ["wasm-bindgen", "now"] }
ruma = { version = "0.3.0", features = ["client-api-c"] }
ruma = { version = "0.4.0", features = ["client-api-c"] }
serde = "1.0.126"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]

View file

@ -23,9 +23,9 @@ docs = ["sled_cryptostore"]
[dependencies]
matrix-qrcode = { version = "0.1.0", path = "../matrix_qrcode" , optional = true}
matrix-sdk-common = { version = "0.3.0", path = "../matrix_sdk_common" }
ruma = { version = "0.3.0", features = ["client-api-c", "unstable-pre-spec"] }
ruma = { version = "0.4.0", features = ["client-api-c", "unstable-pre-spec"] }
olm-rs = { version = "2.0", features = ["serde"] }
olm-rs = { version = "2.0.1", features = ["serde"] }
getrandom = "0.2.3"
serde = { version = "1.0.126", features = ["derive", "rc"] }
serde_json = "1.0.64"
@ -41,7 +41,7 @@ dashmap = "4.0.2"
sha2 = "0.9.5"
aes-gcm = "0.9.2"
aes = { version = "0.7.4", features = ["ctr"] }
pbkdf2 = { version = "0.8.0", default-features = false }
pbkdf2 = { version = "0.9.0", default-features = false }
hmac = "0.11.0"
base64 = "0.13.0"
byteorder = "1.4.3"

View file

@ -1,14 +1,46 @@
[![Build Status](https://img.shields.io/travis/matrix-org/matrix-rust-sdk.svg?style=flat-square)](https://travis-ci.org/matrix-org/matrix-rust-sdk)
[![codecov](https://img.shields.io/codecov/c/github/matrix-org/matrix-rust-sdk/master.svg?style=flat-square)](https://codecov.io/gh/matrix-org/matrix-rust-sdk)
[![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg?style=flat-square)](https://opensource.org/licenses/Apache-2.0)
[![#matrix-rust-sdk](https://img.shields.io/badge/matrix-%23matrix--rust--sdk-blue?style=flat-square)](https://matrix.to/#/#matrix-rust-sdk:matrix.org)
A no-io implementation of a state machine that handles E2EE for [Matrix] clients.
# matrix-sdk-crypto
# Usage
**matrix-rust-sdk** is an implementation of a [Matrix][] client-server library in [Rust][].
This is probably not the crate you are looking for, its used internally in the [matrix-sdk].
**NOTE:** This is a E2EE implementation for Matrix, you are probably interested in the main
[rust-sdk](https://github.com/matrix-org/matrix-rust-sdk/) crate.
If you're still interested in this crate it can be used to introduce E2EE
support into your client or client library.
The state machine works in a push/pull manner, you push state changes and events
that we receive from a sync response from the server, and we pull requests that
we need to send to the server out of the state machine.
```rust,no_run
use std::{collections::BTreeMap, convert::TryFrom};
use matrix_sdk_crypto::{OlmMachine, OlmError};
use ruma::{UserId, api::client::r0::sync::sync_events::{ToDevice, DeviceLists}};
#[tokio::main]
async fn main() -> Result<(), OlmError> {
let alice = UserId::try_from("@alice:example.org").unwrap();
let machine = OlmMachine::new(&alice, "DEVICEID".into());
let to_device_events = ToDevice::default();
let changed_devices = DeviceLists::default();
let one_time_key_counts = BTreeMap::default();
// Push changes that the server sent to us in a sync response.
let decrypted_to_device = machine.receive_sync_changes(
to_device_events,
&changed_devices,
&one_time_key_counts
).await?;
// Pull requests that we need to send out.
let outgoing_requests = machine.outgoing_requests().await?;
// Send the requests here out and call machine.mark_request_as_sent().
Ok(())
}
```
[Matrix]: https://matrix.org/
[Rust]: https://www.rust-lang.org/
[matrix-sdk]: https://github.com/matrix-org/matrix-rust-sdk/

View file

@ -12,9 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! This is the encryption part of the matrix-sdk. It contains a state machine
//! that will aid in adding encryption support to a client library.
#![doc = include_str!("../README.md")]
#![cfg_attr(feature = "docs", feature(doc_cfg))]
#![deny(
missing_debug_implementations,
dead_code,
@ -25,7 +24,6 @@
unused_import_braces,
unused_qualifications
)]
#![cfg_attr(feature = "docs", feature(doc_cfg))]
mod error;
mod file_encryption;

View file

@ -102,7 +102,6 @@ pub struct OlmMachine {
/// State machine handling public user identities and devices, keeping track
/// of when a key query needs to be done and handling one.
identity_manager: IdentityManager,
cross_signing_request: Arc<Mutex<Option<UploadSignaturesRequest>>>,
}
#[cfg(not(tarpaulin_include))]
@ -190,7 +189,6 @@ impl OlmMachine {
verification_machine,
key_request_machine,
identity_manager,
cross_signing_request: Arc::new(Mutex::new(None)),
}
}

View file

@ -18,6 +18,6 @@ http = "0.2.4"
lazy_static = "1.4.0"
matrix-sdk-common = { version = "0.3.0", path = "../matrix_sdk_common" }
matrix-sdk-test-macros = { version = "0.1.0", path = "../matrix_sdk_test_macros" }
ruma = { version = "0.3.0", features = ["client-api-c"] }
ruma = { version = "0.4.0", features = ["client-api-c"] }
serde = "1.0.126"
serde_json = "1.0.64"