From a0910dd023600e937063ba965be9620fc8586bbc Mon Sep 17 00:00:00 2001 From: alexmullins Date: Thu, 26 Nov 2015 14:46:37 -0600 Subject: [PATCH] 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. --- reader.go | 3 --- struct.go | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/reader.go b/reader.go index 1e6dee5..2b174cc 100644 --- a/reader.go +++ b/reader.go @@ -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. diff --git a/struct.go b/struct.go index b2911e9..9fe0482 100644 --- a/struct.go +++ b/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.