chunkstream

package
v0.0.0-...-e73c711 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package chunkstream provides chunked readers and writers; You probably want the ae package.

You probably want ae.NewWriter() and ae.NewReader() rather than these chunkStreamer wrappers. The AEAD is used with a simple nonce counter, so you MUST to provide a unique key if you use this package directly.

Index

Constants

This section is empty.

Variables

View Source
var NewAEAD func([]byte) (cipher.AEAD, error) = chacha20poly1305.New

NewAEAD is the function to instantiate a new authenticated encryption cipher to be used by the chunkStreamer. If you want to use a different one, assign one before calling either NewReader or NewWriter, e.g.:

AEAD = func(key []byte) (aead cipher.AEAD, err error) {
	block, err := aes.NewCipher(key)
	if err != nil {
		return
	}
	return cipher.NewGCM(block)
}

Functions

func NewReader

func NewReader(r io.Reader, key, info []byte, chunksize int) (io.Reader, error)

NewReader instantiates a new authenticated cipher from NewAEAD with the given key and returns a Reader. Any reads from that will read and buffer an appropriate amount of encrypted data to return the next chunk before being decrypted and authenticated. Only successfully authenticated data is ever returned.

Do not increase the chunksize manually to compensate for AEAD overhead, the chunkCipherer within will do that automatically. I.e. if you encrypted with chunksize=2048 you need to decrypt with chunksize=2048.

func NewWriter

func NewWriter(w io.Writer, key, info []byte, chunksize int) (io.WriteCloser, error)

NewWriter instantiates a new authenticated cipher from NewAEAD with the given key and returns a WriteCloser. Any writes to that will be split into small chunks and is then encrypted and authenticated individually before being written to the passed Writer.

You MUST call Close() when you're done to ensure the final chunk is written.

You MUST use a unique key because internally a simple incrementing counter is used as a nonce, so two streams encrypted with the same key will compromise confidentiality!

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL