Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IsEncrypted() method to File struct #82

Closed
wants to merge 3 commits into from

Conversation

belyalov
Copy link

It is an easy way to determine if file is encrypted - useful when you need to e.g. find and do something with password encrypted archives.

I tried to keep it simple and move this code out of data path - to make it seamless for everybody who does not care about this functionality.

@LinkLeong
Copy link

This function is very useful, I hope to deal with it as soon as possible

@bodgit
Copy link
Owner

bodgit commented Nov 17, 2024

I'm not going to merge this for a couple of reasons:

  • This doesn't help in the scenario of the password being wrong and the archive headers are encrypted, in this case you won't be able to open the archive to even see if the files are encrypted.
  • There is more than one encryption method for 7-zip archives, (although only the one is currently implemented as I haven't needed to support any others), so I'd rather not add a special case for just this one.

I have just merged in #278 and released in v1.6.0 support for returning a sevenzip.ReadError on certain operations. This includes a hint that encryption is involved somewhere in the stack and works for both opening the archive as well as extracting a file so hopefully covers all of the scenarios.

You can check using errors.As() with something like this:

r, err := sevenzip.OpenReaderWithPassword(archive, password)
if err != nil {
        var e *sevenzip.ReadError
        if errors.As(err, &e) && e.Encrypted {
                // Encryption involved, retry with a different password
        }

        return err
}

@bodgit bodgit closed this Nov 17, 2024
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.

3 participants