Home

Awesome

Rust Uniform Resources

<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/dspicher/ur-rs/rust.yml?branch=master&logo=github" height="20"> <img alt="build status" src="https://img.shields.io/codecov/c/gh/dspicher/ur-rs?logo=codecov" height="20"> <img alt="build status" src="https://img.shields.io/crates/v/ur.svg" height="20"> dependency status

<!-- cargo-rdme start -->

ur is a crate to interact with uniform resource encodings of binary data. The encoding scheme is optimized for transport in URIs and QR codes.

The [ur::Encoder] allows a byte payload to be transmissioned in multiple stages, respecting maximum size requirements. Under the hood, a fountain encoder is used to create an unbounded stream of URIs, subsets of which can be recombined at the receiving side into the payload:

let data = String::from("Ten chars!").repeat(10);
let max_length = 5;
let mut encoder = ur::Encoder::bytes(data.as_bytes(), max_length).unwrap();
let part = encoder.next_part().unwrap();
assert_eq!(
    part,
    "ur:bytes/1-20/lpadbbcsiecyvdidatkpfeghihjtcxiabdfevlms"
);
let mut decoder = ur::Decoder::default();
while !decoder.complete() {
    let part = encoder.next_part().unwrap();
    // Simulate some communication loss
    if encoder.current_index() & 1 > 0 {
        decoder.receive(&part).unwrap();
    }
}
assert_eq!(decoder.message().unwrap().as_deref(), Some(data.as_bytes()));

The following useful building blocks are also part of the public API:

<!-- cargo-rdme end -->

Usage

Add ur to the dependencies of your Cargo.toml:

cargo add ur

Examples

Animated QR code

To run this example, execute

cargo run --example qr -- "This is my super awesome UR payload"

which will print out URIs and QR codes transmitting the provided payload.

Background: Uniform Resources

Uniform Resources are

a proposed method of encoding binary data of arbitrary content and length so that it is suitable for transport in either URIs or QR codes.

The resulting constraints on the permissible encoding alphabet are nicely analyzed here.

The following building blocks interact to achieve this goal:

Other implementations

This Rust implementation, in particular its test vectors, is based on the following reference implementations:

Contributing

Pull requests are welcome.

License

This project is licensed under the terms of the MIT license.