ocpp-kit 0.5.0

Open Charge Point Protocol (OCPP 1.6J, 2.0.1, 2.1) toolkit for Rust: typed messages, OCPP-J framing, a sans-I/O protocol engine, and transports for charging stations, CSMS and local controllers.
Documentation
//! The catalogues OCPP 2.x defines outside the JSON schemas.
//!
//! Part 2 — Appendices lists things two implementations have to agree on that no schema
//! carries: which security events exist and which of them are critical, what the standardized
//! device-model components and variables are called, and the standardized `reasonCode`
//! values. These modules reproduce that vocabulary — names, data types and criticality — so
//! it can be used and checked in code rather than transcribed from a PDF each time.
//!
//! Generated by `cargo xtask appendix` from OCPP 2.1 Part 2 — Appendices v2.1, and
//! [`security_events_1_6`] from the OCPP 1.6 Security Whitepaper edition 4, §8. The prose
//! descriptions are not reproduced; read them in the source documents.

pub mod components;
pub mod reason_codes;
pub mod security_events;
pub mod security_events_1_6;

pub use components::{ComponentKind, StandardComponent, StandardVariable};
pub use reason_codes::ReasonCode;
pub use security_events::SecurityEvent;

#[cfg(test)]
mod tests {

    /// 1.6 has its own event names and its own criticality (Whitepaper edition 4 §8).
    #[test]
    fn the_16_security_events_are_their_own_catalogue() {
        use super::security_events_1_6::SecurityEvent as Event16;
        assert_eq!(Event16::VARIANTS.len(), 21);
        assert!(!Event16::InvalidFirmwareSignature.is_critical());
        assert!(SecurityEvent::InvalidFirmwareSignature.is_critical());
        assert!(!Event16::FailedToAuthenticateAtCentralSystem.is_critical());
        assert!(Event16::InvalidTLSVersion.is_critical());
        assert_eq!(
            Event16::from_wire("InvalidCentralSystemCertificate"),
            Event16::InvalidCentralSystemCertificate
        );
    }
    use super::*;

    #[test]
    fn the_security_event_list_matches_the_appendix() {
        // The appendix's table has 21 rows.
        assert_eq!(SecurityEvent::VARIANTS.len(), 21);

        // The ones the specification marks critical are pushed to the CSMS, not just logged.
        assert!(SecurityEvent::TamperDetectionActivated.is_critical());
        assert!(SecurityEvent::InvalidCsmsCertificate.is_critical());
        assert!(SecurityEvent::FirmwareUpdated.is_critical());
        // …and the ones it does not are only logged.
        assert!(!SecurityEvent::InvalidMessages.is_critical());
        assert!(!SecurityEvent::AttemptedReplayAttacks.is_critical());
        assert!(!SecurityEvent::FailedToAuthenticateAtCsms.is_critical());
        assert!(!SecurityEvent::ReconfigurationOfSecurityParameters.is_critical());

        // A vendor-specific event is reported rather than quietly dropped.
        let vendor = SecurityEvent::from_wire("AcmeCabinetOpened");
        assert!(!vendor.is_known());
        assert!(vendor.is_critical());

        assert_eq!(SecurityEvent::critical().len(), 16);
    }

    #[test]
    fn standardized_components_carry_their_variables_types_and_units() {
        assert_eq!(components::COMPONENTS.len(), 74);

        let comm = components::component("OCPPCommCtrlr").expect("a controller component");
        assert_eq!(comm.kind, ComponentKind::Controller);
        assert!(
            comm.variables
                .iter()
                .any(|v| v.name == "RetryBackOffWaitMinimum")
        );
        // A wrapped name in the PDF must come out whole.
        assert!(
            comm.variables
                .iter()
                .any(|v| v.name == "NetworkProfileConnectionAttempts")
        );

        let heartbeat = components::variable("OCPPCommCtrlr", "HeartbeatInterval").unwrap();
        assert_eq!(heartbeat.data_type, Some("integer"));
        assert_eq!(heartbeat.unit, Some("s"));

        let evse = components::component("EVSE").expect("a physical component");
        assert_eq!(evse.kind, ComponentKind::Physical);
        // `Count[ChargingProfiles]` is a variable *instance*, not a name.
        let count = evse
            .variables
            .iter()
            .find(|v| v.name == "Count")
            .expect("Count");
        assert_eq!(count.instance, Some("ChargingProfiles"));

        assert!(components::component("NotAComponent").is_none());
    }

    #[test]
    fn reason_codes_come_from_the_appendix_and_stay_open() {
        assert!(ReasonCode::VARIANTS.len() >= 50);
        assert_eq!(ReasonCode::InvalidProfile.as_str(), "InvalidProfile");
        assert!(!ReasonCode::from_wire("SomethingVendorSpecific").is_known());
    }
}