sio-go icon indicating copy to clipboard operation
sio-go copied to clipboard

provide helper functions similar to the `io/ioutil` package

Open aead opened this issue 6 years ago • 1 comments

What is the problem you want to solve?

Often you simply want to create or read from a file. Implementing this logic over and over again is tedious and error prone. Therefore, the io/ioutil provides some helper functions like WriteFile(...)

I suggest a similar sio/sioutil package containing some commonly required functionality. I suspect encrypting and decrypting a file are function candidates. However, I'm not sure right now which concepts should belong to sioutil and which shouldn't.

For example, a file can be encrypted with a password (deriving a key using a PBKDF - like Argon2id) or with a symmetric master key (which may be derived from a password itself) or with a public key (e.g. using ECDH to derive a secret key). Depending on the approach the encrypted file is created in a more open or closed format. For instance the file can start with a cipher id identifying the PBKDF + (fixed) parameters and the AEAD or the file can contain all parameters - like the PBKDF memory cost a.s.o.

Therefore, I suspect that a sio/sioutil is quite useful even though I cannot determine which functionality it should contain right now.

How do you want to solve it?

Currently, I'm thinking of:

  • EncryptFile(password []byte, filename string, data []byte, perm os.FileMode) error
  • DecryptFile(password []byte, filename string) ([]byte, error)

Also a NopCloser(w io.Writer) io.WriteCloser may be useful to avoid closing the underlying io.Writer for Enc/DecWriter in some situations.

Additional context

  1. Are there alternative solutions? Let users implement this logic themself. But - as mentioned - this is tedious and error prone.

  2. Would your solution cause a major breaking API change? No

  3. Anything else that is important? Getting feedback from actual users would be quite helpful.

aead avatar May 24 '19 10:05 aead

I'm an actual user and I would really really like this.

quackduck avatar Mar 22 '21 17:03 quackduck