Skip to content

Commit

Permalink
age: make TestVectorsRoundTrip a little stricter
Browse files Browse the repository at this point in the history
  • Loading branch information
FiloSottile committed Jul 22, 2023
1 parent 4740a92 commit 980763a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions testkit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 980763a

Please sign in to comment.