diff options
-rw-r--r-- | .cargo_vcs_info.json | 7 | ||||
-rw-r--r-- | Android.bp | 4 | ||||
-rw-r--r-- | Cargo.toml | 11 | ||||
-rw-r--r-- | Cargo.toml.orig | 2 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | README.md | 22 | ||||
-rw-r--r-- | src/combinator.rs | 4 | ||||
-rw-r--r-- | src/lib.rs | 12 | ||||
-rw-r--r-- | src/macros.rs | 55 |
9 files changed, 38 insertions, 89 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 5809fb6..227e97d 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,6 @@ { "git": { - "sha1": "d0e0ab4cb4e060c37bfcbb0c2eebe1325186cad6" - } -} + "sha1": "d6b00e821e9148bada1aa4eccc29a5948dc4ab23" + }, + "path_in_vcs": "" +}
\ No newline at end of file @@ -44,7 +44,7 @@ rust_library { host_supported: true, crate_name: "rusticata_macros", cargo_env_compat: true, - cargo_pkg_version: "4.0.0", + cargo_pkg_version: "4.1.0", srcs: ["src/lib.rs"], edition: "2018", rustlibs: [ @@ -57,7 +57,7 @@ rust_test { host_supported: true, crate_name: "rusticata_macros", cargo_env_compat: true, - cargo_pkg_version: "4.0.0", + cargo_pkg_version: "4.1.0", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -3,17 +3,16 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies +# to registry (e.g., crates.io) dependencies. # -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "rusticata-macros" -version = "4.0.0" +version = "4.1.0" authors = ["Pierre Chifflier <chifflier@wzdftpd.net>"] description = "Helper macros for Rusticata" homepage = "https://github.com/rusticata/rusticata-macros" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 983518e..cb377fc 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "rusticata-macros" -version = "4.0.0" +version = "4.1.0" description = "Helper macros for Rusticata" license = "MIT/Apache-2.0" keywords = ["parser","nom","serialize"] @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/rusticata-macros/rusticata-macros-4.0.0.crate" + value: "https://static.crates.io/crates/rusticata-macros/rusticata-macros-4.1.0.crate" } - version: "4.0.0" + version: "4.1.0" license_type: NOTICE last_upgrade_date { - year: 2021 - month: 9 - day: 22 + year: 2022 + month: 3 + day: 1 } } @@ -14,18 +14,16 @@ Helper macros for the [rusticata](https://github.com/rusticata) project. This crate contains some additions to [nom](https://github.com/Geal/nom). -For example, the `error_if!` macro allows to test a condition and return an error from the parser if the condition -fails: +For example, the [`combinator::cond_else`] function allows to apply the first parser if the +condition is true, and the second if the condition is false: ```rust -use rusticata_macros::error_if; -let r : IResult<&[u8],()> = do_parse!( - s, - l: be_u8 >> - error_if!(l < 4, ErrorKind::Verify) >> - data: take!(l - 4) >> - (()) - ); +use rusticata_macros::combinator::cond_else; +let r: IResult<_, _, ()> = cond_else( + || s.len() > 1, + be_u16, + map(be_u8, u16::from) + )(s); ``` See the documentation for more details and examples. @@ -48,6 +46,10 @@ Reference documentation can be found [here](https://docs.rs/rusticata-macros/) ## Changes +### 4.1.0 + +- Remove macro `slice_fixed` + ### 4.0.0 - Upgrade to nom 7 diff --git a/src/combinator.rs b/src/combinator.rs index d542557..6b6a8b3 100644 --- a/src/combinator.rs +++ b/src/combinator.rs @@ -2,8 +2,8 @@ use nom::bytes::streaming::take; use nom::combinator::map_parser; -pub use nom::error::{make_error, ErrorKind, ParseError}; -pub use nom::{IResult, Needed, Parser}; +use nom::error::{make_error, ErrorKind, ParseError}; +use nom::{IResult, Needed, Parser}; use nom::{InputIter, InputTake}; use nom::{InputLength, ToUsize}; @@ -4,7 +4,7 @@ //! //! This crate contains some additions to [nom](https://github.com/Geal/nom). //! -//! For example, the [`cond_else`] function allows to apply the first parser if the +//! For example, the [`combinator::cond_else`] function allows to apply the first parser if the //! condition is true, and the second if the condition is false: //! //! ```rust @@ -31,16 +31,14 @@ unused_qualifications )] -extern crate nom; - -extern crate core; - pub mod combinator; - +pub mod debug; pub use macros::*; #[macro_use] pub mod macros; -pub mod debug; mod traits; pub use traits::*; + +// re-exports +pub use nom; diff --git a/src/macros.rs b/src/macros.rs index 6109162..9ff2f69 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -2,8 +2,7 @@ use nom::bytes::complete::take; use nom::combinator::map_res; -pub use nom::error::{make_error, ErrorKind, ParseError}; -pub use nom::{IResult, Needed}; +use nom::IResult; #[doc(hidden)] pub mod export { @@ -142,29 +141,6 @@ pub fn parse_uint24(i: &[u8]) -> IResult<&[u8], u64> { //named!(parse_hex4<&[u8], u64>, parse_hex_to_u64!(4)); -/// Parse a slice and return a fixed-sized array of bytes -/// -/// This creates a copy of input data -/// Uses unsafe code -#[macro_export] -macro_rules! slice_fixed( - ( $i:expr, $count:expr ) => ( - { - let cnt = $count; - let ires: IResult<_,_> = if $i.len() < cnt { - Err(::nom::Err::Incomplete(Needed::new(cnt))) - } else { - let mut res: [u8; $count] = unsafe { - $crate::export::mem::MaybeUninit::uninit().assume_init() - }; - unsafe{$crate::export::ptr::copy($i.as_ptr(), res.as_mut_ptr(), cnt)}; - Ok((&$i[cnt..],res)) - }; - ires - } - ); -); - /// Combination and flat_map! and take! as first combinator #[macro_export] macro_rules! flat_take ( @@ -260,37 +236,10 @@ macro_rules! align32 { #[cfg(test)] mod tests { use nom::error::ErrorKind; - use nom::number::streaming::{be_u16, be_u32, be_u8}; + use nom::number::streaming::{be_u16, be_u32}; use nom::{error_position, Err, IResult, Needed}; #[test] - #[allow(unsafe_code)] - fn test_slice_fixed() { - let empty = &b""[..]; - let b = &[0x01, 0x02, 0x03, 0x04, 0x05]; - - let res = slice_fixed!(b, 4); - assert_eq!(res, Ok((&b[4..], [1, 2, 3, 4]))); - - // can we still use the result ? - match res { - Ok((rem, _)) => { - let res2: IResult<&[u8], u8> = be_u8(rem); - assert_eq!(res2, Ok((empty, 5))); - } - _ => (), - } - } - - #[test] - #[allow(unsafe_code)] - fn test_slice_fixed_incomplete() { - let b = &[0x01, 0x02, 0x03, 0x04, 0x05]; - let res = slice_fixed!(b, 8); - assert_eq!(res, Err(Err::Incomplete(Needed::new(8)))); - } - - #[test] fn test_error_if() { let empty = &b""[..]; let res: IResult<&[u8], ()> = error_if!(empty, true, ErrorKind::Tag); |