sciparse/lib.rs
1// Copyright 2026 Anapaya Systems
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! # SciParse: Zero-Copy SCION Packets
16//!
17//! This library provides functionality to parse and construct SCION packets.
18//!
19//! Parsing is performed via zero-copy views over byte buffers, providing direct
20//! field access without allocation or data transformation, and with only the
21//! validation required to uphold safety.
22//!
23//! The library is designed to be efficient and flexible, allowing users to work
24//! with SCION packets in a straightforward manner.
25//!
26//! SciParse exposes both view-based and model-based representations of SCION packets.
27//!
28//! ## Overview
29//!
30//! * [SCION Packet Types](proto::packet) - SCION packet parsing and construction
31//! * [SCION Path Types](proto::dataplane_path) - SCION path parsing and construction
32//! * [SCION Header Types](proto::header) - SCION header parsing and construction
33//!
34//! ## Views
35//!
36//! Detailed docs: [view](core::view)
37//!
38//! Views are zero-copy projections over byte buffers.
39//!
40//! A view provides read access and limited write access to SCION packet fields
41//! directly on the underlying buffer, with minimal overhead.
42//!
43//! Views do not support modification of dynamically sized fields
44//! (e.g., addresses, path segments).
45//!
46//! Most relevant structs include:
47//!
48//! * [ScionRawPacketView](proto::packet::view::ScionRawPacketView)
49//! * [ScionUdpPacketView](proto::packet::view::ScionUdpPacketView)
50//! * [ScionHeaderView](proto::header::view::ScionHeaderView)
51//! * [ScionDpPathView](proto::dataplane_path::view::ScionDpPathView)
52//! * [StandardPathView](proto::dataplane_path::standard::view::StandardPathView)
53//! * [OneHopPathView](proto::dataplane_path::onehop::view::OneHopPathView)
54//!
55//!
56//! Most views can be parsed from byte buffers using the [View](crate::core::view::View) trait,
57//! which performs the necessary validation to ensure that the view is safe to use.
58//!
59//! ```no_run
60//! # use sciparse::packet::view::ScionRawPacketView;
61//! # use sciparse::core::view::View;
62//! let buf: Vec<u8> = vec![/* ... */]; // Buffer containing a SCION packet
63//! let packet_view = ScionRawPacketView::try_from_slice(&buf[..]).expect("Failed to parse SCION packet");
64//!
65//! println!("Parsed view: {:?}", packet_view);
66//! ```
67//!
68//! The View trait also supplies functions for mutable slices, and boxed buffers, as well as unsafe
69//! functions for unchecked parsing when the caller can guarantee the validity of the buffer.
70//!
71//! There are some exceptions where views require information found in other parts of the packet,
72//! which can not implement the View trait directly.
73//!
74//! ## Models
75//!
76//! Models represent SCION packets as structured Rust types.
77//!
78//! They are intended for constructing new packets or performing complex
79//! modifications that are impractical or unsafe using views alone.
80//!
81//! Most relevant structs include:
82//! * [ScionRawPacket](proto::packet::model::ScionRawPacket)
83//! * [ScionUdpPacket](proto::packet::model::ScionUdpPacket)
84//! * [ScionHeader](proto::header::model::ScionPacketHeader)
85//! * [DpPath](proto::dataplane_path::model::DpPath)
86//! * [StandardPath](proto::dataplane_path::standard::model::StandardPath)
87//! * [OneHopPath](proto::dataplane_path::onehop::model::OneHopPath)
88//!
89//! Models allow creating new packets from scratch.
90//!
91//! Most models can also be created from views or from byte buffers directly, which load the
92//! relevant fields of a SCION packet into Rust types.
93//!
94//! ```no_run
95//! # use sciparse::packet::model::ScionRawPacket;
96//! # use sciparse::core::convert::TryFromView;
97//! # let buf: Vec<u8> = vec![/* ... */]; // Buffer containing a SCION packet
98//! let model = ScionRawPacket::try_from_slice(&buf[..]).expect("Failed to parse SCION packet");
99//!
100//! println!("Parsed model: {:?}", model);
101//! ```
102//!
103//!
104//! ## Control Plane Primitives
105//!
106//! In addition to dataplane packet parsing and construction, SciParse also provides primitives for
107//! working with SCION control plane messages, such as path segments and beacons.
108
109/// Core traits and utilities for working with bit-level data
110pub mod core;
111
112mod proto;
113pub use proto::*;
114
115mod scion;
116pub use scion::*;
117
118pub mod util;
119
120/// Re-exports of dependencies for users of this library
121pub mod reexport {
122 pub use p256;
123 #[cfg(feature = "proptest")]
124 pub use proptest;
125 pub use prost;
126 pub use prost_types;
127 pub use scion_protobuf as protobuf;
128 pub use tinyvec;
129}