Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
Repair CI
Browse files Browse the repository at this point in the history
  • Loading branch information
a1phyr committed Apr 5, 2024
1 parent 3e88fe6 commit 4064815
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 65 deletions.
71 changes: 22 additions & 49 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,77 +16,50 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
rust: [stable, 1.59.0]
rust: [stable, 1.59]

steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4

- name: Install ${{ matrix.rust }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true

- name: check
uses: actions-rs/cargo@v1
with:
command: check
args: --all --bins --examples

- name: tests
uses: actions-rs/cargo@v1
with:
command: test
args: --all
run: rustup install ${{ matrix.rust }} && rustup default ${{ matrix.rust }}

- name: Downgrade dependencies for MSRV
if: ${{ matrix.rust == '1.59' }}
run: |
cargo update -p byteorder --precise 1.4.3
cargo update -p jobserver --precise 0.1.26
cargo update -p base64ct --precise 1.5.3
- run: cargo check --all --bins --examples
- run: cargo test --all

clippy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: clippy

- name: clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets --all-features -- -D warnings
- run: cargo clippy --all-targets --all-features

check_fmt_and_docs:
name: Checking fmt and docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rustfmt, clippy
override: true

- name: fmt
run: cargo fmt --all -- --check
steps:
- uses: actions/checkout@v4

- name: Docs
run: cargo doc
- run: cargo fmt --all -- --check
- run: cargo doc

fuzz:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true

- uses: actions/checkout@v4
- run: rustup install nightly --profile minimal && rustup default nightly
- run: cargo install cargo-fuzz

- name: compile fuzz
run: |
cargo fuzz build fuzz_read
2 changes: 1 addition & 1 deletion src/cp437.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ mod test {
#[test]
fn example_slice() {
use super::FromCp437;
let data = b"Cura\x87ao";
let data = std::convert::identity(b"Cura\x87ao"); // identity to avoid a lint from rustc
assert!(::std::str::from_utf8(data).is_err());
assert_eq!(data.from_cp437(), "Curaçao");
}
Expand Down
6 changes: 3 additions & 3 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,8 +935,7 @@ impl<'a> ZipFile<'a> {
pub fn is_dir(&self) -> bool {
self.name()
.chars()
.rev()
.next()
.next_back()
.map_or(false, |c| c == '/' || c == '\\')
}

Expand Down Expand Up @@ -991,7 +990,7 @@ impl<'a> Drop for ZipFile<'a> {
// Get the inner `Take` reader so all decryption, decompression and CRC calculation is skipped.
let mut reader: std::io::Take<&mut dyn std::io::Read> = match &mut self.reader {
ZipFileReader::NoReader => {
let innerreader = ::std::mem::replace(&mut self.crypto_reader, None);
let innerreader = self.crypto_reader.take();
innerreader.expect("Invalid reader state").into_inner()
}
reader => {
Expand All @@ -1000,6 +999,7 @@ impl<'a> Drop for ZipFile<'a> {
}
};

#[allow(clippy::unused_io_amount)]
loop {
match reader.read(&mut buffer) {
Ok(0) => break,
Expand Down
3 changes: 1 addition & 2 deletions src/read/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ impl ZipStreamFileMetadata {
pub fn is_dir(&self) -> bool {
self.name()
.chars()
.rev()
.next()
.next_back()
.map_or(false, |c| c == '/' || c == '\\')
}

Expand Down
4 changes: 2 additions & 2 deletions src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod write {
/// Unstable methods for [`FileOptions`].
pub trait FileOptionsExt {
/// Write the file with the given password using the deprecated ZipCrypto algorithm.
///
///
/// This is not recommended for new archives, as ZipCrypto is not secure.
fn with_deprecated_encryption(self, password: &[u8]) -> Self;
}
Expand All @@ -17,4 +17,4 @@ pub mod write {
self.with_deprecated_encryption(password)
}
}
}
}
14 changes: 9 additions & 5 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::spec;
use crate::types::{AtomicU64, DateTime, System, ZipFileData, DEFAULT_VERSION};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use crc32fast::Hasher;
use std::convert::TryInto;
use std::default::Default;
use std::io;
use std::io::prelude::*;
Expand Down Expand Up @@ -410,8 +409,12 @@ impl<W: Write + io::Seek> ZipWriter<W> {
self.files.push(file);
}
if let Some(keys) = options.encrypt_with {
let mut zipwriter = crate::zipcrypto::ZipCryptoWriter { writer: core::mem::replace(&mut self.inner, GenericZipWriter::Closed).unwrap(), buffer: vec![], keys };
let mut crypto_header = [0u8; 12];
let mut zipwriter = crate::zipcrypto::ZipCryptoWriter {
writer: core::mem::replace(&mut self.inner, GenericZipWriter::Closed).unwrap(),
buffer: vec![],
keys,
};
let crypto_header = [0u8; 12];

zipwriter.write_all(&crypto_header)?;
self.inner = GenericZipWriter::Storer(MaybeEncrypted::Encrypted(zipwriter));
Expand All @@ -428,10 +431,11 @@ impl<W: Write + io::Seek> ZipWriter<W> {
match core::mem::replace(&mut self.inner, GenericZipWriter::Closed) {
GenericZipWriter::Storer(MaybeEncrypted::Encrypted(writer)) => {
let crc32 = self.stats.hasher.clone().finalize();
self.inner = GenericZipWriter::Storer(MaybeEncrypted::Unencrypted(writer.finish(crc32)?))
self.inner =
GenericZipWriter::Storer(MaybeEncrypted::Unencrypted(writer.finish(crc32)?))
}
GenericZipWriter::Storer(w) => self.inner = GenericZipWriter::Storer(w),
_ => unreachable!()
_ => unreachable!(),
}
let writer = self.inner.get_plain();

Expand Down
10 changes: 7 additions & 3 deletions tests/zip_crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ use std::io::Read;

#[test]
fn encrypting_file() {
use zip::unstable::write::FileOptionsExt;
use std::io::{Read, Write};
use zip::unstable::write::FileOptionsExt;
let mut buf = vec![0; 2048];
let mut archive = zip::write::ZipWriter::new(std::io::Cursor::new(&mut buf));
archive.start_file("name", zip::write::FileOptions::default().with_deprecated_encryption(b"password")).unwrap();
archive
.start_file(
"name",
zip::write::FileOptions::default().with_deprecated_encryption(b"password"),
)
.unwrap();
archive.write_all(b"test").unwrap();
archive.finish().unwrap();
drop(archive);
Expand All @@ -35,7 +40,6 @@ fn encrypting_file() {
let mut buf = Vec::new();
file.read_to_end(&mut buf).unwrap();
assert_eq!(buf, b"test");

}
#[test]
fn encrypted_file() {
Expand Down

0 comments on commit 4064815

Please sign in to comment.