Skip to main content

Crate bcur

Crate bcur 

Source
Expand description

bcur — a Rust implementation of Uniform Resources.

§Features

Core transport always requires alloc and supports no_std via --no-default-features.

§Layering

L0–L3 (always built). A UR type token is a validated label ([a-z0-9-]+ after ASCII lowercasing). The body is raw bytes plus bytewords CRC. ur::encode / ur::Encoder do not parse or require CBOR, so generic hosts and tests can move opaque payloads; this split matches ur-rs.

BCR-2020-005 says a UR message MUST be dCBOR and that type bytes MUST NOT be used except for testing. That MUST is enforced on L4 (feature = "dcbor"): FromStr for typed::Ur and TryFrom<ur::Decoded> for typed::Ur reject non-dCBOR (ErrorKind::CborDecode). L4 also uses the first registered dcbor tag name as the type token and strips the tag from the UR body (005 “top-level UR is untagged”).

Registry types (seed, hdkey, PSBT, …) are not part of this crate; application types implement UrEncodable / UrDecodable.

§Example

L3 transport (opaque bytes + type token):

use bcur::fountain::EncoderOptions;
use bcur::ur::{Decoder, Encoder};
use bcur::{State, UrType};

let data = b"Ten chars!".repeat(10);
let mut encoder =
    Encoder::new(UrType::new("alpha").unwrap(), data.clone(), EncoderOptions::new(10)).unwrap();
let mut decoder = Decoder::default();
for frame in encoder.by_ref() {
    decoder.receive(&frame).unwrap();
    if matches!(decoder.state(), State::Complete(_)) {
        break;
    }
}
assert_eq!(decoder.into_decoded().unwrap().message(), data.as_slice());

Typed dCBOR (feature = "dcbor"):

use bcur::{Ur, ur_type};
let ur = Ur::new(ur_type!("test"), vec![1, 2, 3]);
assert_eq!(ur.to_string(), "ur:test/lsadaoaxjygonesw");

Re-exports§

pub use bytewords::Style;
pub use fountain::DecoderLimits;
pub use fountain::Part;
pub use fountain::Progress;
pub use fountain::Received;
pub use fountain::State;
pub use ur::UrType;
pub use typed::Ur;
pub use typed::UrDecodable;
pub use typed::UrEncodable;

Modules§

bytemoji
Bytemoji identifiers (BCR-2024-008): a 4-byte digest shown as four space-separated emoji from a fixed 256-entry table.
bytewords
Encode and decode payloads with the bytewords scheme.
fountain
Fountain (Luby-transform style) encoder and decoder for multi-part URs.
typed
Typed dCBOR Uniform Resources (feature = "dcbor", implies std).
ur
Uniform Resource encode/decode and multi-part fountain transport.

Macros§

ur_type
UR type literal validated at compile time: ur_type!("seed") expands to an inline const block, so an invalid token is a compile error.

Structs§

Error
Errors that can occur while encoding or decoding Uniform Resources.

Enums§

ErrorKind
The category of an Error, for matching and diagnostics.
Limit
Which decoder/encoder budget was exceeded.

Type Aliases§

Result
Result alias for bcur operations.