Skip to content

fix: allow aes password as bytes#686

Merged
Pr0methean merged 3 commits intomasterfrom
aes-bytes-password
Feb 22, 2026
Merged

fix: allow aes password as bytes#686
Pr0methean merged 3 commits intomasterfrom
aes-bytes-password

Conversation

@Its-Just-Nans
Copy link
Member

Fix: #214

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Its-Just-Nans, 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 enhances the AES encryption functionality by allowing passwords to be provided as byte slices (&[u8]) in addition to string slices (&str). This change addresses issue #214, providing more flexibility and direct control over password handling, particularly for non-UTF8 compatible passwords or when byte-level precision is required.

Highlights

  • New AES Password Method: Introduced a new with_aes_encryption_and_bytes_password method to FileOptions for specifying AES passwords directly as byte slices (&[u8]).
  • Updated Existing AES Password Method: Modified the existing with_aes_encryption method to convert string passwords (&str) to byte slices (&[u8]) internally before use.
  • Internal Password Type Change: Updated the EncryptWith::Aes enum to store AES passwords as &[u8] instead of &str, providing more flexibility for non-UTF8 passwords.
  • Test Coverage: Added a new test case to validate AES decryption when passwords are provided as byte slices.
Changelog
  • src/write.rs
    • The FileOptions::with_aes_encryption method was updated to convert &str passwords to &[u8].
    • A new method FileOptions::with_aes_encryption_and_bytes_password was added to accept &[u8] passwords directly.
    • The ZipWriter's internal AES encryption setup was modified to use &[u8] passwords directly.
    • Test cases were updated to use empty byte slices &[] for empty passwords.
  • src/zipcrypto.rs
    • The password field in the EncryptWith::Aes enum was changed from &str to &[u8].
  • tests/by_path.rs
    • A new test by_path_decrypt_and_bytes_password was added to verify decryption with byte slice passwords.
Activity
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.

The changes look good overall. This PR successfully adds support for AES passwords as byte arrays (&[u8]) while maintaining backward compatibility with the existing string-based API through the with_aes_encryption() method.

The implementation correctly:

  • Changes the internal EncryptWith::Aes password field to &[u8]
  • Adds with_aes_encryption_and_bytes_password() for direct byte array input
  • Updates with_aes_encryption() to convert strings to bytes via .as_bytes()
  • Removes the redundant .as_bytes() call when initializing the AES writer
  • Adds appropriate test coverage

No blocking issues identified.


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 support for byte-based AES passwords, improving compatibility with non-UTF8 passwords. A high-severity security issue was identified: the encryption password can be leaked through the derived Debug implementation of the EncryptWith enum, requiring manual implementation to redact sensitive information and an update to the Arbitrary implementation to prevent compilation errors. Additionally, refactorings are suggested in src/write.rs to reduce code duplication and improve method naming, with corresponding updates needed in tests.

Copy link
Member

@Pr0methean Pr0methean left a comment

Choose a reason for hiding this comment

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

Shouldn't we support this on the reading side as well? And should we maybe have an option to specify the key directly, bypassing PBKDF in case some other software also did so?

@Pr0methean Pr0methean added this to the 8.2.0 milestone Feb 21, 2026
@Pr0methean
Copy link
Member

Shouldn't we support this on the reading side as well? And should we maybe have an option to specify the key directly, bypassing PBKDF in case some other software also did so?

Never mind; I hadn't seen the mention in #214 that ZipArchive already accepts passwords as bytes. Specifying raw keys is probably still worth doing, but it can be a separate PR.

@Pr0methean Pr0methean enabled auto-merge February 21, 2026 19:26
@Its-Just-Nans Its-Just-Nans self-assigned this Feb 21, 2026
@Pr0methean Pr0methean added this pull request to the merge queue Feb 21, 2026
Merged via the queue into master with commit 60f431d Feb 22, 2026
130 checks passed
@Pr0methean Pr0methean deleted the aes-bytes-password branch February 22, 2026 01:13
@Pr0methean Pr0methean mentioned this pull request Feb 22, 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.

ZipWriter with AES password &[u8]

2 participants