From e7c7b63b6eca5105241716b18d0399466ba8af37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 22 Jun 2021 14:20:25 +0200 Subject: [PATCH] qrcode: Add a readme --- matrix_qrcode/README.md | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 matrix_qrcode/README.md diff --git a/matrix_qrcode/README.md b/matrix_qrcode/README.md new file mode 100644 index 00000000..9da0daeb --- /dev/null +++ b/matrix_qrcode/README.md @@ -0,0 +1,62 @@ +[![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. + +If you still want to play with QR codes, here are a couple of helpful examples. + + +### Decode an image + +```rust +use image; +use matrix_qrcode::{QrVerificationData, DecodingError}; + +fn main() -> Result<(), DecodingError> { + let image = image::open("/path/to/my/image.png").unwrap(); + let result = QrVerificationData::from_image(image)?; + + Ok(()) +} +``` + +### Encode into a QR code + +```rust +use matrix_qrcode::{QrVerificationData, DecodingError}; +use image::Luma; + +fn main() -> Result<(), DecodingError> { + let data = b"MATRIX\ + \x02\x02\x00\x07\ + FLOW_ID\ + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\ + BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\ + SHARED_SECRET"; + + let data = QrVerificationData::from_bytes(data)?; + let encoded = data.to_qr_code().unwrap(); + let image = encoded.render::>().build(); + + Ok(()) +} +``` + + +## License + +[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)