aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid LeGare <legare@google.com>2022-03-04 22:46:01 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-03-04 22:46:01 +0000
commit8165afcc0ef04ff844efb207708732f315a696e4 (patch)
tree8dfc14e9819e551f9f5823e28ea764cabe9b7ca7
parentdb480a77f29a691c8e84270bc79eb8984220c661 (diff)
parentb31c7fdb2703a87dba0c72809e58720aa5dbe7b0 (diff)
downloadrusticata-macros-8165afcc0ef04ff844efb207708732f315a696e4.tar.gz
Update rusticata-macros to 4.1.0 am: e64d134356 am: c0669d4c62 am: b5e53d3c92 am: b31c7fdb27aml_wif_331910020aml_wif_331810010aml_wif_331710030aml_wif_331613000aml_wif_331511020aml_wif_331414000aml_wif_331310070aml_wif_331112000aml_wif_331016070aml_wif_330910030aml_wif_330810040aml_uwb_331910010aml_uwb_331820070aml_uwb_331613010aml_uwb_331611010aml_uwb_331410010aml_uwb_331310030aml_uwb_331115000aml_uwb_331015040aml_uwb_330810010aml_tz4_332714070aml_tz4_332714050aml_tz4_332714010aml_tz4_331910000aml_tz4_331314030aml_tz4_331314020aml_tz4_331314010aml_tz4_331012050aml_tz4_331012040aml_tz4_331012000aml_tet_331910040aml_tet_331820050aml_tet_331711040aml_tet_331511160aml_tet_331511000aml_tet_331412030aml_tet_331312080aml_tet_331117000aml_tet_331012080aml_tet_330911010aml_tet_330812150aml_swc_331911000aml_swc_331712000aml_swc_331612000aml_swc_331511000aml_swc_331410000aml_swc_331318000aml_swc_331116000aml_swc_331012020aml_sta_331910000aml_sta_331811000aml_sta_331711010aml_sta_331610000aml_sta_331511000aml_sta_331410000aml_sta_331311000aml_sta_331010010aml_sta_330910000aml_sdk_331812000aml_sdk_331811100aml_sdk_331811000aml_sdk_331412000aml_sdk_331410000aml_sdk_331310010aml_sdk_331111000aml_sdk_330810050aml_sdk_330810010aml_sch_331113000aml_sch_331111000aml_res_331820000aml_res_331611010aml_res_331512000aml_res_331314010aml_res_331114000aml_res_331011050aml_res_330910000aml_res_330810000aml_per_331913010aml_per_331812030aml_per_331710050aml_per_331611010aml_per_331512020aml_per_331411000aml_per_331313010aml_per_331115020aml_per_331019040aml_per_330912010aml_per_330811030aml_neu_331310000aml_neu_331113000aml_net_331910030aml_net_331812010aml_net_331710000aml_net_331610000aml_net_331412000aml_net_331313030aml_net_331313010aml_net_331110020aml_net_331011030aml_net_330910010aml_net_330811010aml_mpr_331918000aml_mpr_331812020aml_mpr_331711020aml_mpr_331613010aml_mpr_331512020aml_mpr_331412040aml_mpr_331311080aml_mpr_331112050aml_mpr_331112030aml_mpr_331011070aml_mpr_330911040aml_mpr_330811020aml_med_331911000aml_med_331712010aml_med_331612000aml_med_331511000aml_med_331410000aml_med_331318000aml_med_331115000aml_med_331012020aml_ips_331910010aml_ips_331312000aml_ips_331310000aml_ips_331111030aml_ips_331014020aml_ext_331814220aml_ext_331412000aml_ext_331312000aml_ext_331112010aml_ext_331012020aml_doc_331120000aml_con_331413000aml_con_331411000aml_con_331312000aml_con_331115000aml_con_331011010aml_cbr_331910000aml_cbr_331810000aml_cbr_331710020aml_cbr_331610010aml_cbr_331510000aml_cbr_331411000aml_cbr_331310010aml_cbr_331111030aml_cbr_331013010aml_cbr_330911010aml_cbr_330810000aml_ase_331311020aml_ase_331112000aml_ase_331011020aml_art_331813100aml_art_331813010aml_art_331711080aml_art_331612010aml_art_331413030aml_art_331314010aml_art_331113000aml_art_331012050aml_adb_331610000aml_adb_331314020aml_adb_331113120aml_adb_331011050aml_adb_331011040android13-mainline-wifi-releaseandroid13-mainline-uwb-releaseandroid13-mainline-tzdata4-releaseandroid13-mainline-tethering-releaseandroid13-mainline-sdkext-releaseandroid13-mainline-scheduling-releaseandroid13-mainline-resolv-releaseandroid13-mainline-permission-releaseandroid13-mainline-os-statsd-releaseandroid13-mainline-networking-releaseandroid13-mainline-mediaprovider-releaseandroid13-mainline-media-swcodec-releaseandroid13-mainline-media-releaseandroid13-mainline-ipsec-releaseandroid13-mainline-extservices-releaseandroid13-mainline-conscrypt-releaseandroid13-mainline-cellbroadcast-releaseandroid13-mainline-art-releaseandroid13-mainline-appsearch-releaseandroid13-mainline-adbd-releaseaml_tz4_332714010
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/rusticata-macros/+/2005935 Change-Id: I27210d6549199784bab56f677db46a86d6a5c1de
-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);