mirror of https://github.com/yeka/zip.git
Move all password related fields to the FileHeader
This will unify the reading and writing API. Eventually the SetPassword function will be deprecated in favor of a Password field that is of type func() []byte. This way the password can be set dynamically. This will also help in differentiating a nil password and an empty password.
This commit is contained in:
parent
9b6aff4be2
commit
a0910dd023
|
@ -37,9 +37,6 @@ type File struct {
|
|||
zipr io.ReaderAt
|
||||
zipsize int64
|
||||
headerOffset int64
|
||||
password []byte
|
||||
ae uint16
|
||||
aesStrength byte
|
||||
}
|
||||
|
||||
// SetPassword must be called before calling Open on the file.
|
||||
|
|
19
struct.go
19
struct.go
|
@ -97,6 +97,25 @@ type FileHeader struct {
|
|||
Extra []byte
|
||||
ExternalAttrs uint32 // Meaning depends on CreatorVersion
|
||||
Comment string
|
||||
|
||||
// encryption fields
|
||||
password []byte
|
||||
ae uint16
|
||||
aesStrength byte
|
||||
}
|
||||
|
||||
// SetPassword must be called before calling Open on the file.
|
||||
func (f *FileHeader) SetPassword(password []byte) {
|
||||
f.password = password
|
||||
}
|
||||
|
||||
// IsEncrypted indicates whether this file's data is encrypted.
|
||||
func (f *FileHeader) IsEncrypted() bool {
|
||||
return f.Flags&0x1 == 1
|
||||
}
|
||||
|
||||
func (f *FileHeader) isAE2() bool {
|
||||
return f.ae == 2
|
||||
}
|
||||
|
||||
// FileInfo returns an os.FileInfo for the FileHeader.
|
||||
|
|
Loading…
Reference in New Issue