armor: reject empty lines in armored data

Caught by the new CCTV test vectors!
This commit is contained in:
Filippo Valsorda
2025-12-07 21:15:38 +01:00
committed by Filippo Valsorda
parent d7409cdc74
commit 96b6476140
4 changed files with 27 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ package age_test
import (
"bytes"
"compress/zlib"
"crypto/sha256"
"encoding/hex"
"errors"
@@ -55,6 +56,7 @@ type vector struct {
}
func parseVector(t *testing.T, test []byte) *vector {
var z bool
v := &vector{file: test}
for {
line, rest, ok := bytes.Cut(v.file, []byte("\n"))
@@ -105,12 +107,31 @@ func parseVector(t *testing.T, test []byte) *vector {
v.identities = append(v.identities, i)
case "armored":
v.armored = true
case "compressed":
if value != "zlib" {
t.Fatal("invalid test file: unknown compression:", value)
}
z = true
case "comment":
t.Log(value)
default:
t.Fatal("invalid test file: unknown header key:", key)
}
}
if z {
r, err := zlib.NewReader(bytes.NewReader(v.file))
if err != nil {
t.Fatal(err)
}
b, err := io.ReadAll(r)
if err != nil {
t.Fatal(err)
}
if err := r.Close(); err != nil {
t.Fatal(err)
}
v.file = b
}
return v
}