age: improve error on empty files

Fixes #416
This commit is contained in:
Filippo Valsorda
2025-12-23 15:21:31 +01:00
parent 38dd222823
commit ca8a69b1b6
2 changed files with 8 additions and 1 deletions

View File

@@ -15,6 +15,11 @@ age -r age12phkzssndd5axajas2h74vtge62c86xjhd6u9anyanqhzvdg6sps0xthgl -o test.ag
! age -d -i key.txt test.age
stderr 'no identity matched any of the recipients'
# decrypt an empty file
! age -d -i key.txt empty
stderr empty
-- empty --
-- input --
test
-- key.txt --

View File

@@ -239,7 +239,9 @@ func Parse(input io.Reader) (*Header, io.Reader, error) {
rr := bufio.NewReader(input)
line, err := rr.ReadString('\n')
if err != nil {
if err == io.EOF {
return nil, nil, errorf("file is empty")
} else if err != nil {
return nil, nil, errorf("failed to read intro: %w", err)
}
if line != intro {