Skip to content

Nom41 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = "https://github.com/rusticata/ipsec-parser"
repository = "https://github.com/rusticata/ipsec-parser.git"
documentation = "https://docs.rs/ipsec-parser"
name = "ipsec-parser"
version = "0.3.0"
version = "0.4.0"
authors = ["Pierre Chifflier <[email protected]>"]
categories = ["parsing"]

Expand All @@ -20,7 +20,7 @@ include = [
]

[dependencies]
nom = "4.0"
nom = "4.1"
rusticata-macros = "1.0"

[badges]
Expand Down
25 changes: 11 additions & 14 deletions src/esp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use nom::{IResult,be_u32,rest};
use ikev2::IkeV2Header;
use ikev2_parser::parse_ikev2_header;
use crate::ikev2::IkeV2Header;
use crate::ikev2_parser::parse_ikev2_header;
use nom::{be_u32, rest, IResult};

/// Encapsulating Security Payload Packet Format
///
Expand All @@ -9,7 +9,7 @@ use ikev2_parser::parse_ikev2_header;
pub struct ESPHeader<'a> {
pub spi_index: &'a [u8],
pub seq: u32,
pub data: &'a[u8]
pub data: &'a [u8],
}

/// UDP-encapsulated Packet Formats
Expand All @@ -21,15 +21,14 @@ pub enum ESPData<'a> {
IKE(IkeV2Header),
}


/// Parse an encapsulated ESP packet
///
/// The type of encapsulated data depends on the first field (`spi_index`): 0 is a forbidden SPI
/// index, and indicates that the header is an IKE header.
/// Any other value indicates an ESP header.
///
/// *Note: input is entirely consumed*
pub fn parse_esp_encapsulated<'a>(i: &'a[u8]) -> IResult<&'a[u8],ESPData<'a>> {
pub fn parse_esp_encapsulated<'a>(i: &'a [u8]) -> IResult<&'a [u8], ESPData<'a>> {
if peek!(i, be_u32)?.1 == 0 {
parse_ikev2_header(i).map(|x| (x.0, ESPData::IKE(x.1)))
} else {
Expand All @@ -46,18 +45,16 @@ pub fn parse_esp_encapsulated<'a>(i: &'a[u8]) -> IResult<&'a[u8],ESPData<'a>> {
/// - the payload data (which can be encrypted)
///
/// *Note: input is entirely consumed*
pub fn parse_esp_header<'a>(i: &'a[u8]) -> IResult<&'a[u8],ESPHeader<'a>> {
pub fn parse_esp_header<'a>(i: &'a [u8]) -> IResult<&'a [u8], ESPHeader<'a>> {
do_parse!(
i,
spi_index: take!(4) >>
seq: be_u32 >>
data: rest >>
(
ESPHeader{
spi_index: take!(4)
>> seq: be_u32
>> data: rest
>> (ESPHeader {
spi_index: spi_index,
seq: seq,
data: data
}
)
})
)
}
Loading