ipsec_parser/lib.rs
1//! # IPsec parsers
2//!
3//! This crate contains several parsers using for IPsec: IKEv2, and reading the envelope of ESP
4//! encapsulated messages.
5//! This parser provides the base functions to read and analyze messages, but does not handle the
6//! interpretation of messages.
7//!
8//! ESP is supported, but only to read the envelope of the payload.
9//!
10//! Encapsulated ESP is supported, to differentiate between IKE and ESP headers.
11//!
12//! # IKEv2 parser
13//!
14//! An IKEv2 (RFC7296) parser, implemented with the [nom](https://github.com/Geal/nom)
15//! parser combinator framework.
16//!
17//! The code is available on [Github](https://github.com/rusticata/ipsec-parser)
18//! and is part of the [Rusticata](https://github.com/rusticata) project.
19//!
20//! To parse an IKE packet, first read the header using `parse_ikev2_header`, then use the type
21//! from the header to parse the remaining part:
22//!
23//!
24//! ```rust
25//! # extern crate nom;
26//! # extern crate ipsec_parser;
27//! use ipsec_parser::*;
28//! use nom::IResult;
29//!
30//! static IKEV2_INIT_RESP: &'static [u8] = include_bytes!("../assets/ike-sa-init-resp.bin");
31//!
32//! # fn main() {
33//! fn test_ikev2_init_resp() {
34//! let bytes = IKEV2_INIT_RESP;
35//! match parse_ikev2_header(&bytes) {
36//! Ok( (rem, ref hdr) ) => {
37//! match parse_ikev2_payload_list(rem,hdr.next_payload) {
38//! Ok( (_, Ok(ref p)) ) => {
39//! // p is a list of payloads
40//! // first one is always dummy
41//! assert!(p.len() > 0);
42//! assert_eq!(p[0].content, IkeV2PayloadContent::Dummy);
43//! for payload in p {
44//! match payload.content {
45//! IkeV2PayloadContent::SA(ref sa) => { /* .. */ },
46//! _ => ()
47//! }
48//! }
49//! },
50//! e => { eprintln!("Parsing payload failed: {:?}", e); },
51//! }
52//! },
53//! _ => { eprintln!("Parsing header failed"); },
54//! }
55//! }
56//! # }
57//! ```
58
59#![deny(/*missing_docs,*/
60 unstable_features,
61 unused_import_braces, unused_qualifications)]
62#![forbid(unsafe_code)]
63
64mod error;
65mod esp;
66mod ikev2;
67mod ikev2_debug;
68mod ikev2_notify;
69mod ikev2_parser;
70mod ikev2_transforms;
71pub use error::*;
72pub use esp::*;
73pub use ikev2::*;
74pub use ikev2_debug::*;
75pub use ikev2_notify::*;
76pub use ikev2_parser::*;
77pub use ikev2_transforms::*;
78
79// re-export modules
80pub use nom;