diff --git a/internal/testkit/testkit.go b/internal/testkit/testkit.go index 8705162..e459095 100644 --- a/internal/testkit/testkit.go +++ b/internal/testkit/testkit.go @@ -130,8 +130,7 @@ func (f *TestFile) HMAC() { f.HMACLine(h.Sum(nil)) } -func (f *TestFile) Nonce() { - nonce := f.Rand(16) +func (f *TestFile) Nonce(nonce []byte) { f.streamKey = make([]byte, 32) hkdf.New(sha256.New, f.fileKey, nonce, []byte("payload")).Read(f.streamKey) f.Buf.Write(nonce) @@ -152,7 +151,7 @@ func (f *TestFile) PayloadChunkFinal(plaintext []byte) { } func (f *TestFile) Payload(plaintext string) { - f.Nonce() + f.Nonce(f.Rand(16)) f.PayloadChunkFinal([]byte(plaintext)) } diff --git a/testdata/empty_payload.go b/testdata/stream_empty_payload.go similarity index 100% rename from testdata/empty_payload.go rename to testdata/stream_empty_payload.go diff --git a/testdata/empty_payload.test b/testdata/stream_empty_payload.test similarity index 100% rename from testdata/empty_payload.test rename to testdata/stream_empty_payload.test diff --git a/testdata/stream_last_chunk_empty.go b/testdata/stream_last_chunk_empty.go new file mode 100644 index 0000000..8cebe0e --- /dev/null +++ b/testdata/stream_last_chunk_empty.go @@ -0,0 +1,32 @@ +// Copyright 2022 The age Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore + +package main + +import ( + "bytes" + "encoding/hex" + + "filippo.io/age/internal/testkit" +) + +func main() { + f := testkit.NewTestFile() + // Reuse the file key and nonce from a previous test vector to avoid + // bloating the git history with two versions that can't be compressed. + fileKey, _ := hex.DecodeString("7aa5bdac0e6afeed3dd0a7eccb42af44") + f.FileKey(fileKey) + f.VersionLine("v1") + f.X25519(testkit.TestX25519Identity) + f.HMAC() + nonce, _ := hex.DecodeString("c82f71eb82029b77136399e485e879f4") + f.Nonce(nonce) + f.PayloadChunk(bytes.Repeat([]byte{0}, 64*1024)) + f.PayloadChunkFinal([]byte{}) + f.Comment("final STREAM chunk can't be empty unless whole payload is empty") + f.ExpectPayloadFailure() + f.Generate() +} diff --git a/cmd/age/testdata/fail_last_empty.age b/testdata/stream_last_chunk_empty.test similarity index 99% rename from cmd/age/testdata/fail_last_empty.age rename to testdata/stream_last_chunk_empty.test index 3f67f5b..8e03661 100644 Binary files a/cmd/age/testdata/fail_last_empty.age and b/testdata/stream_last_chunk_empty.test differ diff --git a/testdata/stream_last_chunk_full.go b/testdata/stream_last_chunk_full.go new file mode 100644 index 0000000..a86efe7 --- /dev/null +++ b/testdata/stream_last_chunk_full.go @@ -0,0 +1,29 @@ +// Copyright 2022 The age Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore + +package main + +import ( + "bytes" + "encoding/hex" + + "filippo.io/age/internal/testkit" +) + +func main() { + f := testkit.NewTestFile() + // Reuse the file key and nonce from a previous test vector to avoid + // bloating the git history with two versions that can't be compressed. + fileKey, _ := hex.DecodeString("5085919e0d59b19d6cbd00330f03861c") + f.FileKey(fileKey) + f.VersionLine("v1") + f.X25519(testkit.TestX25519Identity) + f.HMAC() + nonce, _ := hex.DecodeString("32521791a6f22e11637fb69ead3f2d5f") + f.Nonce(nonce) + f.PayloadChunkFinal(bytes.Repeat([]byte{0}, 64*1024)) + f.Generate() +} diff --git a/cmd/age/testdata/good_last_full.age b/testdata/stream_last_chunk_full.test similarity index 99% rename from cmd/age/testdata/good_last_full.age rename to testdata/stream_last_chunk_full.test index 78d62d8..bc4baae 100644 Binary files a/cmd/age/testdata/good_last_full.age and b/testdata/stream_last_chunk_full.test differ