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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/bodgit/sevenzip
module github.com/todylcom/sevenzip

go 1.17

Expand Down
2 changes: 1 addition & 1 deletion internal/bcj2/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"errors"
"io"

"github.com/bodgit/sevenzip/internal/util"
"github.com/todylcom/sevenzip/internal/util"
"github.com/hashicorp/go-multierror"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/deflate/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io"
"sync"

"github.com/bodgit/sevenzip/internal/util"
"github.com/todylcom/sevenzip/internal/util"
"github.com/klauspost/compress/flate"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sort"
"sync"

"github.com/bodgit/sevenzip/internal/util"
"github.com/todylcom/sevenzip/internal/util"
)

// Pooler is the interface implemented by a pool.
Expand Down
17 changes: 15 additions & 2 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"time"

"github.com/bodgit/plumbing"
"github.com/bodgit/sevenzip/internal/pool"
"github.com/bodgit/sevenzip/internal/util"
"github.com/hashicorp/go-multierror"
"github.com/todylcom/sevenzip/internal/pool"
"github.com/todylcom/sevenzip/internal/util"
"go4.org/readerutil"
)

Expand Down Expand Up @@ -146,6 +146,19 @@ func (f *File) Open() (io.ReadCloser, error) {
}, nil
}

// IsEncrypted returns true if file is encrypted with AES
func (f *File) IsEncrypted() bool {
if f.zip == nil || f.zip.si == nil || f.zip.si.unpackInfo == nil {
return false
}
for _, coder := range f.zip.si.unpackInfo.folder[f.folder].coder {
if bytes.Equal(aesCbc256CoderSignature, coder.id) {
return true
}
}
return false
}

// OpenReaderWithPassword will open the 7-zip file specified by name using
// password as the basis of the decryption key and return a ReadCloser. If
// name has a ".001" suffix it is assumed there are multiple volumes and each
Expand Down
4 changes: 2 additions & 2 deletions reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"testing"
"testing/fstest"

"github.com/bodgit/sevenzip"
"github.com/bodgit/sevenzip/internal/util"
"github.com/todylcom/sevenzip"
"github.com/todylcom/sevenzip/internal/util"
"github.com/stretchr/testify/assert"
)

Expand Down
26 changes: 15 additions & 11 deletions register.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ import (
"io"
"sync"

"github.com/bodgit/sevenzip/internal/aes7z"
"github.com/bodgit/sevenzip/internal/bcj2"
"github.com/bodgit/sevenzip/internal/brotli"
"github.com/bodgit/sevenzip/internal/bzip2"
"github.com/bodgit/sevenzip/internal/deflate"
"github.com/bodgit/sevenzip/internal/delta"
"github.com/bodgit/sevenzip/internal/lz4"
"github.com/bodgit/sevenzip/internal/lzma"
"github.com/bodgit/sevenzip/internal/lzma2"
"github.com/bodgit/sevenzip/internal/zstd"
"github.com/todylcom/sevenzip/internal/aes7z"
"github.com/todylcom/sevenzip/internal/bcj2"
"github.com/todylcom/sevenzip/internal/brotli"
"github.com/todylcom/sevenzip/internal/bzip2"
"github.com/todylcom/sevenzip/internal/deflate"
"github.com/todylcom/sevenzip/internal/delta"
"github.com/todylcom/sevenzip/internal/lz4"
"github.com/todylcom/sevenzip/internal/lzma"
"github.com/todylcom/sevenzip/internal/lzma2"
"github.com/todylcom/sevenzip/internal/zstd"
)

var (
aesCbc256CoderSignature = []byte{0x06, 0xf1, 0x07, 0x01}
)

// Decompressor describes the function signature that decompression/decryption
Expand Down Expand Up @@ -55,7 +59,7 @@ func init() {
// LZ4
RegisterDecompressor([]byte{0x04, 0xf7, 0x11, 0x04}, Decompressor(lz4.NewReader))
// AES-CBC-256 & SHA-256
RegisterDecompressor([]byte{0x06, 0xf1, 0x07, 0x01}, Decompressor(aes7z.NewReader))
RegisterDecompressor(aesCbc256CoderSignature, Decompressor(aes7z.NewReader))
// LZMA2
RegisterDecompressor([]byte{0x21}, Decompressor(lzma2.NewReader))
}
Expand Down
2 changes: 1 addition & 1 deletion struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

"github.com/bodgit/plumbing"
"github.com/bodgit/sevenzip/internal/util"
"github.com/todylcom/sevenzip/internal/util"
)

var errAlgorithm = errors.New("sevenzip: unsupported compression algorithm")
Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"math/bits"
"time"

"github.com/bodgit/sevenzip/internal/util"
"github.com/todylcom/sevenzip/internal/util"
"github.com/bodgit/windows"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
Expand Down