diff --git a/README.txt b/README.txt index aa95b5d..177985b 100644 --- a/README.txt +++ b/README.txt @@ -11,7 +11,7 @@ hello.txt -> compress -> encrypt -> .zip -> decrypt -> decompress -> hello.txt Roadmap ============================================================================== -Reading - Almost done (TODO: check for AE-2 and skip CRC). +Reading - Working on it. Some bugs to work out (TODO: check for AE-2 and skip CRC). Writing - Not started. Testing - Needs more. diff --git a/reader.go b/reader.go index ff7909b..2ce8cfd 100644 --- a/reader.go +++ b/reader.go @@ -244,6 +244,7 @@ func decryptStream(ciphertext, key, iv []byte) io.Reader { return nil } stream := cipher.NewCTR(block, iv) + // Not decrypting stream correctly if the number of bytes being read is >16 reader := cipher.StreamReader{S: stream, R: bytes.NewReader(ciphertext)} return reader } diff --git a/reader_test.go b/reader_test.go index 751e965..2cf784f 100644 --- a/reader_test.go +++ b/reader_test.go @@ -660,9 +660,39 @@ func TestHelloWorldAes(t *testing.T) { t.Errorf("Expected to open readcloser: %v", err) } defer rc.Close() - io.Copy(&b, rc) + if _, err := io.Copy(&b, rc); err != nil { + t.Errorf("Expected to copy bytes to buffer: %v", err) + } } if !bytes.Equal([]byte(expecting), b.Bytes()) { t.Errorf("Expected ending content to be %s instead of %s", expecting, b.Bytes()) } } + +func TestMacbethAct1(t *testing.T) { + file := "macbeth-act1.zip" + expecting := "Exeunt" + var b bytes.Buffer + r, err := OpenReader(filepath.Join("testdata", file)) + if err != nil { + t.Errorf("Expected %s to open: %v", file, err) + } + defer r.Close() + for _, f := range r.File { + if !f.IsEncrypted() { + t.Errorf("Expected %s to be encrypted.", f.Name) + } + f.SetPassword([]byte("golang")) + rc, err := f.Open() + if err != nil { + t.Errorf("Expected to open readcloser: %v", err) + } + defer rc.Close() + if _, err := io.Copy(&b, rc); err != nil { + t.Errorf("Expected to copy bytes to buffer: %v", err) + } + } + if !bytes.Contains(b.Bytes(), []byte(expecting)) { + t.Errorf("Expected to find %s in the buffer %v", expecting, b.Bytes()) + } +} diff --git a/testdata/macbeth-act1.zip b/testdata/macbeth-act1.zip new file mode 100644 index 0000000..8ee2aa2 Binary files /dev/null and b/testdata/macbeth-act1.zip differ