mirror of https://github.com/yeka/zip.git
commit
03d6312748
|
@ -437,7 +437,8 @@ func (h *FileHeader) writeWinZipExtra() {
|
||||||
h.Extra = append(h.Extra, buf[:]...)
|
h.Extra = append(h.Extra, buf[:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *FileHeader) setEncryptionMethod(enc EncryptionMethod) {
|
// SetEncryptionMethod sets the encryption method.
|
||||||
|
func (h *FileHeader) SetEncryptionMethod(enc EncryptionMethod) {
|
||||||
h.encryption = enc
|
h.encryption = enc
|
||||||
switch enc {
|
switch enc {
|
||||||
case AES128Encryption:
|
case AES128Encryption:
|
||||||
|
@ -478,6 +479,6 @@ func (w *Writer) Encrypt(name string, password string, enc EncryptionMethod) (io
|
||||||
Method: Deflate,
|
Method: Deflate,
|
||||||
}
|
}
|
||||||
fh.SetPassword(password)
|
fh.SetPassword(password)
|
||||||
fh.setEncryptionMethod(enc)
|
fh.SetEncryptionMethod(enc)
|
||||||
return w.CreateHeader(fh)
|
return w.CreateHeader(fh)
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ func TestPasswordHelloWorldAes(t *testing.T) {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
for _, f := range r.File {
|
for _, f := range r.File {
|
||||||
if !f.IsEncrypted() {
|
if !f.IsEncrypted() {
|
||||||
t.Errorf("Expected %s to be encrypted.", f.FileInfo().Name)
|
t.Errorf("Expected %s to be encrypted.", f.FileInfo().Name())
|
||||||
}
|
}
|
||||||
f.SetPassword("golang")
|
f.SetPassword("golang")
|
||||||
rc, err := f.Open()
|
rc, err := f.Open()
|
||||||
|
|
Loading…
Reference in New Issue