From 787044bdb69028574a285af09ae297d2ff5ce927 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Wed, 15 Jun 2022 19:38:18 +0200 Subject: [PATCH] testdata: convert last chunk tests to testkit --- internal/testkit/testkit.go | 5 ++- ...pty_payload.go => stream_empty_payload.go} | 0 ...payload.test => stream_empty_payload.test} | 0 testdata/stream_last_chunk_empty.go | 32 ++++++++++++++++++ .../stream_last_chunk_empty.test | Bin 65752 -> 66044 bytes testdata/stream_last_chunk_full.go | 29 ++++++++++++++++ .../stream_last_chunk_full.test | Bin 65736 -> 65955 bytes 7 files changed, 63 insertions(+), 3 deletions(-) rename testdata/{empty_payload.go => stream_empty_payload.go} (100%) rename testdata/{empty_payload.test => stream_empty_payload.test} (100%) create mode 100644 testdata/stream_last_chunk_empty.go rename cmd/age/testdata/fail_last_empty.age => testdata/stream_last_chunk_empty.test (99%) create mode 100644 testdata/stream_last_chunk_full.go rename cmd/age/testdata/good_last_full.age => testdata/stream_last_chunk_full.test (99%) 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 3f67f5bcac651b5354178995afeb92a430f053a9..8e03661489cab9ffc98cc454dae97167ed91183f 100644 GIT binary patch delta 445 zcmXYtPi~t)9EDXWQYB6?t9D@_4a2~Icdj$G;xWX32pI2%-wZVhV5o5j-dIsC&`qz9 zGxacC)Ka^CPoLiRe!t!QdB3~r*G5A(MyE4?KAnt44&_m*F;bf3#Bs4pC6+n!8KVqH z<}(L73UKD6G^d`gB{16pVoU9V^Z{(k$cs{=XFZG&lhVnQ1gu?|Yprahuw)t_ zqgNtxN{vG4x+}U{cQWVZmQOc4G6hdfi_fEdJe$P?d$toMY3ve)m%B6;Bo^V01i`&X zQn3u?8|pnxk{!isvLed>8*r?u8+MHHqLwAvMjJi}5FF0+GXhzE?NFw_AYC=xfX;P! zvq$~mcpLry15}*;rH1hnT_ax1@X)kBMp^R$?JgXq@uFF>$8*0@alcwJvF6$A{&5OM zqxS76!Y>}ZT74Pi4C1 bQCqGCg8igt@j$cB0z}X*E^i;dK0cAZVET^5 delta 154 zcmey<%yOfVWwHvRLVbp_g=JoLV1`d*WSU!kzJFeMc}1R?v8hv@ms4`Ccb{iI<_Tvu9LAPGxARc9>^M6njOfn~S5bQ}Zdt>8BVO FjQ}6AGu{9I 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 78d62d8a120eab9efd4ec7ccf50e55e6a38f9a09..bc4baae0973595e5195874e29c4b05f008113752 100644 GIT binary patch delta 372 zcmWO1&r*Uw901^HrbEM1(79p!vCFcox75W7Ff>DSy1@P^ObZ1yyf{uT(4{Bn;H&gl zb^k8k@A3TS^ZcMbN+s&HS#5++Rb`Y}vv|*B+ms4vL|ky43^Gj_r4AJ+XOsYu0&=FY z)F73k9gnF@P;3i?GsQ&4guu3;i-j^@Rns;Jc!b$Zfg~)qnRG=i0Wby)PuO#9VH8rm z)kXbpulwA3;N1})TLGV1Ht&yTiSH)}JWK|YY2qRZVLD9$lmvqmMNu!9OoK4$j~wsu zdXhRYL@^2@FpMwrFy@61O}ScM<>gka(m~Tr?#htfZ+5Xvc5z69AwrF#T delta 154 zcmZ47%yOcUW#VmxdN0@1WCL@H#0pEF++06{#LzOsq_Cpw(7Yt))UpUq*C;c8!{Aak zBLgD?F0YW#C|6(8ME|t3oWg>l!c2oOzp}id%+fqpKWFpwszB4UtgygR_lzt@E?r$+ zg-Aai(;|c1u=3OhUlaFqGvB}fQ{UXQK-ZGW6vMz&H-l_n4&yABG