From a26f09d3565d78cea736c19fdeca42407f6e0baa Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Sat, 16 Mar 2024 20:54:39 +0100 Subject: [PATCH] feat: Resolve winnow + chrono deprecations (#70) --- rc-zip/src/parse/central_directory_file_header.rs | 4 ++-- rc-zip/src/parse/date_time.rs | 5 +---- rc-zip/src/parse/eocd.rs | 8 ++++---- rc-zip/src/parse/extra_field.rs | 4 ++-- rc-zip/src/parse/local_headers.rs | 6 +++--- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/rc-zip/src/parse/central_directory_file_header.rs b/rc-zip/src/parse/central_directory_file_header.rs index 4e72488..c5cc3c2 100644 --- a/rc-zip/src/parse/central_directory_file_header.rs +++ b/rc-zip/src/parse/central_directory_file_header.rs @@ -5,7 +5,7 @@ use tracing::trace; use winnow::{ binary::{le_u16, le_u32}, prelude::PResult, - token::{tag, take}, + token::{literal, take}, Parser, Partial, }; @@ -75,7 +75,7 @@ impl<'a> CentralDirectoryFileHeader<'a> { /// Parser for the central directory file header pub fn parser(i: &mut Partial<&'a [u8]>) -> PResult { - _ = tag(Self::SIGNATURE).parse_next(i)?; + _ = literal(Self::SIGNATURE).parse_next(i)?; let creator_version = Version::parser.parse_next(i)?; let reader_version = Version::parser.parse_next(i)?; let flags = le_u16.parse_next(i)?; diff --git a/rc-zip/src/parse/date_time.rs b/rc-zip/src/parse/date_time.rs index ac6d30c..53764b9 100644 --- a/rc-zip/src/parse/date_time.rs +++ b/rc-zip/src/parse/date_time.rs @@ -105,8 +105,5 @@ impl NtfsTimestamp { } pub(crate) fn zero_datetime() -> chrono::DateTime { - chrono::DateTime::from_naive_utc_and_offset( - chrono::naive::NaiveDateTime::from_timestamp_opt(0, 0).unwrap(), - chrono::offset::Utc, - ) + chrono::DateTime::::from_timestamp_millis(0).unwrap() } diff --git a/rc-zip/src/parse/eocd.rs b/rc-zip/src/parse/eocd.rs index afc5883..ddc6523 100644 --- a/rc-zip/src/parse/eocd.rs +++ b/rc-zip/src/parse/eocd.rs @@ -5,7 +5,7 @@ use tracing::trace; use winnow::{ binary::{le_u16, le_u32, le_u64, length_take}, seq, - token::tag, + token::literal, PResult, Parser, Partial, }; @@ -57,7 +57,7 @@ impl<'a> EndOfCentralDirectoryRecord<'a> { /// Parser for the end of central directory record pub fn parser(i: &mut Partial<&'a [u8]>) -> PResult { - let _ = tag(Self::SIGNATURE).parse_next(i)?; + let _ = literal(Self::SIGNATURE).parse_next(i)?; seq! {Self { disk_nbr: le_u16, dir_disk_nbr: le_u16, @@ -89,7 +89,7 @@ impl EndOfCentralDirectory64Locator { /// Parser for the zip64 end of central directory locator pub fn parser(i: &mut Partial<&'_ [u8]>) -> PResult { - _ = tag(Self::SIGNATURE).parse_next(i)?; + _ = literal(Self::SIGNATURE).parse_next(i)?; seq! {Self { dir_disk_number: le_u32, directory_offset: le_u64, @@ -136,7 +136,7 @@ impl EndOfCentralDirectory64Record { /// Parser for the zip64 end of central directory record pub fn parser(i: &mut Partial<&'_ [u8]>) -> PResult { - _ = tag(Self::SIGNATURE).parse_next(i)?; + _ = literal(Self::SIGNATURE).parse_next(i)?; seq! {Self { record_size: le_u64, creator_version: le_u16, diff --git a/rc-zip/src/parse/extra_field.rs b/rc-zip/src/parse/extra_field.rs index 2f4d443..9559c07 100644 --- a/rc-zip/src/parse/extra_field.rs +++ b/rc-zip/src/parse/extra_field.rs @@ -7,7 +7,7 @@ use winnow::{ combinator::{opt, preceded, repeat_till}, error::{ErrMode, ErrorKind, ParserError, StrContext}, seq, - token::{tag, take}, + token::{literal, take}, PResult, Parser, Partial, }; @@ -258,7 +258,7 @@ impl ExtraNewUnixField { const TAG: u16 = 0x7875; fn parser(i: &mut Partial<&'_ [u8]>) -> PResult { - let _ = tag("\x01").parse_next(i)?; + let _ = literal("\x01").parse_next(i)?; seq! {Self { uid: Self::parse_variable_length_integer, gid: Self::parse_variable_length_integer, diff --git a/rc-zip/src/parse/local_headers.rs b/rc-zip/src/parse/local_headers.rs index debf98a..82a7d4c 100644 --- a/rc-zip/src/parse/local_headers.rs +++ b/rc-zip/src/parse/local_headers.rs @@ -13,7 +13,7 @@ use winnow::{ combinator::opt, error::{ContextError, ErrMode, ErrorKind, FromExternalError}, seq, - token::{tag, take}, + token::{literal, take}, PResult, Parser, Partial, }; @@ -69,7 +69,7 @@ impl<'a> LocalFileHeader<'a> { /// Parser for the local file header pub fn parser(i: &mut Partial<&'a [u8]>) -> PResult { - let _ = tag(Self::SIGNATURE).parse_next(i)?; + let _ = literal(Self::SIGNATURE).parse_next(i)?; let reader_version = Version::parser.parse_next(i)?; let flags = le_u16.parse_next(i)?; @@ -204,7 +204,7 @@ impl DataDescriptorRecord { // MAY be encountered with or without this signature marking data // descriptors and SHOULD account for either case when reading ZIP files // to ensure compatibility. - let _ = opt(tag(Self::SIGNATURE)).parse_next(i)?; + let _ = opt(literal(Self::SIGNATURE)).parse_next(i)?; if is_zip64 { seq! {Self {