FiloSottile / age

A simple, modern and secure encryption tool (and Go library) with small explicit keys, no config options, and UNIX-style composability.
https://age-encryption.org
BSD 3-Clause "New" or "Revised" License
15.95k stars 482 forks source link

internal/format: stop NewlineWriter from writing an empty line #264

Closed codesoap closed 3 years ago

codesoap commented 3 years ago

I intended to fix #263 with this (and at a first glance it works), but it seems like I'm breaking things, since multiple tests fail now. I couldn't figure out what the problem is. I just wanted to mention my idea for the fix. Feel free to close this PR, if it is silly.

FiloSottile commented 3 years ago

The plugin protocol will indeed be pretty core to are, because it will be how the CLI and even API is extended without bloating age itself.

However, let's ignore that for a second. "A stanza always ends with a short line" is a simpler rule even in isolation. I actually regret not taking the same approach with the STREAM implementation.

The source of the bug is that I reused the stanza encoding code for the armor. It definitely doesn't make sense for the armor to follow the same rule, but that can be fixed by using PEM rules for it. The armor is not a critical component anyway.

codesoap commented 3 years ago

The plugin protocol will indeed be pretty core

Thanks for the clarification! I'm curiously awaiting it's introduction.

However, let's ignore that for a second. "A stanza always ends with a short line" is a simpler rule even in isolation.

It is a simple rule indeed and I can see some elegance in it. However, it seems like a unusual rule to me, since I have never seen something like this in a protocol before. An explicit delimiter would seem like a more easily understood choice to me.

I am, for example, used to empty lines being disposable/optional in most plain-text file formats I can think of. I'm aware that the age file format is not to be considered plain text, but I could see myself thinking of the age-file-header as a plain text document, where I may delete a seemingly extraneous empty line in some rare scenario.

Overall, I don't think this is going to cause a lot of problems, but I wanted to share my opinion just to give you my point of view on the decision.

codesoap commented 3 years ago

I just had an other idea: Why not skip the line-wrapping in stanzas altogether? This way the first encountered newline character would always signify the end of the stanza. I understand that line-wrapping is a nice-to-have feature when using ascii-armor, but I don't see a good reason for it in the stanzas, because the stanzas are not looked at by humans in the usual use-cases (I think).