Read the text form with blank lines in front, as age does (closes #77)
check / check (push) Waiting to run
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:
@@ -4,6 +4,7 @@ package agekey
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -187,12 +188,18 @@ func (k *Key) Decrypt(dst io.Writer, src io.Reader) error {
|
||||
}
|
||||
|
||||
// unarmored strips the text form when the input begins with the line
|
||||
// that starts one, and leaves binary input alone.
|
||||
// that starts one, and leaves binary input alone. Like age, it looks
|
||||
// past up to 1024 bytes of whitespace for that line, and the text form
|
||||
// reader skips blank lines in front of it.
|
||||
func unarmored(src io.Reader) io.Reader {
|
||||
const maxWhitespace = 1024
|
||||
|
||||
buffered := bufio.NewReader(src)
|
||||
|
||||
start, err := buffered.Peek(len(armor.Header))
|
||||
if err == nil && string(start) == armor.Header {
|
||||
// A shorter input gives an error along with all of it, which is
|
||||
// enough to look at.
|
||||
start, _ := buffered.Peek(maxWhitespace + len(armor.Header))
|
||||
if bytes.HasPrefix(bytes.TrimSpace(start), []byte(armor.Header)) {
|
||||
return armor.NewReader(buffered)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user