2021-06-22 12:20:25 +00:00
|
|
|
**matrix-qrcode** is a crate to easily generate and parse QR codes for
|
|
|
|
interactive verification using [QR codes] in Matrix.
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
This is probably not the crate you are looking for, it's used internally in the
|
2021-09-09 18:26:09 +00:00
|
|
|
[matrix-sdk].
|
2021-06-22 12:20:25 +00:00
|
|
|
|
|
|
|
If you still want to play with QR codes, here are a couple of helpful examples.
|
|
|
|
|
|
|
|
### Decode an image
|
|
|
|
|
2021-09-09 18:26:09 +00:00
|
|
|
```rust,no_run
|
2021-06-22 12:20:25 +00:00
|
|
|
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
|
|
|
|
|
2021-09-09 18:26:09 +00:00
|
|
|
```rust,no_run
|
2021-06-22 12:20:25 +00:00
|
|
|
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::<Luma<u8>>().build();
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-09-09 18:26:09 +00:00
|
|
|
[matrix-sdk]: https://github.com/matrix-org/matrix-rust-sdk/
|
|
|
|
[QR codes]: https://spec.matrix.org/unstable/client-server-api/#qr-codes
|