Skip to main content

Crate tightbeam_asn

Crate tightbeam_asn 

Source
Expand description

§tightbeam-asn

#[derive(AsnCodec)] on der DER types, plus tightbeam-asn-emit to generate TypeScript MessageCodec modules for tightbeam.

§Status

This project is under active development. Public APIs MAY change without notice. No security audit has been conducted. Use this software at your own risk.

§Abstract

A Rust DER type that derives AsnCodec gains wasm exports that encode and decode it as DER (ITU-T X.690) from a plain JavaScript value. tightbeam-asn-emit reads the .d.ts that wasm-pack writes and generates a typed MessageCodec for each DER type, so a TypeScript peer of the tightbeam WebSocket client sends the same message schema as a Rust peer.

docs/asn.md names the suite that compiles the quick-start TypeScript sample.

§Install

cargo add tightbeam-asn
cargo install tightbeam-asn --features emit

§Quick start

After wasm-pack build --target web, scan the wasm .d.ts and write codecs.ts:

tightbeam-asn-emit \
	--from-dts path/to/package.d.ts \
	--out path/to/codecs.ts \
	--import '#your-asn-alias'

Then build the codecs from the wasm module and the output of its init:

import init, * as asn from "#your-asn-alias";
import { AsnCodecs } from "./codecs.js";

const codecs = new AsnCodecs(asn, await init());
const bodyDer = codecs.Doc.encode({ title: "hello" });

A --target nodejs build initializes on import, so its AsnCodecs takes the exports alone: new AsnCodecs(asn).

§Derive

The derive covers Sequence structs, Enumerated enums, and Choice enums, and it refuses at compile time each shape in which DER would erase a None. Implementation: docs/asn.md.

§Field map

Each der field type maps to one TypeScript type, and the generated exports check every value against it. Implementation: docs/asn.md.

§Emit

The emitter writes one AsnCodecs class with a MessageCodec for each DER type, typed so that tsc checks each codec. Implementation: docs/asn.md.

§Errors

A generated export throws a TypeError that names the field by its path, or the error of der for bytes that are not DER. Implementation: docs/asn.md.

§License

Licensed under either of MIT or Apache-2.0 at your option.

Re-exports§

pub use der;

Structs§

FieldError
A value that does not fit its DER type, named by its path in the message.

Traits§

AsnCodec
A der type with codec exports for TypeScript, which the derive implements: docs/asn.md.

Derive Macros§

AsnCodec
Marks a der type as a codec for TypeScript.