Skip to content

Commit

Permalink
test: simplify TestEncryptorReadEOF
Browse files Browse the repository at this point in the history
  • Loading branch information
70sh1 committed Mar 15, 2024
1 parent 58a1b0b commit ba0d79e
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,17 @@ func TestEncryptorReadEOF(t *testing.T) {
dir := testutils.TestFilesSetup()
defer testutils.TestFilesCleanup(dir)

source, err := os.Open(filepath.Join(dir, "empty.txt"))
proc, err := newProcessor(filepath.Join(dir, "empty.txt"), password, Encryption)
if err != nil {
source.Close()
proc.source.Close()
panic(err)
}
defer source.Close()
nonce := make([]byte, chacha20.NonceSize)
salt := make([]byte, 16)
key, err := deriveKey(password, salt)
testutils.PanicIfErr(err)
blakeKey := make([]byte, 32)
c, err := chacha20.NewUnauthenticatedCipher(key, nonce)
testutils.PanicIfErr(err)
c.XORKeyStream(blakeKey, blakeKey)
blake, err := blake2b.New512(blakeKey)
testutils.PanicIfErr(err)
defer proc.source.Close()

encryptor := &encryptor{&processor{c, blake, source, nonce, salt, 0}}
enc := &encryptor{proc}
buf := make([]byte, 128)

n, err := encryptor.Read(buf)
n, err := enc.Read(buf)
require.ErrorIs(t, err, io.EOF)
require.Equal(t, n, 0)
require.Equal(t, buf, make([]byte, 128))
Expand Down

0 comments on commit ba0d79e

Please sign in to comment.