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
16.83k stars 492 forks source link

age: create outfile as late as possible #169

Closed codesoap closed 3 years ago

codesoap commented 3 years ago

age creates empty output files, when something goes wrong. Examples:

  1. With age -p -o data.age data when I enter non matching passphrases.
  2. With age -d -o data data.age when I enter the wrong passphrase.
  3. With age -d -i key -o data data.age when I provided the wrong secret key.

This pull requests ensures, that the output file is created as late as possible and thus avoids the creation of empty files for the given examples. Unfortunately this leads to some boilerplate, but I feel like it's not too bad.

One drawback is that the user is now informed later about already existing output files. Thus they may have already entered a password, only to be informed that the output file already exists and won't be overwritten. This could be prevented by checking if the file exists in advance. Let me know if you want this implemented.

This pull request should resolve #159 and to some extend #57.

FiloSottile commented 3 years ago

Thank you! I took a slightly different implementation strategy, but the examples and discussion was very useful. Let me know if the changes in #173 look good!

codesoap commented 3 years ago

I really like the lazyOpener. I had briefly thought about something like this, but didn't think it would be implementable with so little code. I'll definitely remember this for future projects.