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:
alexmullins 2015-11-26 14:46:37 -06:00
parent 9b6aff4be2
commit a0910dd023
2 changed files with 19 additions and 3 deletions

View File

@ -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.

View File

@ -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.