simulcrypt 0.1.0

DVB SimulCrypt (ETSI TS 103 197) head-end protocol: ECMG client, EMMG server, control words
Documentation
use std::time::Duration;

/// Error of the public API (`Simulcrypt`/`Service`).
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// The requested `(CasRef, ecm_pid)` pair overlaps two different live CW groups at once - an
    /// unresolvable conflict.
    #[error(
        "ecm_pid={ecm_pid} on this CAS is already bound to stream_id={stream_id} from a different CW group"
    )]
    CwGroupConflict {
        /// `ecm_pid` that caused the conflict.
        ecm_pid: u16,
        /// `stream_id` already bound to another group.
        stream_id: u16,
    },

    /// `open_service` joins a live group, but its `crypto_period` differs from the requested one.
    #[error(
        "crypto_period mismatch: the running CW group already uses {expected:?}, this call requested {actual:?}"
    )]
    CryptoPeriodMismatch {
        /// `crypto_period` the group already runs with.
        expected: Duration,
        /// `crypto_period` requested by this call.
        actual: Duration,
    },

    /// `CasRef` is not registered in this `Simulcrypt` (e.g. obtained from another instance).
    #[error("unknown CasRef")]
    UnknownCas,

    /// `ServiceConfig::cas` is empty - the service has nothing to work with.
    #[error("ServiceConfig.cas must not be empty")]
    EmptyService,

    /// `crypto_period` does not fit into the 16-bit `nominal_cp_duration` protocol field.
    #[error(
        "crypto_period {crypto_period:?} does not fit into the wire's hundred-millisecond nominal_cp_duration field"
    )]
    InvalidCryptoPeriod {
        /// The requested crypto period.
        crypto_period: Duration,
    },

    /// Failed to bind the EMMG listening socket.
    #[error("failed to bind EMMG listener: {0}")]
    EmmgBind(#[source] std::io::Error),

    /// Another CAS on the same EMMG port already uses this `channel_id`.
    #[error("EMMG channel_id={channel_id} is already used by another CAS on this port")]
    EmmgChannelInUse {
        /// The clashing `channel_id`.
        channel_id: u16,
    },
}