Read the text form with blank lines in front, as age does (closes #77)
check / check (push) Waiting to run

age decrypt took the text form only when the file began exactly with
-----BEGIN AGE ENCRYPTED FILE-----, so a blank line in front made it
read the file as the binary form and refuse it. It now looks for that
line past up to 1024 bytes of whitespace, as the age tool does, and
the text form reader skips the blank lines. The README's age decrypt
section says so.

Judgement call: that first line with spaces in front of it on the same
line is still refused, as age refuses it.

Model: opus-5-5
Co-authored-by: clawbot <sneak+clawbot@sneak.cloud>
This commit was merged in pull request #88.
This commit is contained in:
2026-10-14 22:35:29 +02:00
committed by clawbot
parent 5582c02edf
commit f1e27814cd
3 changed files with 35 additions and 4 deletions
+22
View File
@@ -2,6 +2,7 @@ package agekey_test
import (
"bytes"
"io"
"strings"
"testing"
@@ -99,6 +100,27 @@ func TestTheArmoredFormIsText(t *testing.T) {
))
}
func TestTheTextFormIsReadWithWhitespaceInFront(t *testing.T) {
t.Parallel()
key := forIndex(t, 0)
var sealed bytes.Buffer
err := key.Encrypt(&sealed, strings.NewReader("hello"), nil, true)
require.NoError(t, err)
// A blank line and a line of two spaces, as pasting can leave. age
// refuses spaces on the first line of the text form itself, and so
// does this.
pasted := io.MultiReader(strings.NewReader("\n \n"), &sealed)
var opened bytes.Buffer
require.NoError(t, key.Decrypt(&opened, pasted))
require.Equal(t, "hello", opened.String())
}
func TestAFileForSomebodyElseIsRefused(t *testing.T) {
t.Parallel()