dvb-ci 0.15.0

DVB Common Interface (EN 50221) — APDU/resource objects, session/transport PDUs, and a CA_PMT builder from a dvb-si PMT.
Documentation
//! DVB Common Interface (CENELEC EN 50221): the host to CICAM wire protocol as
//! typed Rust. The crate parses and builds the transport (TPDU), session
//! (SPDU) and application (APDU) layers, the DVB CI extensions (ETSI TS 101 699)
//! and the CI Plus extension APDUs (ETSI TS 103 205), and builds the `ca_pmt`
//! object a host hands to a Conditional Access Module from a `dvb-si` PMT.
//!
//! It builds on `broadcast-core` (the `Parse`/`Serialize` contract),
//! `broadcast-common`, `dvb-si` (the PMT and `CA_descriptor`) and `mpeg-ts`
//! (`Pid`); `dvb-ci-runtime` drives real devices on top of it. The crate is
//! sans-IO and `no_std` + `alloc`: it never touches a device, implements no
//! CI Plus cryptography and is not a descrambler. Every object round-trips
//! byte for byte, including a non-minimal `length_field` a CAM sent.
//!
//! # Quickstart
//!
//! Build a `ca_info` APDU, then route it by its 3-byte tag without knowing the
//! type in advance:
//!
//! ```rust
//! use broadcast_core::Serialize;
//! use dvb_ci::AnyApdu;
//! use dvb_ci::length::LengthForm;
//! use dvb_ci::objects::ca_info::CaInfo;
//!
//! let info = CaInfo {
//!     length_form: LengthForm::Minimal,
//!     ca_system_ids: vec![0x0500, 0x0B00],
//! };
//! let wire = info.try_to_bytes()?;
//! assert_eq!(wire, [0x9F, 0x80, 0x31, 0x04, 0x05, 0x00, 0x0B, 0x00]);
//!
//! let any = AnyApdu::parse(&wire)?;
//! assert_eq!(any.name(), "CA_INFO");
//! assert_eq!(any.try_to_bytes()?, wire);
//! # Ok::<(), dvb_ci::Error>(())
//! ```
//!
//! # How do I...
//!
//! - Build a `ca_pmt` from a PMT: [`builder::build_ca_pmt`],
//!   `examples/build_ca_pmt.rs`.
//! - Restrict a `ca_pmt` to the CAM's advertised CA system ids:
//!   [`builder::build_ca_pmt_for_caids`], no example yet.
//! - Parse any application object by tag and re-serialize it: [`AnyApdu`],
//!   `examples/parse_apdu.rs`.
//! - Frame APDUs in a session and find where the body starts:
//!   [`spdu::SessionNumber`], `examples/session_apdu.rs`.
//! - Open a session for a resource: [`spdu::OpenSessionRequest`],
//!   `examples/session_apdu.rs`.
//! - Identify a resource and tell extension resources apart:
//!   [`ResourceId`], [`ci_ext::classify`], `examples/session_apdu.rs`.
//! - Parse a TS 101 699 extension APDU (tags collide, so the resource id comes
//!   first): [`ci_ext::CiExtApdu`], no example yet.
//! - Parse a CI Plus APDU: [`ci_plus::CiPlusApdu`], no example yet.
//! - Frame a transport command or response: [`tpdu::CommandTpdu`],
//!   [`tpdu::ResponseTpdu`], no example yet.
//!
//! # Modules
//!
//! Application layer: [`objects`] (EN 50221 resource objects: Resource Manager,
//! Application Information, CA Support, Date-Time, Host Control, MMI,
//! Low-Speed Communications), [`any`] (unified tag dispatch), [`tag`] (the
//! 3-byte `apdu_tag`), [`traits`] (the dispatch trait), [`builder`] (`ca_pmt`
//! from a PMT).
//!
//! Extension resources: [`ci_ext`] (ETSI TS 101 699, dispatched by resource
//! id), [`ci_plus`] (ETSI TS 103 205, dispatched by resource id).
//!
//! Lower layers and framing: [`spdu`] (session objects), [`tpdu`] (transport
//! objects), [`length`] (the ASN.1 `length_field` with its coding form
//! preserved), [`resource`] (the 4-octet resource identifier).
//!
//! Shared vocabulary: [`error`] (typed errors).
//!
//! # Feature flags
//!
//! - `std` (default): links `std` and the siblings' `std`; off gives
//!   `no_std` + `alloc`.
//! - `serde`: `serde::Serialize` on the public types (not the preserved
//!   `length_form` or reserved bits).
//!
//! # Spec citations
//!
//! CENELEC EN 50221 (February 1997): section 7 and Table 1 (`length_field`),
//! section 7.2.4 to 7.2.7 (SPDU), Annex A.4.1 (TPDU), section 8.2.2
//! (`resource_identifier`), section 8.4.3.4 (`ca_pmt`), section 8.8.2 and Table
//! 58 (`apdu_tag`); ETSI TS 101 699 V1.1.1 section 8 and Table 87; ETSI
//! TS 103 205 V1.4.1; transcriptions under
//! `private/specs-verified/dvb/dvb-ci/`.
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![deny(missing_docs)]

extern crate alloc;

#[cfg(doctest)]
#[doc = include_str!("../README.md")]
struct ReadmeDoctests;

pub mod any;
pub mod builder;
pub mod ci_ext;
pub mod ci_plus;
mod dispatch;
pub mod error;
pub mod length;
pub mod objects;
pub mod resource;
#[cfg(test)]
mod roundtrip_property;
pub mod spdu;
#[cfg(test)]
mod strict_tests;
pub mod tag;
pub mod tpdu;
pub mod traits;

pub use any::AnyApdu;
pub use error::{Error, Result};
pub use resource::ResourceId;
pub use tag::ApduTag;
pub use traits::ApduDef;