aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid LeGare <legare@google.com>2022-03-02 16:21:08 +0000
committerDavid LeGare <legare@google.com>2022-03-02 16:21:08 +0000
commite64d134356a9720c1440275aa448841d0c6f2c20 (patch)
tree8dfc14e9819e551f9f5823e28ea764cabe9b7ca7
parent3575b7b4283cced6f92f84967c94dd4c4125075f (diff)
downloadrusticata-macros-e64d134356a9720c1440275aa448841d0c6f2c20.tar.gz
Update rusticata-macros to 4.1.0
Test: cd external/rust/crates && atest --host -c Change-Id: I64f98114c8c162776ef2c617e351bc1ec3a8980d
-rw-r--r--.cargo_vcs_info.json7
-rw-r--r--Android.bp4
-rw-r--r--Cargo.toml11
-rw-r--r--Cargo.toml.orig2
-rw-r--r--METADATA10
-rw-r--r--README.md22
-rw-r--r--src/combinator.rs4
-rw-r--r--src/lib.rs12
-rw-r--r--src/macros.rs55
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
diff --git a/Android.bp b/Android.bp
index 02cb373..412407c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -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,
diff --git a/Cargo.toml b/Cargo.toml
index def8c45..6c9bccf 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"]
diff --git a/METADATA b/METADATA
index 7793cf9..d87a4ea 100644
--- a/METADATA
+++ b/METADATA
@@ -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
}
}
diff --git a/README.md b/README.md
index 42cd1fd..0232006 100644
--- a/README.md
+++ b/README.md
@@ -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};
diff --git a/src/lib.rs b/src/lib.rs
index 119ea48..8d23249 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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);