Skip to content

refactor: reorganize code#714

Merged
Its-Just-Nans merged 20 commits intomasterfrom
reorganize-code
Mar 15, 2026
Merged

refactor: reorganize code#714
Its-Just-Nans merged 20 commits intomasterfrom
reorganize-code

Conversation

@Its-Just-Nans
Copy link
Member

@Its-Just-Nans Its-Just-Nans commented Mar 8, 2026

Refactor part of the code

  • move the extra field aex to the extra_field folder
  • change some literal for better reading

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily focuses on reorganizing and refactoring existing code to improve modularity, encapsulation, and readability. Key data structures like ZipFileData now manage their own related operations, and a new module has been introduced for AES extra fields. These changes aim to make the codebase easier to understand and maintain without altering external behavior.

Highlights

  • AES Extra Field Modularity: The AesExtraField structure and its associated logic have been moved into a dedicated module (src/extra_fields/aex_encryption.rs), improving code organization and separation of concerns within the extra_fields module.
  • Encapsulation of File Data Operations: Several functions related to ZipFileData operations, such as find_data_start, update_local_zip64_extra_field, update_local_file_header, and write_central_directory_header, have been moved from src/read.rs and src/write.rs into src/types.rs as methods of the ZipFileData struct. This enhances encapsulation and makes ZipFileData more self-contained.
  • Improved Flag Handling: A new ZipFlags::matching method has been introduced in src/spec.rs to provide a more idiomatic and readable way to check for specific flags, replacing direct bitwise operations in several places.
  • Code Style and Readability Enhancements: Various minor refactorings were applied across the codebase, including adding _ separators to large hexadecimal and binary literals, updating comments for clarity, and adjusting #[inline] attributes for better compiler hints. Several clippy warnings were also addressed.
Changelog
  • src/cp437.rs
    • Added #[allow(clippy::too_many_lines)] attribute to the to_char function.
  • src/extra_fields/aex_encryption.rs
    • Added new file defining AesExtraField struct and its implementations.
  • src/extra_fields/mod.rs
    • Added aex_encryption module and exposed AesExtraField.
    • Introduced as_u16 constant function for UsedExtraField enum.
    • Updated From<UsedExtraField> for u16 implementation to use as_u16.
    • Updated EXTRA_FIELD_MAPPING array to use as_u16 for enum variants.
  • src/read.rs
    • Removed find_data_start function, which was moved to ZipFileData.
    • Changed #[inline(always)] to #[inline] for index_for_name, index_for_path, and name_for_index methods.
    • Updated flag checking logic to use ZipFlags::matching.
  • src/spec.rs
    • Changed #[inline(always)] to #[inline] for Magic and FixedSizeBlock methods.
    • Added _ separators to hexadecimal literals for Magic constants.
    • Implemented ZipFlags with matching and as_u16 methods, and From<ZipFlags> for u16 trait.
    • Added #[macro_export] attribute to from_le, to_le, and to_and_from_le macros.
  • src/types.rs
    • Moved find_data_start function into ZipFileData as a method.
    • Added update_local_zip64_extra_field, update_local_file_header, and write_central_directory_header methods to ZipFileData.
    • Updated ffi constants with _ separators.
    • Updated comments for System enum variants to use backticks.
    • Added #[must_use] attribute to System::from_version_made_by.
    • Updated binary literals with _ separators in DateTime calculations.
    • Removed AesExtraField struct and its implementations, as it was moved to src/extra_fields/aex_encryption.rs.
    • Modified ZipFileData::initialize_local_block parameters to accept references.
    • Updated flag checking logic to use ZipFlags::matching and as_u16.
  • src/unstable.rs
    • Added a semicolon to a line in path_to_string to resolve a clippy warning.
  • src/write.rs
    • Updated import path for AesExtraField.
    • Removed unused offset_of import.
    • Updated ZipWriter::get_ref and ZipWriter::get_mut to explicitly list GenericZipWriter variants.
    • Refined error message formatting.
    • Added #[must_use] attribute to FileOptions::into_full_options and ZipWriter::set_auto_large_file.
    • Corrected logic for extra_field assignment in copy_file_from_reader.
    • Changed Default::default() to ZipWriterStats::default() for clarity.
    • Updated aes_mode mapping to use direct function reference.
    • Updated calls to update_local_file_header and write_central_directory_header to use ZipFileData methods.
    • Made strip_alignment_extra_field public and updated its usage of UsedExtraField.
    • Removed external update_local_zip64_extra_field and update_local_file_header functions.
  • src/zipcrypto.rs
    • Updated comments to use backticks for ZipCrypto.
    • Added #[allow(clippy::struct_field_names)] to ZipCryptoKeys.
    • Added _ separators to hexadecimal literals for INITIAL_KEY constants and Wrapping operations.
    • Added #[allow(clippy::unreadable_literal)] to CRC_TABLE.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@amazon-q-developer amazon-q-developer bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR reorganizes code across 9 files with 346 additions and 298 deletions. However, there are process issues that need to be addressed:

Critical Issues:

  1. PR Title Format: The PR title "Reorganize code" does not conform to Conventional Commits as required by your guidelines. It should start with a type prefix such as:

    • refactor: Reorganize code (if this is a pure refactoring)
    • chore: Reorganize code (if this is a maintenance task)
  2. Missing Description: The PR has no description. For a reorganization affecting 9 core files, please add a description explaining:

    • What was reorganized and why
    • What the benefits of this reorganization are
    • Whether this is purely code movement or if there are any behavioral changes

Note: Due to the size of the changes, I was unable to perform a detailed line-by-line review. Once the above issues are addressed and if you'd like a detailed technical review, please request one.

Action Required: Please update the PR title to conform to Conventional Commits format before merging.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant code reorganization, primarily aimed at improving modularity and code clarity. Key changes include moving the AesExtraField struct to its own module, refactoring free functions into methods on ZipFileData, and various style improvements like replacing #[inline(always)] with #[inline] and enhancing readability with digit separators in literals. While these changes make the codebase more organized and idiomatic, a medium-severity vulnerability was identified related to the insecure initialization of the legacy ZipCrypto encryption header. Other security-critical areas, such as path sanitization and AES encryption, were found to be correctly implemented. Additionally, a minor suggestion was made to improve an error message for better debuggability.

@Its-Just-Nans Its-Just-Nans changed the title Reorganize code feat: reorganize code Mar 8, 2026
@Its-Just-Nans Its-Just-Nans requested a review from Pr0methean March 8, 2026 19:04
@Its-Just-Nans Its-Just-Nans mentioned this pull request Mar 8, 2026
6 tasks
@Its-Just-Nans Its-Just-Nans self-assigned this Mar 8, 2026
@Pr0methean Pr0methean changed the title feat: reorganize code refactor: reorganize code Mar 11, 2026
@Its-Just-Nans Its-Just-Nans added this pull request to the merge queue Mar 15, 2026
Merged via the queue into master with commit 76b8060 Mar 15, 2026
130 checks passed
@Its-Just-Nans Its-Just-Nans deleted the reorganize-code branch March 15, 2026 07:36
This was referenced Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant