age: make TestVectorsRoundTrip a little stricter

This commit is contained in:
Filippo Valsorda
2023-07-23 00:54:40 +02:00
parent 4740a92ef9
commit 980763a16e

View File

@@ -182,11 +182,13 @@ func TestVectorsRoundTrip(t *testing.T) {
func testVectorRoundTrip(t *testing.T, v *vector) {
if v.armored {
if v.expect == "armor failure" {
t.SkipNow()
}
t.Run("armor", func(t *testing.T) {
payload, err := io.ReadAll(armor.NewReader(bytes.NewReader(v.file)))
if err != nil {
// If the error is unexpected, it will be caught by TestVectors.
t.Skip(err)
t.Fatal(err)
}
buf := &bytes.Buffer{}
w := armor.NewWriter(buf)
@@ -209,10 +211,12 @@ func testVectorRoundTrip(t *testing.T, v *vector) {
return
}
if v.expect == "header failure" {
t.SkipNow()
}
hdr, p, err := format.Parse(bytes.NewReader(v.file))
if err != nil {
// If the error is unexpected, it will be caught by TestVectors.
t.Skip(err)
t.Fatal(err)
}
payload, err := io.ReadAll(p)
if err != nil {
@@ -230,7 +234,7 @@ func testVectorRoundTrip(t *testing.T, v *vector) {
}
})
if v.fileKey != nil && len(payload) > 16 {
if v.expect == "success" {
t.Run("STREAM", func(t *testing.T) {
nonce, payload := payload[:16], payload[16:]
key := streamKey(v.fileKey[:], nonce)
@@ -240,8 +244,7 @@ func testVectorRoundTrip(t *testing.T, v *vector) {
}
plaintext, err := io.ReadAll(r)
if err != nil {
// If the error is unexpected, it will be caught by TestVectors.
t.Skip(err)
t.Fatal(err)
}
buf := &bytes.Buffer{}
w, err := stream.NewWriter(key, buf)